Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Go/feature/shared ssa library #19011

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

Draft
wants to merge 24 commits into
base: main
Choose a base branch
Loading
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8d844e8
Switch to use-use dataflow. This will make post-update nodes easy to …
owen-mc Nov 10, 2023
06404d8
Add missing QLDoc
owen-mc Nov 28, 2023
d8002a0
Clean up code in basicLocalFlowStep
owen-mc Nov 28, 2023
1904daf
Include first step from SsaVariableCapture
owen-mc Nov 28, 2023
9d88795
Adjust SafeFormatArgumentSanitizer to use-use flow
owen-mc Nov 29, 2023
f67555a
Test result that was missing is now found
owen-mc Nov 10, 2023
03204cf
Expected changes in dataflow edges
owen-mc Nov 10, 2023
487dba3
f extra edge
owen-mc Nov 29, 2023
c040c9a
Line numbers change because 3 lines were added
owen-mc Nov 29, 2023
8b6a173
Changes in edges in .expected files
owen-mc Nov 29, 2023
ef9f740
Extra edge to captured variable
owen-mc Nov 29, 2023
ad0b836
Fix Allocation Size Overflow for use-use flow
owen-mc Nov 30, 2023
68128b3
Expected test changes (odd because post update nodes are still at the…
owen-mc Nov 30, 2023
818ebea
Optimise join order for varBlockReaches
smowton Jan 26, 2021
6c863c6
Fix IncorrectIntegerConversion for use-use flow
owen-mc Nov 30, 2023
5a09b15
accept edge changes
owen-mc Mar 6, 2025
7f5e973
Accept fixed test result
owen-mc Mar 6, 2025
c308978
Make insecure randomness test more realistic
owen-mc Mar 6, 2025
a3dbc5e
Fix TypeAssertionCheck to not block successor flow
owen-mc Mar 7, 2025
635b722
Improve SSA tests for variables in closures
owen-mc Mar 12, 2025
a15ab99
Invoke `SsaImplCommon::Make`
owen-mc Mar 1, 2025
5bc4ccf
Refactor: reorder parameters of `SsaDefinition.definesAt`
owen-mc Mar 8, 2025
521b971
Base SSA classes on shared SSA library
owen-mc Mar 10, 2025
d49f05f
Test changes
owen-mc Mar 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor: reorder parameters of SsaDefinition.definesAt
Match the order used in the shared SSA library
  • Loading branch information
owen-mc committed Mar 13, 2025
commit 5bc4ccfcd51ffdbbe2f2a382efcb911e22ae51a7
18 changes: 9 additions & 9 deletions 18 go/ql/lib/semmle/go/dataflow/SSA.qll
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class SsaDefinition extends TSsaDefinition {
* Phi nodes are considered to be at index `-1`, all other definitions at the index of
* the control flow node they correspond to.
*/
abstract predicate definesAt(ReachableBasicBlock bb, int idx, SsaSourceVariable v);
abstract predicate definesAt(SsaSourceVariable v, ReachableBasicBlock bb, int idx);

/**
* INTERNAL: Use `toString()` instead.
Expand Down Expand Up @@ -187,13 +187,13 @@ class SsaExplicitDefinition extends SsaDefinition, TExplicitDef {
/** Gets the right-hand side of the definition. */
IR::Instruction getRhs() { this.getInstruction().writes(_, result) }

override predicate definesAt(ReachableBasicBlock bb, int i, SsaSourceVariable v) {
override predicate definesAt(SsaSourceVariable v, ReachableBasicBlock bb, int i) {
this = TExplicitDef(bb, i, v)
}

override ReachableBasicBlock getBasicBlock() { this.definesAt(result, _, _) }
override ReachableBasicBlock getBasicBlock() { this.definesAt(_, result, _) }

override SsaSourceVariable getSourceVariable() { this = TExplicitDef(_, _, result) }
override SsaSourceVariable getSourceVariable() { this.definesAt(result, _, _) }

override string prettyPrintRef() {
exists(Location loc | loc = this.getLocation() |
Expand Down Expand Up @@ -242,20 +242,20 @@ abstract class SsaImplicitDefinition extends SsaDefinition {
* at any function call that may affect the value of the variable.
*/
class SsaVariableCapture extends SsaImplicitDefinition, TCapture {
override predicate definesAt(ReachableBasicBlock bb, int i, SsaSourceVariable v) {
override predicate definesAt(SsaSourceVariable v, ReachableBasicBlock bb, int i) {
this = TCapture(bb, i, v)
}

override ReachableBasicBlock getBasicBlock() { this.definesAt(result, _, _) }
override ReachableBasicBlock getBasicBlock() { this.definesAt(_, result, _) }

override SsaSourceVariable getSourceVariable() { this.definesAt(_, _, result) }
override SsaSourceVariable getSourceVariable() { this.definesAt(result, _, _) }

override string getKind() { result = "capture" }

override string prettyPrintDef() { result = "capture variable " + this.getSourceVariable() }

override Location getLocation() {
exists(ReachableBasicBlock bb, int i | this.definesAt(bb, i, _) |
exists(ReachableBasicBlock bb, int i | this.definesAt(_, bb, i) |
result = bb.getNode(i).getLocation()
)
}
Expand Down Expand Up @@ -288,7 +288,7 @@ class SsaPhiNode extends SsaPseudoDefinition, TPhi {
result = getDefReachingEndOf(this.getBasicBlock().getAPredecessor(), this.getSourceVariable())
}

override predicate definesAt(ReachableBasicBlock bb, int i, SsaSourceVariable v) {
override predicate definesAt(SsaSourceVariable v, ReachableBasicBlock bb, int i) {
bb = this.getBasicBlock() and v = this.getSourceVariable() and i = -1
}

Expand Down
18 changes: 9 additions & 9 deletions 18 go/ql/lib/semmle/go/dataflow/SsaImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private module Internal {
pragma[noinline]
private predicate inDefDominanceFrontier(ReachableJoinBlock bb, SsaSourceVariable v) {
exists(ReachableBasicBlock defbb, SsaDefinition def |
def.definesAt(defbb, _, v) and
def.definesAt(v, defbb, _) and
bb.inDominanceFrontierOf(defbb)
)
}
Expand Down Expand Up @@ -206,7 +206,7 @@ private module Internal {
private predicate ssaRef(ReachableBasicBlock bb, int i, SsaSourceVariable v, RefKind k) {
useAt(bb, i, v) and k = ReadRef()
or
any(SsaDefinition def).definesAt(bb, i, v) and k = WriteRef()
any(SsaDefinition def).definesAt(v, bb, i) and k = WriteRef()
}

/**
Expand Down Expand Up @@ -248,7 +248,7 @@ private module Internal {
*/
private SsaDefinition getLocalDefinition(ReachableBasicBlock bb, int i, SsaSourceVariable v) {
exists(int r | r = rewindReads(bb, i, v) |
exists(int j | result.definesAt(bb, j, v) and ssaRefRank(bb, j, v, _) = r - 1)
exists(int j | result.definesAt(v, bb, j) and ssaRefRank(bb, j, v, _) = r - 1)
)
}

Expand All @@ -270,7 +270,7 @@ private module Internal {
exists(int lastRef | lastRef = max(int i | ssaRef(bb, i, v, _)) |
result = getLocalDefinition(bb, lastRef, v)
or
result.definesAt(bb, lastRef, v) and
result.definesAt(v, bb, lastRef) and
liveAtSuccEntry(bb, v)
)
or
Expand All @@ -279,7 +279,7 @@ private module Internal {
// then one must dominate the other, so we can find the reaching definition
// by following the idominance relation backwards.
result = getDefReachingEndOfImmediateDominator(bb, v) and
not exists(SsaDefinition ssa | ssa.definesAt(bb, _, v)) and
not exists(SsaDefinition ssa | ssa.definesAt(v, bb, _)) and
liveAtSuccEntry(bb, v)
}

Expand Down Expand Up @@ -412,7 +412,7 @@ private module Internal {
predicate firstUse(SsaDefinition def, IR::Instruction use) {
exists(SsaSourceVariable v, ReachableBasicBlock b1, int i1, ReachableBasicBlock b2, int i2 |
adjacentVarRefs(v, b1, i1, b2, i2) and
def.definesAt(b1, i1, v) and
def.definesAt(v, b1, i1) and
variableUse(v, use, b2, i2)
)
or
Expand All @@ -421,8 +421,8 @@ private module Internal {
int i2
|
adjacentVarRefs(v, b1, i1, b2, i2) and
def.definesAt(b1, i1, v) and
redef.definesAt(b2, i2, v) and
def.definesAt(v, b1, i1) and
redef.definesAt(v, b2, i2) and
firstUse(redef, use)
)
}
Expand Down Expand Up @@ -457,7 +457,7 @@ private module Internal {
|
adjacentVarRefs(v, b1, i1, b2, i2) and
variableUse(v, use1, b1, i1) and
def.definesAt(b2, i2, v) and
def.definesAt(v, b2, i2) and
firstUse(def, use2)
)
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.