Shared: Use shared SuccessorType in shared Cfg and BasicBlock libs.

This commit is contained in:
Anders Schack-Mulligen
2025-08-28 11:03:45 +02:00
parent 4685b4f8a9
commit 144e34c669
22 changed files with 101 additions and 131 deletions

View File

@@ -2,6 +2,7 @@
* Provides classes that specify the conditions under which control flows along a given edge.
*/
private import codeql.controlflow.SuccessorType
private import internal.EdgeKindInternal
private newtype TEdgeKind =
@@ -28,6 +29,21 @@ abstract private class EdgeKindImpl extends TEdgeKind {
final class EdgeKind = EdgeKindImpl;
private SuccessorType getAMatchingSpecificSuccessorType(EdgeKind k) {
result.(BooleanSuccessor).getValue() = true and k instanceof TrueEdge
or
result.(BooleanSuccessor).getValue() = false and k instanceof FalseEdge
or
result instanceof ExceptionSuccessor and k instanceof ExceptionEdge
}
SuccessorType getAMatchingSuccessorType(EdgeKind k) {
result = getAMatchingSpecificSuccessorType(k)
or
not exists(getAMatchingSpecificSuccessorType(k)) and
result instanceof DirectSuccessor
}
/**
* A "goto" edge, representing the unconditional successor of an `Instruction`
* or `IRBlock`.

View File

@@ -265,9 +265,9 @@ private predicate isEntryBlock(TIRBlock block) {
}
module IRCfg implements BB::CfgSig<Language::Location> {
class ControlFlowNode = Instruction;
private import codeql.controlflow.SuccessorType
class SuccessorType = EdgeKind;
class ControlFlowNode = Instruction;
final private class FinalIRBlock = IRBlock;
@@ -280,7 +280,12 @@ module IRCfg implements BB::CfgSig<Language::Location> {
BasicBlock getASuccessor() { result = super.getASuccessor() }
BasicBlock getASuccessor(SuccessorType t) { result = super.getSuccessor(t) }
BasicBlock getASuccessor(SuccessorType t) {
exists(EdgeKind k |
result = super.getSuccessor(k) and
t = getAMatchingSuccessorType(k)
)
}
predicate strictlyDominates(BasicBlock bb) { super.strictlyDominates(bb) }

View File

@@ -265,9 +265,9 @@ private predicate isEntryBlock(TIRBlock block) {
}
module IRCfg implements BB::CfgSig<Language::Location> {
class ControlFlowNode = Instruction;
private import codeql.controlflow.SuccessorType
class SuccessorType = EdgeKind;
class ControlFlowNode = Instruction;
final private class FinalIRBlock = IRBlock;
@@ -280,7 +280,12 @@ module IRCfg implements BB::CfgSig<Language::Location> {
BasicBlock getASuccessor() { result = super.getASuccessor() }
BasicBlock getASuccessor(SuccessorType t) { result = super.getSuccessor(t) }
BasicBlock getASuccessor(SuccessorType t) {
exists(EdgeKind k |
result = super.getSuccessor(k) and
t = getAMatchingSuccessorType(k)
)
}
predicate strictlyDominates(BasicBlock bb) { super.strictlyDominates(bb) }

View File

@@ -265,9 +265,9 @@ private predicate isEntryBlock(TIRBlock block) {
}
module IRCfg implements BB::CfgSig<Language::Location> {
class ControlFlowNode = Instruction;
private import codeql.controlflow.SuccessorType
class SuccessorType = EdgeKind;
class ControlFlowNode = Instruction;
final private class FinalIRBlock = IRBlock;
@@ -280,7 +280,12 @@ module IRCfg implements BB::CfgSig<Language::Location> {
BasicBlock getASuccessor() { result = super.getASuccessor() }
BasicBlock getASuccessor(SuccessorType t) { result = super.getSuccessor(t) }
BasicBlock getASuccessor(SuccessorType t) {
exists(EdgeKind k |
result = super.getSuccessor(k) and
t = getAMatchingSuccessorType(k)
)
}
predicate strictlyDominates(BasicBlock bb) { super.strictlyDominates(bb) }