-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
C++: Test and (perhaps) fix an issue with guards on floating point comparisons. #18586
Conversation
When you do something like codeql/cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll Lines 1071 to 1076 in a54e732
int_value only holds for integers and pointers).
The reason the binary (i.e., the five argument) works is because the 0 will be right right-hand side of the equality (as an I don't particularly like this proposed solution since this will work for Instead, I think we should simply make it clear that if people want to do floating point reasoning they need to use the binary version of the predicates. The unary predicates only exist to handle the cases where there's no expression representing the right-hand side in examples such as
|
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.
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more
Thanks for your thoughts - it looks like we're in agreement at this point that this is a documentation issue not a problem with the library. I've changed my PR to leave the QL alone and add to the qldoc comments instead. I've also taken it out of draft. |
That sounds good, but... you've not actually changed anything compared to the original PR 😂 |
Ah, sorry, now pushed. |
Co-authored-by: Jeroen Ketema <[email protected]>
The issue is with guards library expressions such as
guard.comparesEq(e, _, _, _)
matching integer comparisons to a constant, but not floating point comparisons to a constant, e.g. in(where
i
isint
,f
isfloat
)Note that the five argument version
guard.comparesEq(e, _, _, _, _)
works fine in both cases already.I've added some more test cases around this (there were a couple already)
and put in a naive fix. The fix isn't great, it wouldn't cope withIt may well be the best thing to do is to document this limitation of the four argument version???f == 0.5
for example, it's more intended to provoke discussion about what if anything we should be doing with these cases.@MathiasVP and @jketema I'd love to hear your thoughts on this.