Fix issue 9898: false positive: knownConditionTrueFalse (#2806)
This commit is contained in:
parent
566e74fae0
commit
a42976d656
|
@ -313,11 +313,13 @@ struct ForwardTraversal {
|
|||
if (!scope)
|
||||
return Progress::Break;
|
||||
if (Token::Match(tok->link()->previous(), ")|else {")) {
|
||||
const bool inElse = Token::simpleMatch(tok->link()->previous(), "else {");
|
||||
const Token* tok2 = tok->link()->previous();
|
||||
const bool inElse = Token::simpleMatch(tok2, "else {");
|
||||
const bool inLoop = inElse ? false : Token::Match(tok2->link()->previous(), "while|for (");
|
||||
Token* condTok = getCondTokFromEnd(tok);
|
||||
if (!condTok)
|
||||
return Progress::Break;
|
||||
if (!condTok->hasKnownIntValue()) {
|
||||
if (!condTok->hasKnownIntValue() || inLoop) {
|
||||
if (!analyzer->lowerToPossible())
|
||||
return Progress::Break;
|
||||
} else if (condTok->values().front().intvalue == inElse) {
|
||||
|
|
|
@ -2479,6 +2479,19 @@ private:
|
|||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfXImpossible(code, 8U, 0));
|
||||
|
||||
code = "int foo(int n) {\n"
|
||||
" if( n>= 8 ) {\n"
|
||||
" while(true) {\n"
|
||||
" n -= 8;\n"
|
||||
" if( n < 8 )\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" int x = n == 0;\n"
|
||||
" return x;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 9U, 0));
|
||||
|
||||
code = "bool c();\n"
|
||||
"long f() {\n"
|
||||
" bool stop = false;\n"
|
||||
|
|
Loading…
Reference in New Issue