From b7ddbe483deadbdd196e5a927db4eb3fb6b80404 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sun, 5 Jan 2025 00:43:50 +0100 Subject: [PATCH] Fix #13522 FP knownConditionTrueFalse after unsigned-to-signed conversion --- lib/vf_analyzers.cpp | 2 ++ test/testcondition.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/vf_analyzers.cpp b/lib/vf_analyzers.cpp index 32b06eb96e4..cf92e8f578f 100644 --- a/lib/vf_analyzers.cpp +++ b/lib/vf_analyzers.cpp @@ -527,6 +527,8 @@ struct ValueFlowAnalyzer : Analyzer { continue; if (exact && v.intvalue != 0 && !isPoint) continue; + if (astIsUnsigned(tok) != astIsUnsigned(v.tokvalue)) + continue; std::vector r; ValueFlow::Value::Bound bound = currValue->bound; if (match(v.tokvalue)) { diff --git a/test/testcondition.cpp b/test/testcondition.cpp index db2f41e6da2..5a3f5211bfa 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4947,6 +4947,13 @@ class TestCondition : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("void f(unsigned x) {\n" // #13522 + " unsigned u = x;\n" + " int i = u - 0;\n" + " if (i < 0) {}\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void alwaysTrueInfer() {