Languages: Adapt to api changes.

This commit is contained in:
Anders Schack-Mulligen
2025-08-19 10:34:06 +02:00
parent e53b22dfa7
commit f459ddc40a
34 changed files with 454 additions and 368 deletions

View File

@@ -1,9 +1,11 @@
/** Provides classes representing basic blocks. */
private import swift
private import ControlFlowGraph
private import internal.ControlFlowGraphImpl as CfgImpl
private import SuccessorTypes
private import CfgImpl::BasicBlocks as BasicBlocksImpl
private import codeql.controlflow.BasicBlock as BB
/**
* A basic block, that is, a maximal straight-line sequence of control flow nodes
@@ -111,3 +113,23 @@ final class ConditionBlock extends BasicBlock, BasicBlocksImpl::ConditionBasicBl
super.edgeDominates(controlled, s)
}
}
private class BasicBlockAlias = BasicBlock;
private class ControlFlowNodeAlias = ControlFlowNode;
private class SuccessorTypeAlias = SuccessorType;
module Cfg implements BB::CfgSig<Location> {
class ControlFlowNode = ControlFlowNodeAlias;
class SuccessorType = SuccessorTypeAlias;
class BasicBlock = BasicBlockAlias;
predicate dominatingEdge(BasicBlock bb1, BasicBlock bb2) {
BasicBlocksImpl::dominatingEdge(bb1, bb2)
}
predicate entryBlock(BasicBlock bb) { bb instanceof EntryBasicBlock }
}

View File

@@ -6,15 +6,10 @@ module Ssa {
private import codeql.swift.controlflow.ControlFlowGraph
private import codeql.swift.controlflow.BasicBlocks as BasicBlocks
private module SsaInput implements SsaImplCommon::InputSig<Location> {
private module SsaInput implements SsaImplCommon::InputSig<Location, BasicBlocks::BasicBlock> {
private import internal.DataFlowPrivate
private import codeql.swift.controlflow.ControlFlowGraph as Cfg
private import codeql.swift.controlflow.CfgNodes
class BasicBlock = BasicBlocks::BasicBlock;
class ControlFlowNode = Cfg::ControlFlowNode;
private newtype TSourceVariable =
TNormalSourceVariable(VarDecl v) or
TKeyPathSourceVariable(EntryNode entry) { entry.getScope() instanceof KeyPathExpr }
@@ -55,7 +50,7 @@ module Ssa {
override EntryNode asKeyPath() { result = enter }
}
predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {
predicate variableWrite(BasicBlocks::BasicBlock bb, int i, SourceVariable v, boolean certain) {
exists(AssignExpr assign |
bb.getNode(i).getNode().asAstNode() = assign and
assign.getDest() = v.getAnAccess() and
@@ -93,7 +88,7 @@ module Ssa {
)
}
predicate variableRead(BasicBlock bb, int i, SourceVariable v, boolean certain) {
predicate variableRead(BasicBlocks::BasicBlock bb, int i, SourceVariable v, boolean certain) {
exists(DeclRefExpr ref |
not isLValue(ref) and
bb.getNode(i).getNode().asAstNode() = ref and
@@ -127,7 +122,7 @@ module Ssa {
/**
* INTERNAL: Do not use.
*/
module SsaImpl = SsaImplCommon::Make<Location, SsaInput>;
module SsaImpl = SsaImplCommon::Make<Location, BasicBlocks::Cfg, SsaInput>;
cached
class Definition extends SsaImpl::Definition {
@@ -136,7 +131,7 @@ module Ssa {
cached
ControlFlowNode getARead() {
exists(SsaInput::SourceVariable v, SsaInput::BasicBlock bb, int i |
exists(SsaInput::SourceVariable v, BasicBlocks::BasicBlock bb, int i |
SsaImpl::ssaDefReachesRead(v, this, bb, i) and
SsaInput::variableRead(bb, i, v, true) and
result = bb.getNode(i)
@@ -145,7 +140,7 @@ module Ssa {
cached
ControlFlowNode getAFirstRead() {
exists(SsaInput::BasicBlock bb, int i |
exists(BasicBlocks::BasicBlock bb, int i |
SsaImpl::firstUse(this, bb, i, true) and
result = bb.getNode(i)
)
@@ -154,7 +149,7 @@ module Ssa {
cached
predicate adjacentReadPair(ControlFlowNode read1, ControlFlowNode read2) {
read1 = this.getARead() and
exists(SsaInput::BasicBlock bb1, int i1, SsaInput::BasicBlock bb2, int i2 |
exists(BasicBlocks::BasicBlock bb1, int i1, BasicBlocks::BasicBlock bb2, int i2 |
read1 = bb1.getNode(i1) and
SsaImpl::adjacentUseUse(bb1, i1, bb2, i2, _, true) and
read2 = bb2.getNode(i2)
@@ -162,7 +157,7 @@ module Ssa {
}
cached
deprecated predicate lastRefRedef(SsaInput::BasicBlock bb, int i, Definition next) {
deprecated predicate lastRefRedef(BasicBlocks::BasicBlock bb, int i, Definition next) {
SsaImpl::lastRefRedef(this, bb, i, next)
}
}
@@ -171,7 +166,7 @@ module Ssa {
class WriteDefinition extends Definition, SsaImpl::WriteDefinition {
cached
override Location getLocation() {
exists(SsaInput::BasicBlock bb, int i |
exists(BasicBlocks::BasicBlock bb, int i |
this.definesAt(_, bb, i) and
result = bb.getNode(i).getLocation()
)
@@ -183,19 +178,19 @@ module Ssa {
*/
cached
predicate assigns(CfgNode value) {
exists(AssignExpr a, SsaInput::BasicBlock bb, int i |
exists(AssignExpr a, BasicBlocks::BasicBlock bb, int i |
this.definesAt(_, bb, i) and
a = bb.getNode(i).getNode().asAstNode() and
value.getNode().asAstNode() = a.getSource()
)
or
exists(SsaInput::BasicBlock bb, int blockIndex, NamedPattern np |
exists(BasicBlocks::BasicBlock bb, int blockIndex, NamedPattern np |
this.definesAt(_, bb, blockIndex) and
np = bb.getNode(blockIndex).getNode().asAstNode() and
value.getNode().asAstNode() = np
)
or
exists(SsaInput::BasicBlock bb, int blockIndex, ConditionElement ce, Expr init |
exists(BasicBlocks::BasicBlock bb, int blockIndex, ConditionElement ce, Expr init |
this.definesAt(_, bb, blockIndex) and
ce.getPattern() = bb.getNode(blockIndex).getNode().asAstNode() and
init = ce.getInitializer() and
@@ -210,14 +205,14 @@ module Ssa {
class PhiDefinition extends Definition, SsaImpl::PhiNode {
cached
override Location getLocation() {
exists(SsaInput::BasicBlock bb |
exists(BasicBlocks::BasicBlock bb |
this.definesAt(_, bb, _) and
result = bb.getLocation()
)
}
cached
Definition getPhiInput(SsaInput::BasicBlock bb) {
Definition getPhiInput(BasicBlocks::BasicBlock bb) {
SsaImpl::phiHasInputFromBlock(this, result, bb)
}

View File

@@ -882,30 +882,11 @@ private predicate closureFlowStep(CaptureInput::Expr e1, CaptureInput::Expr e2)
e2.(Pattern).getImmediateMatchingExpr() = e1
}
private module CaptureInput implements VariableCapture::InputSig<Location> {
private module CaptureInput implements VariableCapture::InputSig<Location, BasicBlock> {
private import swift as S
private import codeql.swift.controlflow.ControlFlowGraph as Cfg
private import codeql.swift.controlflow.BasicBlocks as B
class BasicBlock instanceof B::BasicBlock {
string toString() { result = super.toString() }
ControlFlowNode getNode(int i) { result = super.getNode(i) }
int length() { result = super.length() }
Callable getEnclosingCallable() { result = super.getScope() }
Location getLocation() { result = super.getLocation() }
BasicBlock getASuccessor() { result = super.getASuccessor() }
BasicBlock getImmediateDominator() { result = super.getImmediateDominator() }
predicate inDominanceFrontier(BasicBlock df) { super.inDominanceFrontier(df) }
}
class ControlFlowNode = Cfg::ControlFlowNode;
Callable basicBlockGetEnclosingCallable(BasicBlock bb) { result = bb.getScope() }
class CapturedVariable instanceof S::VarDecl {
CapturedVariable() {
@@ -927,9 +908,7 @@ private module CaptureInput implements VariableCapture::InputSig<Location> {
Location getLocation() { result = super.getLocation() }
predicate hasCfgNode(BasicBlock bb, int i) {
this = bb.(B::BasicBlock).getNode(i).getNode().asAstNode()
}
predicate hasCfgNode(BasicBlock bb, int i) { this = bb.getNode(i).getNode().asAstNode() }
}
class VariableWrite extends Expr {
@@ -1001,7 +980,7 @@ class CapturedVariable = CaptureInput::CapturedVariable;
class CapturedParameter = CaptureInput::CapturedParameter;
module CaptureFlow = VariableCapture::Flow<Location, CaptureInput>;
module CaptureFlow = VariableCapture::Flow<Location, Cfg, CaptureInput>;
private CaptureFlow::ClosureNode asClosureNode(Node n) {
result = n.(CaptureNode).getSynthesizedCaptureNode()