Skip to content

Commit fa6c1f1

Browse files
Fix #15015 FP knownConditionTrueFalse (bitwise not of unsigned value) (#8831)
1 parent a039b8b commit fa6c1f1

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎lib/vf_settokenvalue.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ namespace ValueFlow
617617
// ~
618618
else if (parent->str() == "~") {
619619
for (const Value &val : tok->values()) {
620-
if (!val.isIntValue())
620+
if (!val.isIntValue() || (val.isImpossible() && val.intvalue < 0))
621621
continue;
622622
Value v(val);
623623
v.intvalue = ~v.intvalue;

‎test/testvalueflow.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,15 @@ class TestValueFlow : public TestFixture {
12631263
ASSERT_EQUALS(1U, values.size());
12641264
ASSERT_EQUALS(~0U, values.back().intvalue);
12651265

1266+
// #15015
1267+
code = "void f(unsigned u) {\n"
1268+
" if (~u) {}\n"
1269+
"}";
1270+
values = tokenValues(code, "~");
1271+
ASSERT_EQUALS(1U, values.size());
1272+
ASSERT_EQUALS(-1, values.back().intvalue);
1273+
ASSERT(values.back().isImpossible());
1274+
12661275
// !
12671276
code = "void f(int x) {\n"
12681277
" a = !x;\n"

0 commit comments

Comments
 (0)