Fix #11434 FP knownConditionTrueFalse with loop over bool array (#4646)

* Fix #11434 FP knownConditionTrueFalse with loop over bool array

* Simplify
This commit is contained in:
chrchr-github 2022-12-15 14:31:02 +01:00 committed by GitHub
parent 0c1e2ceeb9
commit 553b579f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -1370,10 +1370,23 @@ static bool isForLoopCondition(const Token * const tok)
parent->astParent()->astParent()->astOperand1()->str() == "for";
}
static bool isForLoopIncrement(const Token* const tok)
{
if (!tok)
return false;
const Token *const parent = tok->astParent();
return Token::simpleMatch(parent, ";") && parent->astOperand2() == tok &&
Token::simpleMatch(parent->astParent(), ";") &&
Token::simpleMatch(parent->astParent()->astParent(), "(") &&
parent->astParent()->astParent()->astOperand1()->str() == "for";
}
bool isUsedAsBool(const Token* const tok)
{
if (!tok)
return false;
if (isForLoopIncrement(tok))
return false;
if (astIsBool(tok))
return true;
if (Token::Match(tok, "!|&&|%oror%|%comp%"))

View File

@ -4973,6 +4973,13 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f() {\n" // #11434
" const int N = 5;\n"
" bool a[N];\n"
" for (int i = 0; i < N; a[i++] = false);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueTryCatch()