Skip to content

Commit eec5e66

Browse files
Claudeowen-mc
authored andcommitted
Go: deprecate ConditionGuardNode
1 parent 114e0c0 commit eec5e66

2 files changed

Lines changed: 47 additions & 42 deletions

File tree

‎go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll‎

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,12 @@ module ControlFlow {
258258
}
259259

260260
/**
261+
* DEPRECATED: Use `Guard` from `semmle.go.controlflow.Guards` instead.
262+
*
261263
* A control-flow node recording the fact that a certain expression has a known
262264
* Boolean value at this point in the program.
263265
*/
264-
class ConditionGuardNode extends IR::Instruction {
266+
deprecated class ConditionGuardNode extends IR::Instruction {
265267
Expr cond;
266268
boolean outcome;
267269

@@ -292,43 +294,69 @@ module ControlFlow {
292294
b = false
293295
}
294296

295-
/** Holds if this guard ensures that the result of `nd` is `b`. */
296-
predicate ensures(DataFlow::Node nd, boolean b) {
297+
/**
298+
* DEPRECATED: Use `Guard.controls` from `semmle.go.controlflow.Guards`
299+
* instead.
300+
*
301+
* Holds if this guard ensures that the result of `nd` is `b`.
302+
*/
303+
deprecated predicate ensures(DataFlow::Node nd, boolean b) {
297304
this.ensuresAux(any(Expr e | nd = DataFlow::exprNode(e)), b)
298305
}
299306

300-
/** Holds if this guard ensures that `lesser <= greater + bias` holds. */
301-
predicate ensuresLeq(DataFlow::Node lesser, DataFlow::Node greater, int bias) {
307+
/**
308+
* DEPRECATED: Use `guardEnsuresLeq` from `semmle.go.controlflow.Guards`
309+
* instead.
310+
*
311+
* Holds if this guard ensures that `lesser <= greater + bias` holds.
312+
*/
313+
deprecated predicate ensuresLeq(DataFlow::Node lesser, DataFlow::Node greater, int bias) {
302314
exists(DataFlow::RelationalComparisonNode rel, boolean b |
303-
this.ensures(rel, b) and
315+
this.ensuresAux(rel.asExpr(), b) and
304316
rel.leq(b, lesser, greater, bias)
305317
)
306318
or
307-
this.ensuresEq(lesser, greater) and
319+
exists(DataFlow::EqualityTestNode eq, boolean b |
320+
this.ensuresAux(eq.asExpr(), b) and
321+
eq.eq(b, lesser, greater)
322+
) and
308323
bias = 0
309324
}
310325

311-
/** Holds if this guard ensures that `i = j` holds. */
312-
predicate ensuresEq(DataFlow::Node i, DataFlow::Node j) {
326+
/**
327+
* DEPRECATED: Use `guardEnsuresEq` from `semmle.go.controlflow.Guards`
328+
* instead.
329+
*
330+
* Holds if this guard ensures that `i = j` holds.
331+
*/
332+
deprecated predicate ensuresEq(DataFlow::Node i, DataFlow::Node j) {
313333
exists(DataFlow::EqualityTestNode eq, boolean b |
314-
this.ensures(eq, b) and
334+
this.ensuresAux(eq.asExpr(), b) and
315335
eq.eq(b, i, j)
316336
)
317337
}
318338

319-
/** Holds if this guard ensures that `i != j` holds. */
320-
predicate ensuresNeq(DataFlow::Node i, DataFlow::Node j) {
339+
/**
340+
* DEPRECATED: Use `guardEnsuresNeq` from `semmle.go.controlflow.Guards`
341+
* instead.
342+
*
343+
* Holds if this guard ensures that `i != j` holds.
344+
*/
345+
deprecated predicate ensuresNeq(DataFlow::Node i, DataFlow::Node j) {
321346
exists(DataFlow::EqualityTestNode eq, boolean b |
322-
this.ensures(eq, b.booleanNot()) and
347+
this.ensuresAux(eq.asExpr(), b.booleanNot()) and
323348
eq.eq(b, i, j)
324349
)
325350
}
326351

327352
/**
353+
* DEPRECATED: Use `Guard.controls` from `semmle.go.controlflow.Guards`
354+
* instead.
355+
*
328356
* Holds if this guard dominates basic block `bb`, that is, the guard
329357
* is known to hold at `bb`.
330358
*/
331-
predicate dominates(ReachableBasicBlock bb) {
359+
deprecated predicate dominates(ReachableBasicBlock bb) {
332360
this = bb.getANode() or
333361
this.dominates(bb.getImmediateDominator())
334362
}

‎go/ql/lib/semmle/go/controlflow/IR.qll‎

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,6 @@ module IR {
3232
n.isAfterValue(cc, any(MatchingSuccessor t | t.isMatch()))
3333
}
3434

35-
/**
36-
* Holds if `n` records a boolean outcome, or the matching outcome of an
37-
* expressionless switch case condition.
38-
*/
39-
private predicate isConditionGuardNode(ControlFlow::Node n) {
40-
n.isAfterTrue(_)
41-
or
42-
n.isAfterFalse(_)
43-
or
44-
exists(Expr condition, MatchingSuccessor successor |
45-
condition =
46-
any(ExpressionSwitchStmt switch | not exists(switch.getExpr())).getACase().getAnExpr() and
47-
n.isAfterValue(condition, successor)
48-
)
49-
}
50-
5135
/** Gets the CFG node representing a basic literal, function literal, or plain identifier reference. */
5236
cached
5337
private ControlFlow::Node leafEvaluation(Expr leaf) {
@@ -72,17 +56,17 @@ module IR {
7256
or
7357
this.isAdditional(_, _)
7458
or
75-
isConditionGuardNode(this)
76-
or
7759
// The successful-match node of a type-switch case that binds an implicit
7860
// variable hosts that variable's declaration/assignment (see
7961
// `TypeSwitchImplicitVariableInstruction`).
8062
typeSwitchCaseMatch(this, _)
8163
or
8264
// `NotExpr` and `LogicalBinaryExpr` are not in `postOrInOrder`, so they
83-
// have no `isIn` node. Use their combined after-node as the value-producing
84-
// instruction, but not a value-specific after-node, which is already a
85-
// `ConditionGuardInstruction`.
65+
// have no `isIn` node. When such an expression is not in a conditional
66+
// context (so it has a single combined after-node rather than per-branch
67+
// value-after-nodes), use that after-node as the value-producing
68+
// instruction. In conditional contexts the value is already split
69+
// across branches, so no separate value instruction is needed.
8670
exists(Expr e |
8771
(e instanceof NotExpr or e instanceof LogicalBinaryExpr) and
8872
this.isAfter(e) and
@@ -182,8 +166,6 @@ module IR {
182166
or
183167
this instanceof GoInstruction and result = "go"
184168
or
185-
this instanceof ConditionGuardInstruction and result = "condition guard"
186-
or
187169
this instanceof ReturnInstruction and result = "return"
188170
or
189171
this instanceof WriteResultInstruction and result = "result write"
@@ -207,11 +189,6 @@ module IR {
207189
}
208190
}
209191

210-
/** A condition guard instruction, representing a known boolean outcome for a condition. */
211-
private class ConditionGuardInstruction extends Instruction {
212-
ConditionGuardInstruction() { isConditionGuardNode(this) }
213-
}
214-
215192
/**
216193
* An IR instruction representing the evaluation of an expression.
217194
*/

0 commit comments

Comments
 (0)