Skip to content

Commit 3a0d29b

Browse files
owen-mcCopilot
andcommitted
Go: deprecate ConditionGuardNode
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent bbc3f48 commit 3a0d29b

4 files changed

Lines changed: 53 additions & 17 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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ module IR {
8080
typeSwitchCaseMatch(this, _)
8181
or
8282
// `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`.
83+
// have no `isIn` node. When such an expression is not in a conditional
84+
// context (so it has a single combined after-node rather than per-branch
85+
// value-after-nodes), use that after-node as the value-producing
86+
// instruction. In conditional contexts the value is already split
87+
// across branches, so no separate value instruction is needed.
8688
exists(Expr e |
8789
(e instanceof NotExpr or e instanceof LogicalBinaryExpr) and
8890
this.isAfter(e) and

‎go/ql/test/library-tests/semmle/go/controlflow/Guards/Guards.expected‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,5 @@ modelBarrierResult
271271
| guards.go:360:27:360:33 | pointer | model null | model-null |
272272
| guards.go:363:31:363:37 | pointer | model not null | model-not-null |
273273
| guards.go:366:34:366:40 | pointer | model no exception | model-no-exception |
274+
legacyConditionGuardCount
275+
| 88 |

‎go/ql/test/library-tests/semmle/go/controlflow/Guards/Guards.ql‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ query predicate modelBarrierResult(DataFlow::Node node, string label, string kin
4949
barrierNode(node, kind, _)
5050
)
5151
}
52+
53+
deprecated query predicate legacyConditionGuardCount(int guardCount) {
54+
guardCount = count(ControlFlow::ConditionGuardNode guard)
55+
}

0 commit comments

Comments
 (0)