Skip to content

Commit 3329e2f

Browse files
Fix #11741 FP knownConditionTrueFalse minus/negation confuses check (#5766)
1 parent 1135520 commit 3329e2f

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6304,7 +6304,7 @@ struct ConditionHandler {
63046304
values.insert(values.end(), cond.false_values.cbegin(), cond.false_values.cend());
63056305

63066306
// extra logic for unsigned variables 'i>=1' => possible value can also be 0
6307-
if (Token::Match(tok, "<|>")) {
6307+
if (Token::Match(tok, "<|>|<=|>=")) {
63086308
values.remove_if([](const ValueFlow::Value& v) {
63096309
if (v.isIntValue())
63106310
return v.intvalue != 0;

test/testcondition.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4547,6 +4547,14 @@ class TestCondition : public TestFixture {
45474547
" }\n"
45484548
"}\n");
45494549
ASSERT_EQUALS("", errout.str());
4550+
4551+
check("int f(int i) {\n" // #11741
4552+
" i = -i - 1;\n"
4553+
" if (i < 0 || i >= 20)\n"
4554+
" return 0;\n"
4555+
" return 1;\n"
4556+
"}\n");
4557+
ASSERT_EQUALS("", errout.str());
45504558
}
45514559

45524560
void alwaysTrueSymbolic()

test/testvalueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ class TestValueFlow : public TestFixture {
14601460
" int a = x;\n"
14611461
" if (x >= 1) {}\n"
14621462
"}";
1463-
ASSERT_EQUALS(true, testValueOfX(code, 2U, 1));
1463+
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 2U, 1));
14641464
ASSERT_EQUALS(true, testValueOfX(code, 2U, 0));
14651465

14661466
code = "void f(unsigned int x) {\n"

0 commit comments

Comments
 (0)