Fixed #7358 (valueflow: value is not known after conditional assignment)

This commit is contained in:
Daniel Marjamäki 2016-01-27 19:20:00 +01:00
parent 477d02bbe7
commit b5986f6ad2
2 changed files with 25 additions and 8 deletions

View File

@ -1158,9 +1158,14 @@ static bool valueFlowForward(Token * const startToken,
errorLogger,
settings);
if (isVariableChanged(startToken1, startToken1->link(), varid))
if (isVariableChanged(startToken1, startToken1->link(), varid)) {
removeValues(values, truevalues);
std::list<ValueFlow::Value>::iterator it;
for (it = values.begin(); it != values.end(); ++it)
it->changeKnownToPossible();
}
// goto '}'
tok2 = startToken1->link();

View File

@ -1754,13 +1754,25 @@ private:
ASSERT_EQUALS(3, value.intvalue);
ASSERT(value.isKnown());
code = "void f() {\n"
" int x = 15;\n"
" if (x == 15) { x += 7; }\n" // <- condition is true
"}";
value = valueOfTok(code, "==");
ASSERT_EQUALS(1, value.intvalue);
ASSERT(value.isKnown());
{
code = "void f() {\n"
" int x = 15;\n"
" if (x == 15) { x += 7; }\n" // <- condition is true
"}";
value = valueOfTok(code, "==");
ASSERT_EQUALS(1, value.intvalue);
ASSERT(value.isKnown());
code = "int f() {\n"
" int a = 0, x = 0;\n"
" a = index();\n"
" if (a != 0)\n"
" x = next();\n"
" return x + 1;\n"
"}\n";
value = valueOfTok(code, "+");
ASSERT(value.isPossible());
}
code = "void f() {\n"
" int x;\n"