value flow: fixed fp for rhs in && and || expressions
This commit is contained in:
parent
f0743d3bc4
commit
60348da1b5
|
@ -116,11 +116,14 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
||||||
|
|
||||||
// skip if variable is conditionally used in ?: expression.
|
// skip if variable is conditionally used in ?: expression.
|
||||||
const Token *parent = tok2->astParent();
|
const Token *parent = tok2->astParent();
|
||||||
while (parent && !Token::Match(parent, "[?:]"))
|
while (parent && !Token::Match(parent, "%oror%|&&?|:"))
|
||||||
parent = parent->astParent();
|
parent = parent->astParent();
|
||||||
if (parent) {
|
if (parent) {
|
||||||
if (settings->debugwarnings)
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,15 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 123));
|
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: ?:
|
||||||
bailout("void f(int x) {\n"
|
bailout("void f(int x) {\n"
|
||||||
" y = ((x<0) ? x : ((x==2)?3:4));\n"
|
" y = ((x<0) ? x : ((x==2)?3:4));\n"
|
||||||
|
|
Loading…
Reference in New Issue