Fixed #6877 (ValueFlow: valueFlowForward, after goto label the value is not known)

This commit is contained in:
Daniel Marjamäki 2015-07-26 17:05:21 +02:00
parent ae124cb365
commit 190550f9f9
2 changed files with 16 additions and 0 deletions

View File

@ -993,6 +993,13 @@ static bool valueFlowForward(Token * const startToken,
} }
} }
if (Token::Match(tok2, "[;{}] %name% :")) {
for (std::list<ValueFlow::Value>::iterator it = values.begin(); it != values.end(); ++it)
it->changeKnownToPossible();
tok2 = tok2->tokAt(2);
continue;
}
if (Token::Match(tok2, "sizeof|typeof|typeid (")) if (Token::Match(tok2, "sizeof|typeof|typeid ("))
tok2 = tok2->linkAt(1); tok2 = tok2->linkAt(1);

View File

@ -1651,6 +1651,15 @@ private:
ASSERT_EQUALS(1, value.intvalue); ASSERT_EQUALS(1, value.intvalue);
ASSERT(value.isPossible()); ASSERT(value.isPossible());
code = "void f() {\n"
" int x = 0;\n"
"a:\n"
" a = x + 1;\n" // <- possible value
"}";
value = valueOfTok(code, "+");
ASSERT_EQUALS(1, value.intvalue);
ASSERT(value.isPossible());
// after condition // after condition
code = "int f(int x) {\n" code = "int f(int x) {\n"
" if (x == 4) {}\n" " if (x == 4) {}\n"