Skip to content

Commit 5bc4ccf

Browse files
committedMar 13, 2025
Refactor: reorder parameters of SsaDefinition.definesAt
Match the order used in the shared SSA library
1 parent a15ab99 commit 5bc4ccf

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed
 

‎go/ql/lib/semmle/go/dataflow/SSA.qll

+9-9
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class SsaDefinition extends TSsaDefinition {
127127
* Phi nodes are considered to be at index `-1`, all other definitions at the index of
128128
* the control flow node they correspond to.
129129
*/
130-
abstract predicate definesAt(ReachableBasicBlock bb, int idx, SsaSourceVariable v);
130+
abstract predicate definesAt(SsaSourceVariable v, ReachableBasicBlock bb, int idx);
131131

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

190-
override predicate definesAt(ReachableBasicBlock bb, int i, SsaSourceVariable v) {
190+
override predicate definesAt(SsaSourceVariable v, ReachableBasicBlock bb, int i) {
191191
this = TExplicitDef(bb, i, v)
192192
}
193193

194-
override ReachableBasicBlock getBasicBlock() { this.definesAt(result, _, _) }
194+
override ReachableBasicBlock getBasicBlock() { this.definesAt(_, result, _) }
195195

196-
override SsaSourceVariable getSourceVariable() { this = TExplicitDef(_, _, result) }
196+
override SsaSourceVariable getSourceVariable() { this.definesAt(result, _, _) }
197197

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

249-
override ReachableBasicBlock getBasicBlock() { this.definesAt(result, _, _) }
249+
override ReachableBasicBlock getBasicBlock() { this.definesAt(_, result, _) }
250250

251-
override SsaSourceVariable getSourceVariable() { this.definesAt(_, _, result) }
251+
override SsaSourceVariable getSourceVariable() { this.definesAt(result, _, _) }
252252

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

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

257257
override Location getLocation() {
258-
exists(ReachableBasicBlock bb, int i | this.definesAt(bb, i, _) |
258+
exists(ReachableBasicBlock bb, int i | this.definesAt(_, bb, i) |
259259
result = bb.getNode(i).getLocation()
260260
)
261261
}
@@ -288,7 +288,7 @@ class SsaPhiNode extends SsaPseudoDefinition, TPhi {
288288
result = getDefReachingEndOf(this.getBasicBlock().getAPredecessor(), this.getSourceVariable())
289289
}
290290

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

‎go/ql/lib/semmle/go/dataflow/SsaImpl.qll

+9-9
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private module Internal {
7171
pragma[noinline]
7272
private predicate inDefDominanceFrontier(ReachableJoinBlock bb, SsaSourceVariable v) {
7373
exists(ReachableBasicBlock defbb, SsaDefinition def |
74-
def.definesAt(defbb, _, v) and
74+
def.definesAt(v, defbb, _) and
7575
bb.inDominanceFrontierOf(defbb)
7676
)
7777
}
@@ -206,7 +206,7 @@ private module Internal {
206206
private predicate ssaRef(ReachableBasicBlock bb, int i, SsaSourceVariable v, RefKind k) {
207207
useAt(bb, i, v) and k = ReadRef()
208208
or
209-
any(SsaDefinition def).definesAt(bb, i, v) and k = WriteRef()
209+
any(SsaDefinition def).definesAt(v, bb, i) and k = WriteRef()
210210
}
211211

212212
/**
@@ -248,7 +248,7 @@ private module Internal {
248248
*/
249249
private SsaDefinition getLocalDefinition(ReachableBasicBlock bb, int i, SsaSourceVariable v) {
250250
exists(int r | r = rewindReads(bb, i, v) |
251-
exists(int j | result.definesAt(bb, j, v) and ssaRefRank(bb, j, v, _) = r - 1)
251+
exists(int j | result.definesAt(v, bb, j) and ssaRefRank(bb, j, v, _) = r - 1)
252252
)
253253
}
254254

@@ -270,7 +270,7 @@ private module Internal {
270270
exists(int lastRef | lastRef = max(int i | ssaRef(bb, i, v, _)) |
271271
result = getLocalDefinition(bb, lastRef, v)
272272
or
273-
result.definesAt(bb, lastRef, v) and
273+
result.definesAt(v, bb, lastRef) and
274274
liveAtSuccEntry(bb, v)
275275
)
276276
or
@@ -279,7 +279,7 @@ private module Internal {
279279
// then one must dominate the other, so we can find the reaching definition
280280
// by following the idominance relation backwards.
281281
result = getDefReachingEndOfImmediateDominator(bb, v) and
282-
not exists(SsaDefinition ssa | ssa.definesAt(bb, _, v)) and
282+
not exists(SsaDefinition ssa | ssa.definesAt(v, bb, _)) and
283283
liveAtSuccEntry(bb, v)
284284
}
285285

@@ -412,7 +412,7 @@ private module Internal {
412412
predicate firstUse(SsaDefinition def, IR::Instruction use) {
413413
exists(SsaSourceVariable v, ReachableBasicBlock b1, int i1, ReachableBasicBlock b2, int i2 |
414414
adjacentVarRefs(v, b1, i1, b2, i2) and
415-
def.definesAt(b1, i1, v) and
415+
def.definesAt(v, b1, i1) and
416416
variableUse(v, use, b2, i2)
417417
)
418418
or
@@ -421,8 +421,8 @@ private module Internal {
421421
int i2
422422
|
423423
adjacentVarRefs(v, b1, i1, b2, i2) and
424-
def.definesAt(b1, i1, v) and
425-
redef.definesAt(b2, i2, v) and
424+
def.definesAt(v, b1, i1) and
425+
redef.definesAt(v, b2, i2) and
426426
firstUse(redef, use)
427427
)
428428
}
@@ -457,7 +457,7 @@ private module Internal {
457457
|
458458
adjacentVarRefs(v, b1, i1, b2, i2) and
459459
variableUse(v, use1, b1, i1) and
460-
def.definesAt(b2, i2, v) and
460+
def.definesAt(v, b2, i2) and
461461
firstUse(def, use2)
462462
)
463463
}

0 commit comments

Comments
 (0)