Fix #11741 FP knownConditionTrueFalse minus/negation confuses check (#5766)

This commit is contained in:
chrchr-github 2023-12-16 17:03:56 +01:00 committed by GitHub
parent 1135520aa8
commit 3329e2f633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -6304,7 +6304,7 @@ struct ConditionHandler {
values.insert(values.end(), cond.false_values.cbegin(), cond.false_values.cend());
// extra logic for unsigned variables 'i>=1' => possible value can also be 0
if (Token::Match(tok, "<|>")) {
if (Token::Match(tok, "<|>|<=|>=")) {
values.remove_if([](const ValueFlow::Value& v) {
if (v.isIntValue())
return v.intvalue != 0;

View File

@ -4547,6 +4547,14 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("int f(int i) {\n" // #11741
" i = -i - 1;\n"
" if (i < 0 || i >= 20)\n"
" return 0;\n"
" return 1;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueSymbolic()

View File

@ -1460,7 +1460,7 @@ private:
" int a = x;\n"
" if (x >= 1) {}\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 2U, 1));
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 2U, 1));
ASSERT_EQUALS(true, testValueOfX(code, 2U, 0));
code = "void f(unsigned int x) {\n"