From b2f878229d3b3d0995af249ac09287db0511d80c Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Wed, 28 Jan 2026 16:34:07 +0000 Subject: [PATCH] Use shared `getASuccessor` and `getAPredecessor` --- go/ql/lib/semmle/go/controlflow/BasicBlocks.qll | 8 +------- go/ql/lib/semmle/go/dataflow/SSA.qll | 2 +- go/ql/lib/semmle/go/dataflow/SsaImpl.qll | 6 +++--- go/ql/src/Security/CWE-020/IncompleteHostnameRegexp.ql | 2 +- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/go/ql/lib/semmle/go/controlflow/BasicBlocks.qll b/go/ql/lib/semmle/go/controlflow/BasicBlocks.qll index 232b6a5e00b..4352312e1b8 100644 --- a/go/ql/lib/semmle/go/controlflow/BasicBlocks.qll +++ b/go/ql/lib/semmle/go/controlflow/BasicBlocks.qll @@ -43,12 +43,6 @@ private module Input implements BB::InputSig { private module BbImpl = BB::Make; class BasicBlock extends BbImpl::BasicBlock { - /** Gets a basic block succeeding this one. */ - BasicBlock getASuccessor() { result = this.getASuccessor(_) } - - /** Gets a basic block preceding this one. */ - BasicBlock getAPredecessor() { result.getASuccessor() = this } - /** Gets the innermost function or file to which this basic block belongs. */ ControlFlow::Root getRoot() { result = this.getScope() } } @@ -59,7 +53,7 @@ cached private predicate reachableBB(BasicBlock bb) { bb instanceof EntryBasicBlock or - exists(BasicBlock predBB | predBB.getASuccessor() = bb | reachableBB(predBB)) + exists(BasicBlock predBB | predBB.getASuccessor(_) = bb | reachableBB(predBB)) } /** diff --git a/go/ql/lib/semmle/go/dataflow/SSA.qll b/go/ql/lib/semmle/go/dataflow/SSA.qll index 98dae5f3d01..2c36051e3a7 100644 --- a/go/ql/lib/semmle/go/dataflow/SSA.qll +++ b/go/ql/lib/semmle/go/dataflow/SSA.qll @@ -285,7 +285,7 @@ abstract class SsaPseudoDefinition extends SsaImplicitDefinition { */ class SsaPhiNode extends SsaPseudoDefinition, TPhi { override SsaVariable getAnInput() { - result = getDefReachingEndOf(this.getBasicBlock().getAPredecessor(), this.getSourceVariable()) + result = getDefReachingEndOf(this.getBasicBlock().getAPredecessor(_), this.getSourceVariable()) } override predicate definesAt(ReachableBasicBlock bb, int i, SsaSourceVariable v) { diff --git a/go/ql/lib/semmle/go/dataflow/SsaImpl.qll b/go/ql/lib/semmle/go/dataflow/SsaImpl.qll index 9689c998acf..a5db316b601 100644 --- a/go/ql/lib/semmle/go/dataflow/SsaImpl.qll +++ b/go/ql/lib/semmle/go/dataflow/SsaImpl.qll @@ -186,7 +186,7 @@ private module Internal { * Holds if `v` is live at the beginning of any successor of basic block `bb`. */ private predicate liveAtSuccEntry(ReachableBasicBlock bb, SsaSourceVariable v) { - liveAtEntry(bb.getASuccessor(), v) + liveAtEntry(bb.getASuccessor(_), v) } /** @@ -317,7 +317,7 @@ private module Internal { SsaSourceVariable v, ReachableBasicBlock b1, ReachableBasicBlock b2 ) { varOccursInBlock(v, b1) and - b2 = b1.getASuccessor() + b2 = b1.getASuccessor(_) } /** @@ -335,7 +335,7 @@ private module Internal { ) { varBlockReaches(v, b1, mid) and not varOccursInBlock(v, mid) and - b2 = mid.getASuccessor() + b2 = mid.getASuccessor(_) } /** diff --git a/go/ql/src/Security/CWE-020/IncompleteHostnameRegexp.ql b/go/ql/src/Security/CWE-020/IncompleteHostnameRegexp.ql index f6e3df7d1d9..a6321b7d7cb 100644 --- a/go/ql/src/Security/CWE-020/IncompleteHostnameRegexp.ql +++ b/go/ql/src/Security/CWE-020/IncompleteHostnameRegexp.ql @@ -45,7 +45,7 @@ predicate writesHttpError(ReachableBasicBlock b) { predicate onlyErrors(BasicBlock block) { writesHttpError(block) or - forex(ReachableBasicBlock pred | pred = block.getAPredecessor() | onlyErrors(pred)) + forex(ReachableBasicBlock pred | pred = block.getAPredecessor(_) | onlyErrors(pred)) } /** Gets a node that refers to a handler that is considered to return an HTTP error. */