-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: Fix the two null termination queries and re-enable them. #6915
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
Conversation
…in NullTermination.qll.
This reverts commit f38dade.
It looks like a join-ordering issue where
I think you can get a simpler (and behaviour-preserving) fix by replacing: mayAddNullTerminatorHelper(e, va, e0) and
bb.getNode(pos) = e and
bb0.getNode(pos0) = e0 with mayAddNullTerminatorHelper(pragma[only_bind_into](e), va, pragma[only_bind_into](e0)) and
pragma[only_bind_into](bb).getNode(pos) = e and
pragma[only_bind_into](bb0).getNode(pos0) = e0 that should force the compiler to only compute |
I've pushed a commit updating to your suggestion, then a commit applying similar changes to |
The naive version using |
Indeed, I think it would be super nice to have a transitive version of
For now, I think it's best to make |
I've added some tests, fixed a bug revealed by the tests, renamed the predicate (though we can and should use a shorter name if we make it a member predicate of
|
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.
LGTM! The PR check failure is not related to this PR.
Would it help if I retry the check, or merge latest main? |
Yes. This has been fixed on the latest main. So you should be fine if you retry. |
I don't seem to be able to get DCA working right now. I'll try again / try something else to confirm performance tomorrow. |
Do tell me if I can help with anything! |
DCA results are in:
So the performance improvements are good, but I think this isn't quite ready to merge yet... |
I've just removed the part of this PR that re-enables the queries, leaving us with just the performance fixes which I think are uncontroversial at this point. The intent being to get what we have here merged as I'm working on other things. I've extended the ticket for to this work with the stuff I discussed doing above, so we should be able to come back to it. |
Sounds good. |
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.
LGTM!
This is my proposed fix (update: major contributions from @MathiasVP) for performance of the two null termination queries that regressed the CPP-Differences suite last week (caused by #6794 and temporarily fixed by #6893).
It is not behaviour preserving, as I didn't have much luck making an improvement that was.I'm very much open to suggestions of other approaches and discussions about tradeoffs.This PR also re-enables the two queries as they should now perform acceptably.
The issue is in the
NullTermination.qll
library, that is only used by these two queries. It does not appear to be related to the recent QL changes themselves, rather just the fact that these queries were enabled. The issue does not affect all projects, but for example inphp
the time to computemayAddNullTerminator
exploded (specifically the "Assignment to another stack variable" part).Performance:
294s295s forcpp/improper-null-termination
and 882s ->529s538s forcpp/user-controlled-null-termination-tainted
onphp
(the remaining time I believe is largely cache warmup of SSA, def-use etc).the DCA results show a 28% speedup onTODO: re-run with the new strategy.php
comparable to the original slowdown that is 32% of the slow run.1130s939s forcpp/improper-null-termination
onwireshark
; less of a speedup, the issue inmayAddNullTerminator
is resolved but there may be a similar problem invariableMustBeNullTerminated
that remains.Results:
the change makes the "Assignment to another stack variable" case coarser, thusmayAddNullTerminator
is wider so we will in principle see fewer query results.in local runs, on tests, and on DCA I saw no query differences.TODO: it's probably worth running an LGTM diff query, there will likely be something to see.@MathiasVP - I've not made this a draft, but I feel we should discuss it and possibly iterate before merging.