@@ -8,47 +8,14 @@ module;
88private import codeql.util.Boolean
99private import codeql.util.Unit
1010private import codeql.util.Location
11+ private import codeql.controlflow.BasicBlock as BB
1112private import codeql.ssa.Ssa as Ssa
1213
13- signature module InputSig< LocationSig Location> {
14- /**
15- * A basic block, that is, a maximal straight-line sequence of control flow nodes
16- * without branches or joins.
17- */
18- class BasicBlock {
19- /** Gets a textual representation of this basic block. */
20- string toString ( ) ;
21-
22- /** Gets the `i`th node in this basic block. */
23- ControlFlowNode getNode ( int i ) ;
14+ signature class BasicBlockSig ;
2415
25- /** Gets the length of this basic block. */
26- int length ( ) ;
27-
28- /** Gets the enclosing callable. */
29- Callable getEnclosingCallable ( ) ;
30-
31- /** Gets the location of this basic block. */
32- Location getLocation ( ) ;
33-
34- BasicBlock getASuccessor ( ) ;
35-
36- BasicBlock getImmediateDominator ( ) ;
37-
38- predicate inDominanceFrontier ( BasicBlock df ) ;
39- }
40-
41- /** A control flow node. */
42- class ControlFlowNode {
43- /** Gets a textual representation of this control flow node. */
44- string toString ( ) ;
45-
46- /** Gets the location of this control flow node. */
47- Location getLocation ( ) ;
48- }
49-
50- /** Holds if `bb` is a control-flow entry point. */
51- default predicate entryBlock ( BasicBlock bb ) { not exists ( bb .getImmediateDominator ( ) ) }
16+ signature module InputSig< LocationSig Location, BasicBlockSig BasicBlock> {
17+ /** Gets the enclosing callable of the basic block. */
18+ Callable basicBlockGetEnclosingCallable ( BasicBlock bb ) ;
5219
5320 /** A variable that is captured in a closure. */
5421 class CapturedVariable {
@@ -134,7 +101,9 @@ signature module InputSig<LocationSig Location> {
134101 }
135102}
136103
137- signature module OutputSig< LocationSig Location, InputSig< Location > I> {
104+ signature module OutputSig<
105+ LocationSig Location, BasicBlockSig BasicBlock, InputSig< Location , BasicBlock > I>
106+ {
138107 /**
139108 * A data flow node that we need to reference in the step relations for
140109 * captured variables.
@@ -236,9 +205,18 @@ signature module OutputSig<LocationSig Location, InputSig<Location> I> {
236205 * Constructs the type `ClosureNode` and associated step relations, which are
237206 * intended to be included in the data-flow node and step relations.
238207 */
239- module Flow< LocationSig Location, InputSig< Location > Input> implements OutputSig< Location , Input > {
208+ module Flow<
209+ LocationSig Location, BB:: CfgSig< Location > Cfg, InputSig< Location , Cfg:: BasicBlock > Input>
210+ implements OutputSig< Location , Cfg:: BasicBlock , Input >
211+ {
240212 private import Input
241213
214+ final private class CfgBb = Cfg:: BasicBlock ;
215+
216+ private class BasicBlock extends CfgBb {
217+ Callable getEnclosingCallable ( ) { result = basicBlockGetEnclosingCallable ( this ) }
218+ }
219+
242220 additional module ConsistencyChecks {
243221 final private class FinalExpr = Expr ;
244222
@@ -318,12 +296,12 @@ module Flow<LocationSig Location, InputSig<Location> Input> implements OutputSig
318296
319297 query predicate localDominator ( RelevantBasicBlock bb , string msg ) {
320298 msg = "BasicBlock has non-local dominator" and
321- bb .getEnclosingCallable ( ) != bb .getImmediateDominator ( ) .getEnclosingCallable ( )
299+ bb .getEnclosingCallable ( ) != bb .getImmediateDominator ( ) .( BasicBlock ) . getEnclosingCallable ( )
322300 }
323301
324302 query predicate localSuccessor ( RelevantBasicBlock bb , string msg ) {
325303 msg = "BasicBlock has non-local successor" and
326- bb .getEnclosingCallable ( ) != bb .getASuccessor ( ) .getEnclosingCallable ( )
304+ bb .getEnclosingCallable ( ) != bb .getASuccessor ( ) .( BasicBlock ) . getEnclosingCallable ( )
327305 }
328306
329307 query predicate uniqueDefiningScope ( CapturedVariable v , string msg ) {
@@ -650,7 +628,7 @@ module Flow<LocationSig Location, InputSig<Location> Input> implements OutputSig
650628 /** Holds if `cc` needs a definition at the entry of its callable scope. */
651629 private predicate entryDef ( CaptureContainer cc , BasicBlock bb , int i ) {
652630 exists ( Callable c |
653- entryBlock ( bb ) and
631+ Cfg :: entryBlock ( bb ) and
654632 pragma [ only_bind_out ] ( bb .getEnclosingCallable ( ) ) = c and
655633 i =
656634 min ( int j |
@@ -666,14 +644,10 @@ module Flow<LocationSig Location, InputSig<Location> Input> implements OutputSig
666644 )
667645 }
668646
669- private module CaptureSsaInput implements Ssa:: InputSig< Location > {
670- final class BasicBlock = Input:: BasicBlock ;
671-
672- final class ControlFlowNode = Input:: ControlFlowNode ;
673-
647+ private module CaptureSsaInput implements Ssa:: InputSig< Location , Cfg:: BasicBlock > {
674648 class SourceVariable = CaptureContainer ;
675649
676- predicate variableWrite ( BasicBlock bb , int i , SourceVariable cc , boolean certain ) {
650+ predicate variableWrite ( Cfg :: BasicBlock bb , int i , SourceVariable cc , boolean certain ) {
677651 Cached:: ref ( ) and
678652 (
679653 exists ( CapturedVariable v | cc = TVariable ( v ) and captureWrite ( v , bb , i , true , _) )
@@ -683,9 +657,9 @@ module Flow<LocationSig Location, InputSig<Location> Input> implements OutputSig
683657 certain = true
684658 }
685659
686- predicate variableRead ( BasicBlock bb , int i , SourceVariable cc , boolean certain ) {
660+ predicate variableRead ( Cfg :: BasicBlock bb , int i , SourceVariable cc , boolean certain ) {
687661 (
688- synthThisQualifier ( bb , i ) and cc = TThis ( bb .getEnclosingCallable ( ) )
662+ synthThisQualifier ( bb , i ) and cc = TThis ( bb .( BasicBlock ) . getEnclosingCallable ( ) )
689663 or
690664 exists ( CapturedVariable v | cc = TVariable ( v ) |
691665 captureRead ( v , bb , i , true , _) or synthRead ( v , bb , i , true , _)
@@ -695,26 +669,30 @@ module Flow<LocationSig Location, InputSig<Location> Input> implements OutputSig
695669 }
696670 }
697671
698- private module CaptureSsa = Ssa:: Make< Location , CaptureSsaInput > ;
672+ private module CaptureSsa = Ssa:: Make< Location , Cfg , CaptureSsaInput > ;
699673
700674 private module DataFlowIntegrationInput implements CaptureSsa:: DataFlowIntegrationInputSig {
701675 private import codeql.util.Void
702676
703- class Expr instanceof Input :: ControlFlowNode {
677+ class Expr instanceof Cfg :: ControlFlowNode {
704678 string toString ( ) { result = super .toString ( ) }
705679
706- predicate hasCfgNode ( BasicBlock bb , int i ) { bb .getNode ( i ) = this }
680+ predicate hasCfgNode ( Cfg :: BasicBlock bb , int i ) { bb .getNode ( i ) = this }
707681 }
708682
709683 class GuardValue = Void ;
710684
711685 class Guard extends Void {
712- predicate hasValueBranchEdge ( BasicBlock bb1 , BasicBlock bb2 , GuardValue val ) { none ( ) }
686+ predicate hasValueBranchEdge ( Cfg:: BasicBlock bb1 , Cfg:: BasicBlock bb2 , GuardValue val ) {
687+ none ( )
688+ }
713689
714- predicate valueControlsBranchEdge ( BasicBlock bb1 , BasicBlock bb2 , GuardValue val ) { none ( ) }
690+ predicate valueControlsBranchEdge ( Cfg:: BasicBlock bb1 , Cfg:: BasicBlock bb2 , GuardValue val ) {
691+ none ( )
692+ }
715693 }
716694
717- predicate guardDirectlyControlsBlock ( Guard guard , BasicBlock bb , GuardValue val ) { none ( ) }
695+ predicate guardDirectlyControlsBlock ( Guard guard , Cfg :: BasicBlock bb , GuardValue val ) { none ( ) }
718696
719697 predicate includeWriteDefsInFlowStep ( ) { none ( ) }
720698
0 commit comments