-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed #11202/#11199/#11201/#12330/#12774 / refs #13508/#11200/#13506 - fixed various floating-point comparison regressions #7148
Changes from all commits
a04fc3b
50c53e9
ef3337d
f8fdc21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -496,6 +496,7 @@ namespace ValueFlow | |
} | ||
const double floatValue1 = value1.isFloatValue() ? value1.floatValue : static_cast<double>(value1.intvalue); | ||
const double floatValue2 = value2.isFloatValue() ? value2.floatValue : static_cast<double>(value2.intvalue); | ||
const bool isFloat = value1.isFloatValue() || value2.isFloatValue(); | ||
const auto intValue1 = [&]() -> MathLib::bigint { | ||
return value1.isFloatValue() ? static_cast<MathLib::bigint>(value1.floatValue) : value1.intvalue; | ||
}; | ||
|
@@ -550,17 +551,27 @@ namespace ValueFlow | |
setTokenValue(parent, std::move(result), settings); | ||
} else if (Token::Match(parent, "%op%")) { | ||
if (Token::Match(parent, "%comp%")) { | ||
if (!result.isFloatValue() && !value1.isIntValue() && !value2.isIntValue()) | ||
if (!isFloat && !value1.isIntValue() && !value2.isIntValue()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The !isFloat is redundant here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the same but it is not (this is actually the important change based on my older comment). It reflects if either is a float. That doesn't mean one of them cannot be an Int. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, To make it clearer dont use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well - I took it from the original code. |
||
continue; | ||
} else { | ||
if (value1.isTokValue() || value2.isTokValue()) | ||
break; | ||
} | ||
bool error = false; | ||
if (result.isFloatValue()) { | ||
result.floatValue = calculate(parent->str(), floatValue1, floatValue2, &error); | ||
if (isFloat) { | ||
firewave marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, looking at the test, we just need to run calculate as both float if one operand is float and convert to the result type int or float at the end. Also rather than use lambdas(like intValue1) to do the conversion we should instead update the getIntValue and getFloatValue methods to do the conversion. This should make the code much simpler. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes the regression introduced by my change. Thanks. I will take a look into the remaining false negatives tomorrow. There is also a few test variations I still like to add. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like everything has already been fixed. The existing false negatives do not appear to be related to the commit in question but a much earlier one. Will clean up the tests tomorrow. |
||
auto val = calculate(parent->str(), floatValue1, floatValue2, &error); | ||
if (result.isFloatValue()) { | ||
result.floatValue = val; | ||
} else { | ||
result.intvalue = static_cast<MathLib::bigint>(val); | ||
} | ||
} else { | ||
result.intvalue = calculate(parent->str(), intValue1(), intValue2(), &error); | ||
auto val = calculate(parent->str(), intValue1(), intValue2(), &error); | ||
if (result.isFloatValue()) { | ||
result.floatValue = static_cast<double>(val); | ||
} else { | ||
result.intvalue = val; | ||
} | ||
} | ||
if (error) | ||
continue; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrchr-github This crash fix from #5587 was way too specific.