-
Notifications
You must be signed in to change notification settings - Fork 2k
Go: Avoid combinatorial explosion in mostRecentSideEffect when there are multiple entry points
#21753
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
hvitved
wants to merge
1
commit into
github:main
Choose a base branch
from
hvitved:go/most-recent-side-effect-multi-entry
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
Go: Avoid combinatorial explosion in mostRecentSideEffect when there are multiple entry points
#21753
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -127,10 +127,11 @@ private predicate sideEffectCfg(ControlFlow::Node src, ControlFlow::Node dst) { | |
|
|
||
| /** | ||
| * Holds if `dominator` is the immediate dominator of `node` in | ||
| * the side-effect CFG. | ||
| * the side-effect CFG belonging to `entry`. | ||
| */ | ||
| private predicate iDomEffect(ControlFlow::Node dominator, ControlFlow::Node node) = | ||
| idominance(entryNode/1, sideEffectCfg/2)(_, dominator, node) | ||
| private predicate iDomEffect( | ||
| ControlFlow::Node entry, ControlFlow::Node dominator, ControlFlow::Node node | ||
| ) = idominance(entryNode/1, sideEffectCfg/2)(entry, dominator, node) | ||
|
|
||
| /** | ||
| * Gets the most recent side effect. To be more precise, `result` is a | ||
|
|
@@ -181,15 +182,21 @@ private predicate iDomEffect(ControlFlow::Node dominator, ControlFlow::Node node | |
| * The immediate dominator path to line 015 is 000 - 009 - 012 - 015. | ||
| * Therefore, the most recent side effect for line 015 is line 009. | ||
| */ | ||
| cached | ||
| private ControlFlow::Node mostRecentSideEffect(ControlFlow::Node node) { | ||
| exists(ControlFlow::Node entry | | ||
| entryNode(entry) and | ||
| iDomEffect(entry, result) and | ||
| iDomEffect*(result, node) | ||
| private ControlFlow::Node mostRecentSideEffect(ControlFlow::Node entry, ControlFlow::Node node) { | ||
|
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. Please update the QLDoc to explain what the new parameter does. |
||
| iDomEffect(entry, entry, result) and | ||
| result = node | ||
| or | ||
| exists(ControlFlow::Node mid | | ||
| result = mostRecentSideEffect(entry, mid) and | ||
| iDomEffect(entry, mid, node) | ||
| ) | ||
| } | ||
|
|
||
| cached | ||
| private ControlFlow::Node mostRecentSideEffectUnique(ControlFlow::Node node) { | ||
| result = unique( | | mostRecentSideEffect(_, node)) | ||
| } | ||
|
|
||
| /** Used to represent the "global value number" of an expression. */ | ||
| cached | ||
| private newtype GvnBase = | ||
|
|
@@ -369,10 +376,12 @@ private predicate mkMethodAccess(DataFlow::Node access, GVN qualifier, Method m) | |
| ) | ||
| } | ||
|
|
||
| private predicate analyzableFieldRead(Read fread, DataFlow::Node base, Field f) { | ||
| private predicate analyzableFieldRead( | ||
| Read fread, DataFlow::Node base, Field f, ControlFlow::Node dominator | ||
| ) { | ||
| exists(IR::ReadInstruction r | r = fread.asInstruction() | | ||
| r.readsField(base.asInstruction(), f) and | ||
| strictcount(mostRecentSideEffect(r)) = 1 and | ||
| dominator = mostRecentSideEffectUnique(r) and | ||
| not r.isConst() | ||
| ) | ||
| } | ||
|
|
@@ -381,9 +390,8 @@ private predicate mkFieldRead( | |
| DataFlow::Node fread, GVN qualifier, Field v, ControlFlow::Node dominator | ||
| ) { | ||
| exists(DataFlow::Node base | | ||
| analyzableFieldRead(fread, base, v) and | ||
| qualifier = globalValueNumber(base) and | ||
| dominator = mostRecentSideEffect(fread.asInstruction()) | ||
| analyzableFieldRead(fread, base, v, dominator) and | ||
| qualifier = globalValueNumber(base) | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -421,18 +429,17 @@ private predicate incompleteSsa(ValueEntity v) { | |
| /** | ||
| * Holds if `access` is an access to a variable `target` for which SSA information is incomplete. | ||
| */ | ||
| private predicate analyzableOtherVariable(DataFlow::Node access, ValueEntity target) { | ||
| private predicate analyzableOtherVariable( | ||
|
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. Please update the QLDoc to explain what the new parameter does. |
||
| DataFlow::Node access, ValueEntity target, ControlFlow::Node dominator | ||
| ) { | ||
| access.asInstruction().reads(target) and | ||
| incompleteSsa(target) and | ||
| strictcount(mostRecentSideEffect(access.asInstruction())) = 1 and | ||
| dominator = mostRecentSideEffectUnique(access.asInstruction()) and | ||
| not access.isConst() and | ||
| not target instanceof Function | ||
| } | ||
|
|
||
| private predicate mkOtherVariable(DataFlow::Node access, ValueEntity x, ControlFlow::Node dominator) { | ||
| analyzableOtherVariable(access, x) and | ||
| dominator = mostRecentSideEffect(access.asInstruction()) | ||
| } | ||
| private predicate mkOtherVariable = analyzableOtherVariable/3; | ||
|
|
||
| private predicate analyzableBinaryOp( | ||
| DataFlow::BinaryOperationNode op, string opname, DataFlow::Node lhs, DataFlow::Node rhs | ||
|
|
@@ -463,29 +470,29 @@ private predicate mkUnaryOp(DataFlow::UnaryOperationNode op, GVN child, string o | |
| opname = op.getOperator() | ||
| } | ||
|
|
||
| private predicate analyzableIndexExpr(DataFlow::ElementReadNode ae) { | ||
| strictcount(mostRecentSideEffect(ae.asInstruction())) = 1 and | ||
| private predicate analyzableIndexExpr(DataFlow::ElementReadNode ae, ControlFlow::Node dominator) { | ||
| dominator = mostRecentSideEffectUnique(ae.asInstruction()) and | ||
| not ae.isConst() | ||
| } | ||
|
|
||
| private predicate mkIndex( | ||
| DataFlow::ElementReadNode ae, GVN base, GVN offset, ControlFlow::Node dominator | ||
| ) { | ||
| analyzableIndexExpr(ae) and | ||
| analyzableIndexExpr(ae, dominator) and | ||
| base = globalValueNumber(ae.getBase()) and | ||
| offset = globalValueNumber(ae.getIndex()) and | ||
| dominator = mostRecentSideEffect(ae.asInstruction()) | ||
| offset = globalValueNumber(ae.getIndex()) | ||
| } | ||
|
|
||
| private predicate analyzablePointerDereferenceExpr(DataFlow::PointerDereferenceNode deref) { | ||
| strictcount(mostRecentSideEffect(deref.asInstruction())) = 1 and | ||
| private predicate analyzablePointerDereferenceExpr( | ||
| DataFlow::PointerDereferenceNode deref, ControlFlow::Node dominator | ||
| ) { | ||
| dominator = mostRecentSideEffectUnique(deref.asInstruction()) and | ||
| not deref.isConst() | ||
| } | ||
|
|
||
| private predicate mkDeref(DataFlow::PointerDereferenceNode deref, GVN p, ControlFlow::Node dominator) { | ||
| analyzablePointerDereferenceExpr(deref) and | ||
| p = globalValueNumber(deref.getOperand()) and | ||
| dominator = mostRecentSideEffect(deref.asInstruction()) | ||
| analyzablePointerDereferenceExpr(deref, dominator) and | ||
| p = globalValueNumber(deref.getOperand()) | ||
| } | ||
|
|
||
| private predicate ssaInit(SsaExplicitDefinition ssa, DataFlow::Node rhs) { | ||
|
|
@@ -587,12 +594,12 @@ private predicate analyzableExpr(DataFlow::Node e) { | |
| analyzableConst(e) or | ||
| any(DataFlow::SsaNode ssa).getAUse() = e or | ||
| e instanceof DataFlow::SsaNode or | ||
| analyzableOtherVariable(e, _) or | ||
| analyzableOtherVariable(e, _, _) or | ||
| analyzableMethodAccess(e, _, _) or | ||
| analyzableFieldRead(e, _, _) or | ||
| analyzableFieldRead(e, _, _, _) or | ||
| analyzableCall(e, _) or | ||
| analyzableBinaryOp(e, _, _, _) or | ||
| analyzableUnaryOp(e) or | ||
| analyzableIndexExpr(e) or | ||
| analyzablePointerDereferenceExpr(e) | ||
| analyzableIndexExpr(e, _) or | ||
| analyzablePointerDereferenceExpr(e, _) | ||
| } | ||
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.
I found the QLDoc for this predicate quite hard to understand. I asked copilot to make it clearer and it suggested this.