Skip to content

Commit 89183e7

Browse files
committed
use calculateArithmetic for unary minus in programmemory Executor
1 parent 14439b1 commit 89183e7

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎lib/programmemory.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ namespace {
21042104
}
21052105
if (expr->str() == "-") {
21062106
for (ValueFlow::Value& v : lhs) {
2107-
v.intvalue = -v.intvalue;
2107+
v.intvalue = calculateArithmetic<MathLib::bigint>('-', 0, v.intvalue);
21082108
v.invertBound();
21092109
}
21102110
}

‎test/testvalueflow.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,14 @@ class TestValueFlow : public TestFixture {
24792479
"}\n";
24802480
ASSERT_EQUALS(true, testValueOfX(code, 4U, LLONG_MIN));
24812481

2482+
// negating the minimum wraps without signed integer overflow
2483+
code = "long long f() {\n"
2484+
" long long m = -0x7fffffffffffffff - 1;\n"
2485+
" long long x = -m;\n"
2486+
" return x;\n"
2487+
"}\n";
2488+
ASSERT_EQUALS(true, testValueOfX(code, 4U, LLONG_MIN));
2489+
24822490
code = "void f() {\n"
24832491
" int x = 123;\n"
24842492
" a = sizeof(x);\n"

0 commit comments

Comments
 (0)