Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: deprecated
---
* `ControlFlow::ConditionGuardNode` is now deprecated and has no instances. Use the API from `semmle.go.controlflow.Guards` instead.
4 changes: 4 additions & 0 deletions go/ql/lib/change-notes/2026-08-17-shared-guards.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: feature
---
* The Go language library now instantiates the shared library `semmle.go.controlflow.Guards`, including the `Guard` and `GuardValue` classes and the `guardEnsures`, `guardEnsuresEq`, `guardEnsuresNeq`, and `guardEnsuresLeq` predicates.
56 changes: 42 additions & 14 deletions go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,12 @@ module ControlFlow {
}

/**
* DEPRECATED: Use `Guard` from `semmle.go.controlflow.Guards` instead.
*
* A control-flow node recording the fact that a certain expression has a known
* Boolean value at this point in the program.
*/
class ConditionGuardNode extends IR::Instruction {
deprecated class ConditionGuardNode extends IR::Instruction {
Expr cond;
boolean outcome;

Expand Down Expand Up @@ -292,43 +294,69 @@ module ControlFlow {
b = false
}

/** Holds if this guard ensures that the result of `nd` is `b`. */
predicate ensures(DataFlow::Node nd, boolean b) {
/**
* DEPRECATED: Use `Guard.controls` from `semmle.go.controlflow.Guards`
* instead.
*
* Holds if this guard ensures that the result of `nd` is `b`.
*/
deprecated predicate ensures(DataFlow::Node nd, boolean b) {
this.ensuresAux(any(Expr e | nd = DataFlow::exprNode(e)), b)
}

/** Holds if this guard ensures that `lesser <= greater + bias` holds. */
predicate ensuresLeq(DataFlow::Node lesser, DataFlow::Node greater, int bias) {
/**
* DEPRECATED: Use `guardEnsuresLeq` from `semmle.go.controlflow.Guards`
* instead.
*
* Holds if this guard ensures that `lesser <= greater + bias` holds.
*/
deprecated predicate ensuresLeq(DataFlow::Node lesser, DataFlow::Node greater, int bias) {
exists(DataFlow::RelationalComparisonNode rel, boolean b |
this.ensures(rel, b) and
this.ensuresAux(rel.asExpr(), b) and
rel.leq(b, lesser, greater, bias)
)
or
this.ensuresEq(lesser, greater) and
exists(DataFlow::EqualityTestNode eq, boolean b |
this.ensuresAux(eq.asExpr(), b) and
eq.eq(b, lesser, greater)
) and
bias = 0
}

/** Holds if this guard ensures that `i = j` holds. */
predicate ensuresEq(DataFlow::Node i, DataFlow::Node j) {
/**
* DEPRECATED: Use `guardEnsuresEq` from `semmle.go.controlflow.Guards`
* instead.
*
* Holds if this guard ensures that `i = j` holds.
*/
deprecated predicate ensuresEq(DataFlow::Node i, DataFlow::Node j) {
exists(DataFlow::EqualityTestNode eq, boolean b |
this.ensures(eq, b) and
this.ensuresAux(eq.asExpr(), b) and
eq.eq(b, i, j)
)
}

/** Holds if this guard ensures that `i != j` holds. */
predicate ensuresNeq(DataFlow::Node i, DataFlow::Node j) {
/**
* DEPRECATED: Use `guardEnsuresNeq` from `semmle.go.controlflow.Guards`
* instead.
*
* Holds if this guard ensures that `i != j` holds.
*/
deprecated predicate ensuresNeq(DataFlow::Node i, DataFlow::Node j) {
exists(DataFlow::EqualityTestNode eq, boolean b |
this.ensures(eq, b.booleanNot()) and
this.ensuresAux(eq.asExpr(), b.booleanNot()) and
eq.eq(b, i, j)
)
}

/**
* DEPRECATED: Use `Guard.controls` from `semmle.go.controlflow.Guards`
* instead.
*
* Holds if this guard dominates basic block `bb`, that is, the guard
* is known to hold at `bb`.
*/
predicate dominates(ReachableBasicBlock bb) {
deprecated predicate dominates(ReachableBasicBlock bb) {
this = bb.getANode() or
this.dominates(bb.getImmediateDominator())
}
Expand Down
Loading
Loading