Skip to content

Commit 57db4c8

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 bd2947e commit 57db4c8

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
@@ -297,43 +297,69 @@ module ControlFlow {
297297
b = false
298298
}
299299

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

305-
/** Holds if this guard ensures that `lesser <= greater + bias` holds. */
306-
predicate ensuresLeq(DataFlow::Node lesser, DataFlow::Node greater, int bias) {
310+
/**
311+
* DEPRECATED: Use `guardEnsuresLeq` from `semmle.go.controlflow.Guards`
312+
* instead.
313+
*
314+
* Holds if this guard ensures that `lesser <= greater + bias` holds.
315+
*/
316+
deprecated predicate ensuresLeq(DataFlow::Node lesser, DataFlow::Node greater, int bias) {
307317
exists(DataFlow::RelationalComparisonNode rel, boolean b |
308-
this.ensures(rel, b) and
318+
this.ensuresAux(rel.asExpr(), b) and
309319
rel.leq(b, lesser, greater, bias)
310320
)
311321
or
312-
this.ensuresEq(lesser, greater) and
322+
exists(DataFlow::EqualityTestNode eq, boolean b |
323+
this.ensuresAux(eq.asExpr(), b) and
324+
eq.eq(b, lesser, greater)
325+
) and
313326
bias = 0
314327
}
315328

316-
/** Holds if this guard ensures that `i = j` holds. */
317-
predicate ensuresEq(DataFlow::Node i, DataFlow::Node j) {
329+
/**
330+
* DEPRECATED: Use `guardEnsuresEq` from `semmle.go.controlflow.Guards`
331+
* instead.
332+
*
333+
* Holds if this guard ensures that `i = j` holds.
334+
*/
335+
deprecated predicate ensuresEq(DataFlow::Node i, DataFlow::Node j) {
318336
exists(DataFlow::EqualityTestNode eq, boolean b |
319-
this.ensures(eq, b) and
337+
this.ensuresAux(eq.asExpr(), b) and
320338
eq.eq(b, i, j)
321339
)
322340
}
323341

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

332355
/**
356+
* DEPRECATED: Use `Guard.controls` from `semmle.go.controlflow.Guards`
357+
* instead.
358+
*
333359
* Holds if this guard dominates basic block `bb`, that is, the guard
334360
* is known to hold at `bb`.
335361
*/
336-
predicate dominates(ReachableBasicBlock bb) {
362+
deprecated predicate dominates(ReachableBasicBlock bb) {
337363
this = bb.getANode() or
338364
this.dominates(bb.getImmediateDominator())
339365
}

0 commit comments

Comments
 (0)