Skip to content

Commit 80047b5

Browse files
Fix #13522 FP knownConditionTrueFalse after unsigned-to-signed conversion (danmar#7179)
1 parent 9288b8e commit 80047b5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/vf_analyzers.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ struct ValueFlowAnalyzer : Analyzer {
528528
continue;
529529
if (exact && v.intvalue != 0 && !isPoint)
530530
continue;
531+
if (astIsUnsigned(tok) != astIsUnsigned(v.tokvalue))
532+
continue;
531533
std::vector<MathLib::bigint> r;
532534
ValueFlow::Value::Bound bound = currValue->bound;
533535
if (match(v.tokvalue)) {

test/testcondition.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4968,6 +4968,13 @@ class TestCondition : public TestFixture {
49684968
" }\n"
49694969
"}\n");
49704970
ASSERT_EQUALS("", errout_str());
4971+
4972+
check("void f(unsigned x) {\n" // #13522
4973+
" unsigned u = x;\n"
4974+
" int i = u - 0;\n"
4975+
" if (i < 0) {}\n"
4976+
"}\n");
4977+
ASSERT_EQUALS("", errout_str());
49714978
}
49724979

49734980
void alwaysTrueInfer() {

0 commit comments

Comments
 (0)