Fixed #6000 (ValueFlow: conditional code in for loops)
This commit is contained in:
parent
76cdfbf487
commit
a8416bfb16
|
@ -2017,6 +2017,14 @@ static void valueFlowForLoopSimplify(Token * const bodyStart, const unsigned int
|
|||
tok2 = tok2->linkAt(2);
|
||||
}
|
||||
}
|
||||
|
||||
else if (Token::simpleMatch(tok2, ") {")) {
|
||||
if (settings->debugwarnings)
|
||||
bailout(tokenlist, errorLogger, tok2, "For loop skipping {} code");
|
||||
tok2 = tok2->linkAt(1);
|
||||
if (Token::simpleMatch(tok2, "} else {"))
|
||||
tok2 = tok2->linkAt(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1600,6 +1600,19 @@ private:
|
|||
" n = (int)(i < 10 || abs(negWander) < abs(negTravel));\n"
|
||||
"}";
|
||||
testValueOfX(code,0,0); // <- dont hang
|
||||
|
||||
// conditional code in loop
|
||||
code = "void f(int mask) {\n" // #6000
|
||||
" for (int x = 10; x < 14; x++) {\n"
|
||||
" int bit = mask & (1 << i);\n"
|
||||
" if (bit) {\n"
|
||||
" if (bit == (1 << 10)) {}\n"
|
||||
" else { a = x; }\n" // <- x is not 10
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 6U, 10));
|
||||
|
||||
}
|
||||
|
||||
void valueFlowSubFunction() {
|
||||
|
|
Loading…
Reference in New Issue