Skip to content

Commit f8092fc

Browse files
Claudeowen-mc
andauthored
Go: deprecate the guard-reasoning members of ConditionGuardNode
Agent-Logs-Url: https://github.com/github/codeql/sessions/d505ffcf-a693-4b67-9dc3-54fa92e27896 Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
1 parent 3c0d5a5 commit f8092fc

2 files changed

Lines changed: 43 additions & 13 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+
* The guard-reasoning member predicates of `ControlFlow::ConditionGuardNode` (`ensures`, `ensuresLeq`, `ensuresEq`, `ensuresNeq` and `dominates`) have been deprecated. Use the `Guard` class and the `guardEnsures`, `guardEnsuresEq`, `guardEnsuresNeq` and `guardEnsuresLeq` predicates from `semmle.go.controlflow.Guards` instead. The `ConditionGuardNode` class itself remains, since it is part of the control-flow graph.

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

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,43 +270,69 @@ module ControlFlow {
270270
b = false
271271
}
272272

273-
/** Holds if this guard ensures that the result of `nd` is `b`. */
274-
predicate ensures(DataFlow::Node nd, boolean b) {
273+
/**
274+
* DEPRECATED: Use `Guard.controls` from `semmle.go.controlflow.Guards`
275+
* instead.
276+
*
277+
* Holds if this guard ensures that the result of `nd` is `b`.
278+
*/
279+
deprecated predicate ensures(DataFlow::Node nd, boolean b) {
275280
this.ensuresAux(any(Expr e | nd = DataFlow::exprNode(e)), b)
276281
}
277282

278-
/** Holds if this guard ensures that `lesser <= greater + bias` holds. */
279-
predicate ensuresLeq(DataFlow::Node lesser, DataFlow::Node greater, int bias) {
283+
/**
284+
* DEPRECATED: Use `guardEnsuresLeq` from `semmle.go.controlflow.Guards`
285+
* instead.
286+
*
287+
* Holds if this guard ensures that `lesser <= greater + bias` holds.
288+
*/
289+
deprecated predicate ensuresLeq(DataFlow::Node lesser, DataFlow::Node greater, int bias) {
280290
exists(DataFlow::RelationalComparisonNode rel, boolean b |
281-
this.ensures(rel, b) and
291+
this.ensuresAux(rel.asExpr(), b) and
282292
rel.leq(b, lesser, greater, bias)
283293
)
284294
or
285-
this.ensuresEq(lesser, greater) and
295+
exists(DataFlow::EqualityTestNode eq, boolean b |
296+
this.ensuresAux(eq.asExpr(), b) and
297+
eq.eq(b, lesser, greater)
298+
) and
286299
bias = 0
287300
}
288301

289-
/** Holds if this guard ensures that `i = j` holds. */
290-
predicate ensuresEq(DataFlow::Node i, DataFlow::Node j) {
302+
/**
303+
* DEPRECATED: Use `guardEnsuresEq` from `semmle.go.controlflow.Guards`
304+
* instead.
305+
*
306+
* Holds if this guard ensures that `i = j` holds.
307+
*/
308+
deprecated predicate ensuresEq(DataFlow::Node i, DataFlow::Node j) {
291309
exists(DataFlow::EqualityTestNode eq, boolean b |
292-
this.ensures(eq, b) and
310+
this.ensuresAux(eq.asExpr(), b) and
293311
eq.eq(b, i, j)
294312
)
295313
}
296314

297-
/** Holds if this guard ensures that `i != j` holds. */
298-
predicate ensuresNeq(DataFlow::Node i, DataFlow::Node j) {
315+
/**
316+
* DEPRECATED: Use `guardEnsuresNeq` from `semmle.go.controlflow.Guards`
317+
* instead.
318+
*
319+
* Holds if this guard ensures that `i != j` holds.
320+
*/
321+
deprecated predicate ensuresNeq(DataFlow::Node i, DataFlow::Node j) {
299322
exists(DataFlow::EqualityTestNode eq, boolean b |
300-
this.ensures(eq, b.booleanNot()) and
323+
this.ensuresAux(eq.asExpr(), b.booleanNot()) and
301324
eq.eq(b, i, j)
302325
)
303326
}
304327

305328
/**
329+
* DEPRECATED: Use `Guard.controls` from `semmle.go.controlflow.Guards`
330+
* instead.
331+
*
306332
* Holds if this guard dominates basic block `bb`, that is, the guard
307333
* is known to hold at `bb`.
308334
*/
309-
predicate dominates(ReachableBasicBlock bb) {
335+
deprecated predicate dominates(ReachableBasicBlock bb) {
310336
this = bb.getANode() or
311337
this.dominates(bb.getImmediateDominator())
312338
}

0 commit comments

Comments
 (0)