Skip to content

Commit ccb31d8

Browse files
authored
Fix 10460: FP knownConditionTrueFalse 'fabs(x)<1/(double)16' is always false (#3445)
1 parent 2a8b4ae commit ccb31d8

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

lib/valueflow.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,13 @@ static void setTokenValueCast(Token *parent, const ValueType &valueType, const V
945945
setTokenValue(parent, castValue(value, valueType.sign, settings->long_bit), settings);
946946
else if (valueType.type == ValueType::Type::LONGLONG)
947947
setTokenValue(parent, castValue(value, valueType.sign, settings->long_long_bit), settings);
948+
else if (valueType.isFloat()) {
949+
ValueFlow::Value floatValue = value;
950+
floatValue.valueType = ValueFlow::Value::ValueType::FLOAT;
951+
if (value.isIntValue())
952+
floatValue.floatValue = value.intvalue;
953+
setTokenValue(parent, floatValue, settings);
954+
}
948955
else if (value.isIntValue()) {
949956
const long long charMax = settings->signedCharMax();
950957
const long long charMin = settings->signedCharMin();

test/testvalueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ class TestValueFlow : public TestFixture {
519519
ASSERT_EQUALS((int)('\n'), valueOfTok("x='\\n';", "'\\n'").intvalue);
520520
TODO_ASSERT_EQUALS(
521521
0xFFFFFFFF00000000, -1, valueOfTok("x=0xFFFFFFFF00000000;", "0xFFFFFFFF00000000").intvalue); // #7701
522+
ASSERT_EQUALS_DOUBLE(16, valueOfTok("x=(double)16;", "(").floatValue, 1e-5);
523+
ASSERT_EQUALS_DOUBLE(0.0625, valueOfTok("x=1/(double)16;", "/").floatValue, 1e-5);
522524

523525
// scope
524526
{

0 commit comments

Comments
 (0)