Fix #11820 FP duplicateExpression with double negation (#5227)

This commit is contained in:
chrchr-github 2023-07-07 23:30:59 +02:00 committed by GitHub
parent d6d3c7b3fc
commit 218650dc85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -1458,10 +1458,10 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
tok2 = tok2->astOperand2();
}
// Skip double not
if (Token::simpleMatch(tok1, "!") && Token::simpleMatch(tok1->astOperand1(), "!") && !Token::simpleMatch(tok1->astParent(), "=")) {
if (Token::simpleMatch(tok1, "!") && Token::simpleMatch(tok1->astOperand1(), "!") && !Token::simpleMatch(tok1->astParent(), "=") && astIsBoolLike(tok2)) {
return isSameExpression(cpp, macro, tok1->astOperand1()->astOperand1(), tok2, library, pure, followVar, errors);
}
if (Token::simpleMatch(tok2, "!") && Token::simpleMatch(tok2->astOperand1(), "!") && !Token::simpleMatch(tok2->astParent(), "=")) {
if (Token::simpleMatch(tok2, "!") && Token::simpleMatch(tok2->astOperand1(), "!") && !Token::simpleMatch(tok2->astParent(), "=") && astIsBoolLike(tok1)) {
return isSameExpression(cpp, macro, tok1, tok2->astOperand1()->astOperand1(), library, pure, followVar, errors);
}
const bool tok_str_eq = tok1->str() == tok2->str();

View File

@ -6570,6 +6570,15 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The comparison 'p == 0' is always true.\n", errout.str());
// #11820
check("unsigned f(unsigned x) {\n"
" return x - !!x;\n"
"}\n"
"unsigned g(unsigned x) {\n"
" return !!x - x;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void duplicateExpression8() {