From cf062a9ed634114a19c267dbc740a82dc1af7f1c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:07:41 +0200 Subject: [PATCH 1/8] Update vf_common.h --- lib/vf_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vf_common.h b/lib/vf_common.h index aca438a0dff..448d14ccb41 100644 --- a/lib/vf_common.h +++ b/lib/vf_common.h @@ -41,7 +41,7 @@ namespace ValueFlow { bool getMinMaxValues(const ValueType* vt, const Platform& platform, MathLib::bigint& minValue, MathLib::bigint& maxValue); - MathLib::bigint truncateIntValue(MathLib::bigint value, size_t value_size, ValueType::Sign dst_sign); + MathLib::bigint truncateIntValue(MathLib::bigint value, size_t value_size, const ValueType* dst, const Platform& platform); Token * valueFlowSetConstantValue(Token *tok, const Settings &settings); From 5c0277e05d711beb04e70ee7e2982d91ac5fe054 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:09:59 +0200 Subject: [PATCH 2/8] Update vf_analyzers.cpp --- lib/vf_analyzers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vf_analyzers.cpp b/lib/vf_analyzers.cpp index 1a4d17aa849..b2ef2abe1ea 100644 --- a/lib/vf_analyzers.cpp +++ b/lib/vf_analyzers.cpp @@ -357,7 +357,7 @@ struct ValueFlowAnalyzer : Analyzer { if (dst) { const size_t sz = dst->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer); if (sz > 0 && sz < sizeof(MathLib::biguint)) { - MathLib::bigint newvalue = ValueFlow::truncateIntValue(value->intvalue, sz, dst->sign); + MathLib::bigint newvalue = ValueFlow::truncateIntValue(value->intvalue, sz, dst, settings.platform); /* Handle overflow/underflow for value bounds */ if (value->bound != ValueFlow::Value::Bound::Point) { From 29745e9e36e3046c6ae7dd9ad4b6227e3e20b9c3 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:10:34 +0200 Subject: [PATCH 3/8] Update vf_common.cpp --- lib/vf_common.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vf_common.cpp b/lib/vf_common.cpp index f9eecc20fb9..b1cabcc9201 100644 --- a/lib/vf_common.cpp +++ b/lib/vf_common.cpp @@ -96,7 +96,7 @@ namespace ValueFlow return true; } - MathLib::bigint truncateIntValue(MathLib::bigint value, size_t value_size, const ValueType::Sign dst_sign) + MathLib::bigint truncateIntValue(MathLib::bigint value, size_t value_size, const ValueType* dst, const Platform& platform) { if (value_size == 0) return value; @@ -104,7 +104,7 @@ namespace ValueFlow const MathLib::biguint unsignedMaxValue = std::numeric_limits::max() >> ((sizeof(unsignedMaxValue) - value_size) * 8); const MathLib::biguint signBit = 1ULL << ((value_size * 8) - 1); value &= unsignedMaxValue; - if (dst_sign == ValueType::Sign::SIGNED && (value & signBit)) + if ((dst->sign == ValueType::Sign::SIGNED || (dst->sign == ValueType::Sign::UNKNOWN_SIGN && dst->type == ValueType::Type::CHAR && platform.defaultSign == 's')) && (value & signBit)) value |= ~unsignedMaxValue; return value; From 1d21203f4bc3d24b8ff7554cea581f29100e2bb5 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:11:44 +0200 Subject: [PATCH 4/8] Update vf_settokenvalue.cpp --- lib/vf_settokenvalue.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index 1d6179fb9af..21bfbbe2da2 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -665,7 +665,7 @@ namespace ValueFlow const ValueType *dst = tok->valueType(); if (dst) { const size_t sz = dst->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer); - MathLib::bigint newvalue = ValueFlow::truncateIntValue(v.intvalue + 1, sz, dst->sign); + MathLib::bigint newvalue = ValueFlow::truncateIntValue(v.intvalue + 1, sz, dst, settings.platform); if (v.bound != ValueFlow::Value::Bound::Point) { if (newvalue < v.intvalue) { v.invertBound(); @@ -695,7 +695,7 @@ namespace ValueFlow const ValueType *dst = tok->valueType(); if (dst) { const size_t sz = dst->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer); - MathLib::bigint newvalue = ValueFlow::truncateIntValue(v.intvalue - 1, sz, dst->sign); + MathLib::bigint newvalue = ValueFlow::truncateIntValue(v.intvalue - 1, sz, dst, settings.platform); if (v.bound != ValueFlow::Value::Bound::Point) { if (newvalue > v.intvalue) { v.invertBound(); From a74ef74a30d7c217a23293e1fd30db80324bc709 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:12:12 +0200 Subject: [PATCH 5/8] Update valueflow.cpp --- lib/valueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index c021d1d296b..96c2ba24159 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4131,7 +4131,7 @@ static std::list truncateValues(std::list va } if (value.isIntValue() && sz > 0 && sz < sizeof(MathLib::biguint)) - value.intvalue = ValueFlow::truncateIntValue(value.intvalue, sz, dst->sign); + value.intvalue = ValueFlow::truncateIntValue(value.intvalue, sz, dst, settings.platform); } return values; } From d19541aaeacf1aa594e36d6fa20dc590b2497f20 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:13:38 +0200 Subject: [PATCH 6/8] Update testvalueflow.cpp --- test/testvalueflow.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index f84f0ea0d89..b42b79ddebc 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1389,6 +1389,12 @@ class TestValueFlow : public TestFixture { ASSERT_EQUALS(22, values.back().intvalue); } + code = "void f() {\n" // #15032 + " char c = -1;\n" + " if (~c == -256) {}\n" + "}\n"; + ASSERT(testKnownValueOfTok(code, "~", 0)); + // #10251 starship operator code = "struct X {};\n" "auto operator<=>(const X & a, const X & b) -> decltype(1 <=> 2) {\n" From 9221dc5efe759b64f079c16bdded996109a0e640 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:51:14 +0200 Subject: [PATCH 7/8] Update testvalueflow.cpp --- test/testvalueflow.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index b42b79ddebc..746a59e394f 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1393,7 +1393,12 @@ class TestValueFlow : public TestFixture { " char c = -1;\n" " if (~c == -256) {}\n" "}\n"; - ASSERT(testKnownValueOfTok(code, "~", 0)); + const Settings settingsUnix64 = settingsBuilder().platform(Platform::Type::Unix64).build(); + values = tokenValues(code, "~", &settingsUnix64); + ASSERT_EQUALS(1U, values.size()); + ASSERT_EQUALS(0, values.front().intvalue); + ASSERT(values.front().isKnown()); + ASSERT(values.front().isIntValue()); // #10251 starship operator code = "struct X {};\n" From 22d1c8c8b9eb71d20766407d17db77021867fd2e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 14 Oct 2026 17:39:00 +0200 Subject: [PATCH 8/8] Update testvalueflow.cpp --- test/testvalueflow.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 746a59e394f..3609bf2aee2 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1393,12 +1393,8 @@ class TestValueFlow : public TestFixture { " char c = -1;\n" " if (~c == -256) {}\n" "}\n"; - const Settings settingsUnix64 = settingsBuilder().platform(Platform::Type::Unix64).build(); - values = tokenValues(code, "~", &settingsUnix64); - ASSERT_EQUALS(1U, values.size()); - ASSERT_EQUALS(0, values.front().intvalue); - ASSERT(values.front().isKnown()); - ASSERT(values.front().isIntValue()); + const int expected = std::numeric_limits::is_signed ? 0 : -256; + ASSERT_EQUALS(true, testKnownValueOfTok(code, "~", expected)); // #10251 starship operator code = "struct X {};\n"