Skip to content

Commit def5d61

Browse files
Claudeowen-mc
authored andcommitted
Go: deprecate ConditionGuardNode
1 parent 19d7fbf commit def5d61

3 files changed

Lines changed: 47 additions & 47 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: deprecated
3+
---
4+
* `ControlFlow::ConditionGuardNode` has been deprecated and no longer has any instances. Use the `Guard` class and the `guardEnsures`, `guardEnsuresEq`, `guardEnsuresNeq` and `guardEnsuresLeq` predicates from `semmle.go.controlflow.Guards` instead.

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

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,12 @@ module ControlFlow {
261261
}
262262

263263
/**
264+
* DEPRECATED: Use `Guard` from `semmle.go.controlflow.Guards` instead.
265+
*
264266
* A control-flow node recording the fact that a certain expression has a known
265267
* Boolean value at this point in the program.
266268
*/
267-
class ConditionGuardNode extends IR::Instruction {
269+
deprecated class ConditionGuardNode extends IR::Instruction {
268270
Expr cond;
269271
boolean outcome;
270272

@@ -297,43 +299,69 @@ module ControlFlow {
297299
b = false
298300
}
299301

300-
/** Holds if this guard ensures that the result of `nd` is `b`. */
301-
predicate ensures(DataFlow::Node nd, boolean b) {
302+
/**
303+
* DEPRECATED: Use `Guard.controls` from `semmle.go.controlflow.Guards`
304+
* instead.
305+
*
306+
* Holds if this guard ensures that the result of `nd` is `b`.
307+
*/
308+
deprecated predicate ensures(DataFlow::Node nd, boolean b) {
302309
this.ensuresAux(any(Expr e | nd = DataFlow::exprNode(e)), b)
303310
}
304311

305-
/** Holds if this guard ensures that `lesser <= greater + bias` holds. */
306-
predicate ensuresLeq(DataFlow::Node lesser, DataFlow::Node greater, int bias) {
312+
/**
313+
* DEPRECATED: Use `guardEnsuresLeq` from `semmle.go.controlflow.Guards`
314+
* instead.
315+
*
316+
* Holds if this guard ensures that `lesser <= greater + bias` holds.
317+
*/
318+
deprecated predicate ensuresLeq(DataFlow::Node lesser, DataFlow::Node greater, int bias) {
307319
exists(DataFlow::RelationalComparisonNode rel, boolean b |
308-
this.ensures(rel, b) and
320+
this.ensuresAux(rel.asExpr(), b) and
309321
rel.leq(b, lesser, greater, bias)
310322
)
311323
or
312-
this.ensuresEq(lesser, greater) and
324+
exists(DataFlow::EqualityTestNode eq, boolean b |
325+
this.ensuresAux(eq.asExpr(), b) and
326+
eq.eq(b, lesser, greater)
327+
) and
313328
bias = 0
314329
}
315330

316-
/** Holds if this guard ensures that `i = j` holds. */
317-
predicate ensuresEq(DataFlow::Node i, DataFlow::Node j) {
331+
/**
332+
* DEPRECATED: Use `guardEnsuresEq` from `semmle.go.controlflow.Guards`
333+
* instead.
334+
*
335+
* Holds if this guard ensures that `i = j` holds.
336+
*/
337+
deprecated predicate ensuresEq(DataFlow::Node i, DataFlow::Node j) {
318338
exists(DataFlow::EqualityTestNode eq, boolean b |
319-
this.ensures(eq, b) and
339+
this.ensuresAux(eq.asExpr(), b) and
320340
eq.eq(b, i, j)
321341
)
322342
}
323343

324-
/** Holds if this guard ensures that `i != j` holds. */
325-
predicate ensuresNeq(DataFlow::Node i, DataFlow::Node j) {
344+
/**
345+
* DEPRECATED: Use `guardEnsuresNeq` from `semmle.go.controlflow.Guards`
346+
* instead.
347+
*
348+
* Holds if this guard ensures that `i != j` holds.
349+
*/
350+
deprecated predicate ensuresNeq(DataFlow::Node i, DataFlow::Node j) {
326351
exists(DataFlow::EqualityTestNode eq, boolean b |
327-
this.ensures(eq, b.booleanNot()) and
352+
this.ensuresAux(eq.asExpr(), b.booleanNot()) and
328353
eq.eq(b, i, j)
329354
)
330355
}
331356

332357
/**
358+
* DEPRECATED: Use `Guard.controls` from `semmle.go.controlflow.Guards`
359+
* instead.
360+
*
333361
* Holds if this guard dominates basic block `bb`, that is, the guard
334362
* is known to hold at `bb`.
335363
*/
336-
predicate dominates(ReachableBasicBlock bb) {
364+
deprecated predicate dominates(ReachableBasicBlock bb) {
337365
this = bb.getANode() or
338366
this.dominates(bb.getImmediateDominator())
339367
}

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

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,6 @@ module IR {
5858
n.isAfterValue(cc, any(MatchingSuccessor t | t.isMatch()))
5959
}
6060

61-
/**
62-
* Holds if `n` is a genuine boolean condition-guard node: an "after" node
63-
* that records exactly one of the true/false outcomes of a boolean
64-
* condition.
65-
*
66-
* The shared CFG library's `isAfterTrue`/`isAfterFalse` are deliberately
67-
* permissive when used for step-endpoint matching: a plain "after" node (or
68-
* a merged leaf node) satisfies both of them. A real guard node is
69-
* distinguished by satisfying exactly one of them.
70-
*/
71-
private predicate isConditionGuardNode(ControlFlow::Node n) {
72-
n.isAfterTrue(_) and not n.isAfterFalse(_)
73-
or
74-
n.isAfterFalse(_) and not n.isAfterTrue(_)
75-
or
76-
exists(Expr condition, MatchingSuccessor successor |
77-
condition =
78-
any(ExpressionSwitchStmt switch | not exists(switch.getExpr())).getACase().getAnExpr() and
79-
n.isAfterValue(condition, successor)
80-
)
81-
}
82-
8361
/**
8462
* An IR instruction.
8563
*/
@@ -89,8 +67,6 @@ module IR {
8967
or
9068
this.isAdditional(_, _)
9169
or
92-
isConditionGuardNode(this)
93-
or
9470
// The successful-match node of a type-switch case that binds an implicit
9571
// variable hosts that variable's declaration/assignment (see
9672
// `TypeSwitchImplicitVariableInstruction`).
@@ -101,8 +77,7 @@ module IR {
10177
// context (so it has a single combined after-node rather than per-branch
10278
// value-after-nodes), use that after-node as the value-producing
10379
// instruction. In conditional contexts the value is already split
104-
// across branches and the `ConditionGuardInstruction` for each branch
105-
// captures the outcome, so no separate value instruction is needed.
80+
// across branches, so no separate value instruction is needed.
10681
exists(Expr e |
10782
(e instanceof NotExpr or e instanceof LogicalBinaryExpr) and
10883
not isInBooleanCondContext(e) and
@@ -199,8 +174,6 @@ module IR {
199174
or
200175
this instanceof GoInstruction and result = "go"
201176
or
202-
this instanceof ConditionGuardInstruction and result = "condition guard"
203-
or
204177
this instanceof ReturnInstruction and result = "return"
205178
or
206179
this instanceof WriteResultInstruction and result = "result write"
@@ -224,11 +197,6 @@ module IR {
224197
}
225198
}
226199

227-
/** A condition guard instruction, representing a known boolean outcome for a condition. */
228-
private class ConditionGuardInstruction extends Instruction {
229-
ConditionGuardInstruction() { isConditionGuardNode(this) }
230-
}
231-
232200
/**
233201
* An IR instruction representing the evaluation of an expression.
234202
*/

0 commit comments

Comments
 (0)