Fixed #7596 (ValueFlow: better handling for 'x*(1-x-1)')
This commit is contained in:
parent
29a6a39fb5
commit
5df8e7f50c
|
@ -381,7 +381,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
result.condition = value1->condition ? value1->condition : value2->condition;
|
result.condition = value1->condition ? value1->condition : value2->condition;
|
||||||
result.inconclusive = value1->inconclusive | value2->inconclusive;
|
result.inconclusive = value1->inconclusive | value2->inconclusive;
|
||||||
result.varId = (value1->varId != 0U) ? value1->varId : value2->varId;
|
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)
|
if (value1->valueKind == value2->valueKind)
|
||||||
result.valueKind = value1->valueKind;
|
result.valueKind = value1->valueKind;
|
||||||
const float floatValue1 = value1->isIntValue() ? value1->intvalue : value1->floatValue;
|
const float floatValue1 = value1->isIntValue() ? value1->intvalue : value1->floatValue;
|
||||||
|
|
|
@ -408,6 +408,12 @@ private:
|
||||||
ASSERT_EQUALS(4, values.front().intvalue);
|
ASSERT_EQUALS(4, values.front().intvalue);
|
||||||
ASSERT_EQUALS(16, values.back().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
|
// addition of different variables with known values
|
||||||
code = "int f(int x) {\n"
|
code = "int f(int x) {\n"
|
||||||
" int a = 1;\n"
|
" int a = 1;\n"
|
||||||
|
|
Loading…
Reference in New Issue