ValueFlow: Better handling of && and || in for loop to avoid FP
This commit is contained in:
parent
d4f2512421
commit
31337dda27
|
@ -2301,8 +2301,8 @@ static void valueFlowForLoopSimplify(Token * const bodyStart, const unsigned int
|
|||
|
||||
if (Token::Match(tok2, "%oror%|&&")) {
|
||||
const ProgramMemory programMemory(getProgramMemory(tok2->astTop(), varid, ValueFlow::Value(value)));
|
||||
if ((tok2->str() == "&&" && conditionIsFalse(tok2->astOperand1(), programMemory)) ||
|
||||
(tok2->str() == "||" && conditionIsTrue(tok2->astOperand1(), programMemory))) {
|
||||
if ((tok2->str() == "&&" && !conditionIsTrue(tok2->astOperand1(), programMemory)) ||
|
||||
(tok2->str() == "||" && !conditionIsFalse(tok2->astOperand1(), programMemory))) {
|
||||
// Skip second expression..
|
||||
const Token *parent = tok2;
|
||||
while (parent && parent->str() == tok2->str())
|
||||
|
|
|
@ -1731,6 +1731,14 @@ private:
|
|||
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 4U, 9));
|
||||
|
||||
code = "void foo() {\n"
|
||||
" for (int x = 0; x < 10; x++) {\n"
|
||||
" if (x < value\n"
|
||||
" && x) {}" // <- maybe x is not 9
|
||||
" }\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 4U, 9));
|
||||
|
||||
// ||
|
||||
code = "void foo() {\n"
|
||||
" for (int x = 0; x < 10; x++) {\n"
|
||||
|
|
Loading…
Reference in New Issue