Fixed #7596 (ValueFlow: better handling for 'x*(1-x-1)')

This commit is contained in:
Daniel Marjamäki 2016-12-04 22:39:59 +01:00
parent 29a6a39fb5
commit 5df8e7f50c
2 changed files with 7 additions and 1 deletions

View File

@ -381,7 +381,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
result.condition = value1->condition ? value1->condition : value2->condition;
result.inconclusive = value1->inconclusive | value2->inconclusive;
result.varId = (value1->varId != 0U) ? value1->varId : value2->varId;
result.varvalue = (result.varId == value1->varId) ? value1->intvalue : value2->intvalue;
result.varvalue = (result.varId == value1->varId) ? value1->varvalue : value2->varvalue;
if (value1->valueKind == value2->valueKind)
result.valueKind = value1->valueKind;
const float floatValue1 = value1->isIntValue() ? value1->intvalue : value1->floatValue;

View File

@ -408,6 +408,12 @@ private:
ASSERT_EQUALS(4, values.front().intvalue);
ASSERT_EQUALS(16, values.back().intvalue);
code = "void f(int x) {\n"
" if (x == 3) {}\n"
" a = x * (1 - x - 1);\n"
"}";
ASSERT_EQUALS(-9, valueOfTok(code, "*").intvalue);
// addition of different variables with known values
code = "int f(int x) {\n"
" int a = 1;\n"