-
Notifications
You must be signed in to change notification settings - Fork 2k
C++: Support reasoning about whether a phi node overwrites the entire buffer #21836
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
Open
MathiasVP
wants to merge
10
commits into
github:main
Choose a base branch
from
MathiasVP:uncertain-def-more-complete
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8e25240
C++: Add a FP caused by missing certainty around SSA writes from Unin…
MathiasVP b753e7d
C++: Make 'toString' on 'Ssa::Definition' more clear.
MathiasVP e77d85f
C++: Add a new test to test assignment certainty (i.e., whether the e…
MathiasVP 6d5d57a
C++: Add missing overrides.
MathiasVP fc80a24
C++: Slightly refactor certainty computation with a newtype.
MathiasVP 8585bb6
C++: Some writes are always certain regardless of the address.
MathiasVP f40d42c
C++: Perform an SCC reduction to simulate greatest fixed-point semant…
MathiasVP 07b8d7e
C++: Accept test changes in experimental query.
MathiasVP 25c4d9d
Potential fix for pull request finding
MathiasVP d93de54
C++: Consistent use of 'this.getIndirection()' in 'toString'.
MathiasVP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,7 +136,9 @@ private module SourceVariables { | |
| NormalSourceVariable() { this = TNormalSourceVariable(base, ind) } | ||
|
|
||
| final override string toString() { | ||
| result = repeatStars(this.getIndirection()) + base.toString() | ||
| if this.getIndirection() = 0 | ||
| then result = "&" + base.toString() | ||
| else result = repeatStars(this.getIndirection() - 1) + base.toString() | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -157,7 +159,9 @@ private module SourceVariables { | |
| } | ||
|
|
||
| final override string toString() { | ||
| result = repeatStars(this.getIndirection()) + base.toString() + " [before crement]" | ||
| if this.getIndirection() = 0 | ||
| then result = "&" + base.toString() + " [before crement]" | ||
| else result = repeatStars(this.getIndirection() - 1) + base.toString() + " [before crement]" | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1353,6 +1357,53 @@ class PhiNode extends Definition instanceof SsaImpl::PhiNode { | |
| final predicate hasInputFromBlock(Definition input, IRBlock bb) { | ||
| phiHasInputFromBlock(this, input, bb) | ||
| } | ||
|
|
||
| override int getIndirection() { result = this.getSourceVariable().getIndirection() } | ||
|
|
||
| override predicate isCertain() { | ||
| // If this phi node is part of a phi cycle of phi nodes the least | ||
| // fixed-point semantics of datalog means we don't get the right answer. | ||
| // So we perform an SCC reduction to simulate greatest fixed-point semantics. | ||
| getCycle(this).isCertain() | ||
| or | ||
| // If there is no cycle we get the right semantics through traditional | ||
| // recursion. | ||
| not exists(getCycle(this)) and | ||
| forex(Definition inp | inp = this.getAnInput() | inp.isCertain()) | ||
| } | ||
|
|
||
| final override Declaration getFunction() { | ||
| result = SsaImpl::PhiNode.super.getBasicBlock().getEnclosingFunction() | ||
| } | ||
| } | ||
|
|
||
| private PhiNode getAnInput(PhiNode phi) { result = phi.getAnInput() } | ||
|
|
||
| private predicate definitionCycle(PhiNode phi) { getAnInput+(phi) = phi } | ||
|
|
||
| private predicate hasAnInput(PhiNode phi1, PhiNode phi2) { | ||
| definitionCycle(phi1) and | ||
| definitionCycle(phi2) and | ||
| getAnInput(phi1) = phi2 | ||
| } | ||
|
|
||
| private module PhiCycleEquivalence = QlBuiltins::EquivalenceRelation<PhiNode, hasAnInput/2>; | ||
|
|
||
| private PhiCycle getCycle(PhiNode phi) { result.getAPhiNode() = phi } | ||
|
|
||
| private class PhiCycle extends PhiCycleEquivalence::EquivalenceClass { | ||
| PhiNode getAPhiNode() { PhiCycleEquivalence::getEquivalenceClass(result) = this } | ||
|
|
||
| predicate hasPhiNode(PhiNode phi) { this.getAPhiNode() = phi } | ||
|
|
||
| string toString() { result = strictconcat(this.getAPhiNode().toString(), ", ") } | ||
|
|
||
| predicate isCertain() { | ||
| // A phi cycle is certain if all of the inputs into the phi cycle is certain. | ||
|
MathiasVP marked this conversation as resolved.
|
||
| forex(PhiNode phi | phi = this.getAPhiNode() | | ||
| forall(PhiNode inp | phi.getAnInput() = inp and not this.hasPhiNode(inp) | inp.isCertain()) | ||
| ) | ||
|
Comment on lines
+1403
to
+1405
Contributor
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. Factor out the range to make the recursion simpler. Add a member predicate and use this to define the recursive forall: Note also that I've changed the type of |
||
| } | ||
| } | ||
|
|
||
| /** An static single assignment (SSA) definition. */ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
This is wrong. You're attempting to define SCC-internal edges here, but if two SCCs are adjacent then this will accidentally merge them. You need this instead: