Skip to content

Commit 1820c05

Browse files
Fix #14540 FP shiftNegative after sign check (#8269)
1 parent 09150ed commit 1820c05

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3682,7 +3682,7 @@ static void valueFlowSymbolicOperators(const SymbolDatabase& symboldatabase, con
36823682
continue;
36833683
if (vartok->exprId() == 0)
36843684
continue;
3685-
if (Token::Match(tok, "<<|>>|/") && !astIsLHS(vartok))
3685+
if (Token::Match(tok, "<<|>>|/|-") && !astIsLHS(vartok))
36863686
continue;
36873687
if (Token::Match(tok, "<<|>>|^|+|-|%or%") && constant->intvalue != 0)
36883688
continue;

test/testvalueflow.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8910,6 +8910,18 @@ class TestValueFlow : public TestFixture {
89108910
" return x;\n"
89118911
"}\n";
89128912
ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, "a", 0));
8913+
8914+
code = "void f(int n) {\n"
8915+
" int x = 0 - n;\n"
8916+
" return x;\n"
8917+
"}\n";
8918+
ASSERT_EQUALS(false, testValueOfX(code, 3U, "n", ValueFlow::Value::ValueType::SYMBOLIC));
8919+
8920+
code = "void f(int n) {\n"
8921+
" int x = n - 0;\n"
8922+
" return x;\n"
8923+
"}\n";
8924+
ASSERT_EQUALS(true, testValueOfX(code, 3U, "n", ValueFlow::Value::ValueType::SYMBOLIC));
89138925
}
89148926

89158927
void valueFlowSymbolicStrlen()

0 commit comments

Comments
 (0)