C++: Ensure that there are AST GuardConditions for || and &&
#21239
+53
−68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes two bugs in the AST-based GuardCondition library. First some background:
In C/C++ guard conditions come in two flavors: One that directly is built directly on the IR, and one that wraps the IR-based logic in an AST-based wrapper.
To encode short circuiting the IR desugars binary logical operators (i.e.,
||and&&) into individual checks. For example the IR for:is the same as the IR for
This means that there's no
Instructionthat holds the computes theb1 && b2expression. That is, there is no instructionifor whichi.getUnconvertedResultExpression()is theb1 && b2. As a result, there is no AST-based guard condition forb1 && b2.This has confused people in the past, and because of that we added special cases in the AST-based wrapper to make sure these exist. Unfortunately, we implemented the logic around these all wrong 🙈. The second part of this PR fixes that logic!
The first commit fixes another AST-wrapper bug: The mapping from
IRBlocks to ASTBasicBlocks was incorrect when theIRBlockwas the initial block of a function. This is because, in the AST-basedBasicBlocklibrary the function itself is the exit block of the function, but there are someInstructions whose AST component is the function itself. This resulted in bugs where the initialIRBlockof a function was incorrectly translated into the exitBasicBlockof a function.Commit-by-commit review recommended. You can see the effects on our tests in each commit. They are a bit hard to interpret because the tests haven't been ported to use inline expectations yet. Maybe I should do that as a follow-up 🤔
DCA looks excellent. We get two new TPs.1 cc @bdrodes because you
complained aboutpolitely raised this issue.Footnotes
Don't look to closely at the "related locations" in the alert comparison. It turns out this work helped discover a 6 year old bug in DCA. The results are actually TPs, but the locations of the related locations are incorrectly swapped in the generated report. ↩