value flow: fixed fp for rhs in && and || expressions

This commit is contained in:
Daniel Marjamäki 2014-01-11 11:30:34 +01:00
parent f0743d3bc4
commit 60348da1b5
2 changed files with 14 additions and 2 deletions

View File

@ -116,11 +116,14 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
// skip if variable is conditionally used in ?: expression.
const Token *parent = tok2->astParent();
while (parent && !Token::Match(parent, "[?:]"))
while (parent && !Token::Match(parent, "%oror%|&&?|:"))
parent = parent->astParent();
if (parent) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "no simplification of " + tok2->str() + " within ?: expression");
bailout(tokenlist,
errorLogger,
tok2,
"no simplification of " + tok2->str() + " within " + (Token::Match(parent,"[?:]") ? "?:" : parent->str()) + " expression");
continue;
}

View File

@ -104,6 +104,15 @@ private:
"}";
ASSERT_EQUALS(true, testValueOfX(code, 3U, 123));
// guarding by &&
bailout("void f(int x) {\n"
" if (!x || \n" // <- x can be 0
" a/x) {}\n" // <- x can't be 0
" if (x==0) {}\n"
"}");
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 2U, 0));
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
// bailout: ?:
bailout("void f(int x) {\n"
" y = ((x<0) ? x : ((x==2)?3:4));\n"