@@ -13,7 +13,7 @@ private import semmle.code.cpp.models.interfaces.DataFlow
13
13
private import semmle.code.cpp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
14
14
private import DataFlowPrivate
15
15
private import ModelUtil
16
- private import SsaInternals as Ssa
16
+ private import SsaImpl as SsaImpl
17
17
private import DataFlowImplCommon as DataFlowImplCommon
18
18
private import codeql.util.Unit
19
19
private import Node0ToString
@@ -39,38 +39,39 @@ private newtype TIRDataFlowNode =
39
39
TNode0 ( Node0Impl node ) { DataFlowImplCommon:: forceCachingInSameStage ( ) } or
40
40
TGlobalLikeVariableNode ( GlobalLikeVariable var , int indirectionIndex ) {
41
41
indirectionIndex =
42
- [ getMinIndirectionsForType ( var .getUnspecifiedType ( ) ) .. Ssa :: getMaxIndirectionsForType ( var .getUnspecifiedType ( ) ) ]
42
+ [ getMinIndirectionsForType ( var .getUnspecifiedType ( ) ) .. SsaImpl :: getMaxIndirectionsForType ( var .getUnspecifiedType ( ) ) ]
43
43
} or
44
44
TPostUpdateNodeImpl ( Operand operand , int indirectionIndex ) {
45
45
operand = any ( FieldAddress fa ) .getObjectAddressOperand ( ) and
46
- indirectionIndex = [ 0 .. Ssa:: countIndirectionsForCppType ( Ssa:: getLanguageType ( operand ) ) ]
46
+ indirectionIndex =
47
+ [ 0 .. SsaImpl:: countIndirectionsForCppType ( SsaImpl:: getLanguageType ( operand ) ) ]
47
48
or
48
- Ssa :: isModifiableByCall ( operand , indirectionIndex )
49
+ SsaImpl :: isModifiableByCall ( operand , indirectionIndex )
49
50
} or
50
- TSsaSynthNode ( Ssa :: SynthNode n ) or
51
+ TSsaSynthNode ( SsaImpl :: SynthNode n ) or
51
52
TSsaIteratorNode ( IteratorFlow:: IteratorFlowNode n ) or
52
53
TRawIndirectOperand0 ( Node0Impl node , int indirectionIndex ) {
53
- Ssa :: hasRawIndirectOperand ( node .asOperand ( ) , indirectionIndex )
54
+ SsaImpl :: hasRawIndirectOperand ( node .asOperand ( ) , indirectionIndex )
54
55
} or
55
56
TRawIndirectInstruction0 ( Node0Impl node , int indirectionIndex ) {
56
57
not exists ( node .asOperand ( ) ) and
57
- Ssa :: hasRawIndirectInstruction ( node .asInstruction ( ) , indirectionIndex )
58
+ SsaImpl :: hasRawIndirectInstruction ( node .asInstruction ( ) , indirectionIndex )
58
59
} or
59
60
TFinalParameterNode ( Parameter p , int indirectionIndex ) {
60
- exists ( Ssa :: FinalParameterUse use |
61
+ exists ( SsaImpl :: FinalParameterUse use |
61
62
use .getParameter ( ) = p and
62
63
use .getIndirectionIndex ( ) = indirectionIndex
63
64
)
64
65
} or
65
- TFinalGlobalValue ( Ssa :: GlobalUse globalUse ) or
66
- TInitialGlobalValue ( Ssa :: GlobalDef globalUse ) or
66
+ TFinalGlobalValue ( SsaImpl :: GlobalUse globalUse ) or
67
+ TInitialGlobalValue ( SsaImpl :: GlobalDef globalUse ) or
67
68
TBodyLessParameterNodeImpl ( Parameter p , int indirectionIndex ) {
68
69
// Rule out parameters of catch blocks.
69
70
not exists ( p .getCatchBlock ( ) ) and
70
71
// We subtract one because `getMaxIndirectionsForType` returns the maximum
71
72
// indirection for a glvalue of a given type, and this doesn't apply to
72
73
// parameters.
73
- indirectionIndex = [ 0 .. Ssa :: getMaxIndirectionsForType ( p .getUnspecifiedType ( ) ) - 1 ] and
74
+ indirectionIndex = [ 0 .. SsaImpl :: getMaxIndirectionsForType ( p .getUnspecifiedType ( ) ) - 1 ] and
74
75
not any ( InitializeParameterInstruction init ) .getParameter ( ) = p
75
76
} or
76
77
TFlowSummaryNode ( FlowSummaryImpl:: Private:: SummaryNode sn )
@@ -81,7 +82,7 @@ private newtype TIRDataFlowNode =
81
82
class FieldAddress extends Operand {
82
83
FieldAddressInstruction fai ;
83
84
84
- FieldAddress ( ) { fai = this .getDef ( ) and not Ssa :: ignoreOperand ( this ) }
85
+ FieldAddress ( ) { fai = this .getDef ( ) and not SsaImpl :: ignoreOperand ( this ) }
85
86
86
87
/** Gets the field associated with this instruction. */
87
88
Field getField ( ) { result = fai .getField ( ) }
@@ -126,7 +127,7 @@ predicate conversionFlow(
126
127
)
127
128
or
128
129
additional = true and
129
- Ssa :: isAdditionalConversionFlow ( opFrom , instrTo )
130
+ SsaImpl :: isAdditionalConversionFlow ( opFrom , instrTo )
130
131
)
131
132
or
132
133
isPointerArith = true and
@@ -183,7 +184,7 @@ class Node extends TIRDataFlowNode {
183
184
or
184
185
this .asOperand ( ) .getUse ( ) = block .getInstruction ( i )
185
186
or
186
- exists ( Ssa :: SynthNode ssaNode |
187
+ exists ( SsaImpl :: SynthNode ssaNode |
187
188
this .( SsaSynthNode ) .getSynthNode ( ) = ssaNode and
188
189
ssaNode .getBasicBlock ( ) = block and
189
190
ssaNode .getIndex ( ) = i
@@ -364,10 +365,10 @@ class Node extends TIRDataFlowNode {
364
365
* pointed to by `p`.
365
366
*/
366
367
Expr asDefinition ( boolean uncertain ) {
367
- exists ( StoreInstruction store , Ssa :: Definition def |
368
+ exists ( StoreInstruction store , SsaImpl :: Definition def |
368
369
store = this .asInstruction ( ) and
369
370
result = asDefinitionImpl ( store ) and
370
- Ssa :: defToNode ( this , def , _) and
371
+ SsaImpl :: defToNode ( this , def , _) and
371
372
if def .isCertain ( ) then uncertain = false else uncertain = true
372
373
)
373
374
}
@@ -627,7 +628,7 @@ class OperandNode extends Node, Node0 {
627
628
* For example, `stripPointers(int*&)` is `int*` and `stripPointers(int*)` is `int`.
628
629
*/
629
630
Type stripPointer ( Type t ) {
630
- result = any ( Ssa :: Indirection ind | ind .getType ( ) = t ) .getBaseType ( )
631
+ result = any ( SsaImpl :: Indirection ind | ind .getType ( ) = t ) .getBaseType ( )
631
632
or
632
633
result = t .( PointerToMemberType ) .getBaseType ( )
633
634
or
@@ -694,12 +695,12 @@ class PostFieldUpdateNode extends PostUpdateNodeImpl {
694
695
* in a data flow graph.
695
696
*/
696
697
class SsaSynthNode extends Node , TSsaSynthNode {
697
- Ssa :: SynthNode node ;
698
+ SsaImpl :: SynthNode node ;
698
699
699
700
SsaSynthNode ( ) { this = TSsaSynthNode ( node ) }
700
701
701
702
/** Gets the synthesized SSA node associated with this node. */
702
- Ssa :: SynthNode getSynthNode ( ) { result = node }
703
+ SsaImpl :: SynthNode getSynthNode ( ) { result = node }
703
704
704
705
override DataFlowCallable getEnclosingCallable ( ) {
705
706
result .asSourceCallable ( ) = this .getFunction ( )
@@ -782,12 +783,12 @@ class SideEffectOperandNode extends Node instanceof IndirectOperand {
782
783
* from a function body.
783
784
*/
784
785
class FinalGlobalValue extends Node , TFinalGlobalValue {
785
- Ssa :: GlobalUse globalUse ;
786
+ SsaImpl :: GlobalUse globalUse ;
786
787
787
788
FinalGlobalValue ( ) { this = TFinalGlobalValue ( globalUse ) }
788
789
789
790
/** Gets the underlying SSA use. */
790
- Ssa :: GlobalUse getGlobalUse ( ) { result = globalUse }
791
+ SsaImpl :: GlobalUse getGlobalUse ( ) { result = globalUse }
791
792
792
793
override DataFlowCallable getEnclosingCallable ( ) {
793
794
result .asSourceCallable ( ) = this .getFunction ( )
@@ -814,12 +815,12 @@ class FinalGlobalValue extends Node, TFinalGlobalValue {
814
815
* a function body.
815
816
*/
816
817
class InitialGlobalValue extends Node , TInitialGlobalValue {
817
- Ssa :: GlobalDef globalDef ;
818
+ SsaImpl :: GlobalDef globalDef ;
818
819
819
820
InitialGlobalValue ( ) { this = TInitialGlobalValue ( globalDef ) }
820
821
821
822
/** Gets the underlying SSA definition. */
822
- Ssa :: GlobalDef getGlobalDef ( ) { result = globalDef }
823
+ SsaImpl :: GlobalDef getGlobalDef ( ) { result = globalDef }
823
824
824
825
override DataFlowCallable getEnclosingCallable ( ) {
825
826
result .asSourceCallable ( ) = this .getFunction ( )
@@ -1288,11 +1289,11 @@ class UninitializedNode extends Node {
1288
1289
LocalVariable v ;
1289
1290
1290
1291
UninitializedNode ( ) {
1291
- exists ( Ssa :: Definition def , Ssa :: SourceVariable sv |
1292
+ exists ( SsaImpl :: Definition def , SsaImpl :: SourceVariable sv |
1292
1293
def .getIndirectionIndex ( ) = 0 and
1293
1294
def .getValue ( ) .asInstruction ( ) instanceof UninitializedInstruction and
1294
- Ssa :: defToNode ( this , def , sv ) and
1295
- v = sv .getBaseVariable ( ) .( Ssa :: BaseIRVariable ) .getIRVariable ( ) .getAst ( )
1295
+ SsaImpl :: defToNode ( this , def , sv ) and
1296
+ v = sv .getBaseVariable ( ) .( SsaImpl :: BaseIRVariable ) .getIRVariable ( ) .getAst ( )
1296
1297
)
1297
1298
}
1298
1299
@@ -1722,7 +1723,7 @@ private module Cached {
1722
1723
cached
1723
1724
predicate flowsToBackEdge ( Node n ) {
1724
1725
exists ( Node succ , IRBlock bb1 , IRBlock bb2 |
1725
- Ssa :: ssaFlow ( n , succ ) and
1726
+ SsaImpl :: ssaFlow ( n , succ ) and
1726
1727
bb1 = n .getBasicBlock ( ) and
1727
1728
bb2 = succ .getBasicBlock ( ) and
1728
1729
bb1 != bb2 and
@@ -1820,7 +1821,7 @@ private module Cached {
1820
1821
predicate simpleLocalFlowStep ( Node nodeFrom , Node nodeTo , string model ) {
1821
1822
(
1822
1823
// Def-use/Use-use flow
1823
- Ssa :: ssaFlow ( nodeFrom , nodeTo )
1824
+ SsaImpl :: ssaFlow ( nodeFrom , nodeTo )
1824
1825
or
1825
1826
IteratorFlow:: localFlowStep ( nodeFrom , nodeTo )
1826
1827
or
@@ -1833,7 +1834,7 @@ private module Cached {
1833
1834
|
1834
1835
simpleOperandLocalFlowStep ( iFrom , opTo ) and
1835
1836
// Omit when the instruction node also represents the operand.
1836
- not iFrom = Ssa :: getIRRepresentationOfOperand ( opTo )
1837
+ not iFrom = SsaImpl :: getIRRepresentationOfOperand ( opTo )
1837
1838
)
1838
1839
or
1839
1840
// Indirect operand -> (indirect) instruction flow
@@ -1906,7 +1907,7 @@ private module Cached {
1906
1907
// We also want a write coming out of an `OutNode` to flow `nodeTo`.
1907
1908
// This is different from `reverseFlowInstruction` since `nodeFrom` can never
1908
1909
// be an `OutNode` when it's defined by an instruction.
1909
- Ssa :: outNodeHasAddressAndIndex ( nodeFrom , address , indirectionIndex )
1910
+ SsaImpl :: outNodeHasAddressAndIndex ( nodeFrom , address , indirectionIndex )
1910
1911
)
1911
1912
}
1912
1913
@@ -2099,7 +2100,7 @@ private newtype TContent =
2099
2100
TFieldContent ( Field f , int indirectionIndex ) {
2100
2101
// the indirection index for field content starts at 1 (because `TFieldContent` is thought of as
2101
2102
// the address of the field, `FieldAddress` in the IR).
2102
- indirectionIndex = [ 1 .. Ssa :: getMaxIndirectionsForType ( f .getUnspecifiedType ( ) ) ] and
2103
+ indirectionIndex = [ 1 .. SsaImpl :: getMaxIndirectionsForType ( f .getUnspecifiedType ( ) ) ] and
2103
2104
// Reads and writes of union fields are tracked using `UnionContent`.
2104
2105
not f .getDeclaringType ( ) instanceof Union
2105
2106
} or
@@ -2111,7 +2112,9 @@ private newtype TContent =
2111
2112
// field can be read by any read of the union's fields. Again, the indirection index
2112
2113
// is 1-based (because 0 is considered the address).
2113
2114
indirectionIndex =
2114
- [ 1 .. max ( Ssa:: getMaxIndirectionsForType ( getAFieldWithSize ( u , bytes ) .getUnspecifiedType ( ) ) ) ]
2115
+ [ 1 .. max ( SsaImpl:: getMaxIndirectionsForType ( getAFieldWithSize ( u , bytes )
2116
+ .getUnspecifiedType ( ) )
2117
+ ) ]
2115
2118
)
2116
2119
} or
2117
2120
TElementContent ( int indirectionIndex ) {
@@ -2354,7 +2357,7 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
2354
2357
controls ( g , result , edge )
2355
2358
)
2356
2359
or
2357
- result = Ssa :: BarrierGuard< guardChecksNode / 3 > :: getABarrierNode ( )
2360
+ result = SsaImpl :: BarrierGuard< guardChecksNode / 3 > :: getABarrierNode ( )
2358
2361
}
2359
2362
2360
2363
/**
@@ -2453,7 +2456,7 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
2453
2456
)
2454
2457
or
2455
2458
result =
2456
- Ssa :: BarrierGuardWithIntParam< guardChecksIndirectNode / 4 > :: getABarrierNode ( indirectionIndex )
2459
+ SsaImpl :: BarrierGuardWithIntParam< guardChecksIndirectNode / 4 > :: getABarrierNode ( indirectionIndex )
2457
2460
}
2458
2461
}
2459
2462
@@ -2490,7 +2493,7 @@ module InstructionBarrierGuard<instructionGuardChecksSig/3 instructionGuardCheck
2490
2493
controls ( g , result , edge )
2491
2494
)
2492
2495
or
2493
- result = Ssa :: BarrierGuard< guardChecksNode / 3 > :: getABarrierNode ( )
2496
+ result = SsaImpl :: BarrierGuard< guardChecksNode / 3 > :: getABarrierNode ( )
2494
2497
}
2495
2498
2496
2499
bindingset [ value, n]
@@ -2520,7 +2523,7 @@ module InstructionBarrierGuard<instructionGuardChecksSig/3 instructionGuardCheck
2520
2523
)
2521
2524
or
2522
2525
result =
2523
- Ssa :: BarrierGuardWithIntParam< guardChecksIndirectNode / 4 > :: getABarrierNode ( indirectionIndex )
2526
+ SsaImpl :: BarrierGuardWithIntParam< guardChecksIndirectNode / 4 > :: getABarrierNode ( indirectionIndex )
2524
2527
}
2525
2528
}
2526
2529
@@ -2576,3 +2579,16 @@ Function getARuntimeTarget(Call call) {
2576
2579
result = DataFlowImplCommon:: viableCallableLambda ( dfCall , _) .asSourceCallable ( )
2577
2580
)
2578
2581
}
2582
+
2583
+ /** A module that provides static single assignment (SSA) information. */
2584
+ module Ssa {
2585
+ class Definition = SsaImpl:: Definition ;
2586
+
2587
+ class ExplicitDefinition = SsaImpl:: ExplicitDefinition ;
2588
+
2589
+ class DirectExplicitDefinition = SsaImpl:: DirectExplicitDefinition ;
2590
+
2591
+ class IndirectExplicitDefinition = SsaImpl:: IndirectExplicitDefinition ;
2592
+
2593
+ class PhiNode = SsaImpl:: PhiNode ;
2594
+ }
0 commit comments