@@ -10,6 +10,7 @@ private import FlowSummaryImpl as FlowSummaryImpl
10
10
private import DataFlowImplCommon as DataFlowImplCommon
11
11
private import semmle.code.java.controlflow.Guards
12
12
private import semmle.code.java.dataflow.RangeUtils
13
+ private import SsaImpl as SsaImpl
13
14
14
15
/** Gets a string for approximating the name of a field. */
15
16
string approximateFieldContent ( FieldContent fc ) { result = fc .getField ( ) .getName ( ) .prefix ( 1 ) }
@@ -22,117 +23,24 @@ private predicate deadcode(Expr e) {
22
23
}
23
24
24
25
module SsaFlow {
25
- import codeql.ssa.Ssa
26
+ module Impl = SsaImpl :: DataFlowIntegration;
26
27
27
- private module SsaInput implements InputSig< Location > {
28
- private import semmle.code.java.controlflow.BasicBlocks as BB
29
- private import semmle.code.java.controlflow.Dominance as Dom
30
- private import semmle.code.java.ControlFlowGraph as Cfg
31
-
32
- class BasicBlock = BB:: BasicBlock ;
33
-
34
- class ControlFlowNode = Cfg:: ControlFlowNode ;
35
-
36
- BasicBlock getImmediateBasicBlockDominator ( BasicBlock bb ) { Dom:: bbIDominates ( result , bb ) }
37
-
38
- BasicBlock getABasicBlockSuccessor ( BasicBlock bb ) { result = bb .getABBSuccessor ( ) }
39
-
40
- class ExitBasicBlock extends BasicBlock {
41
- ExitBasicBlock ( ) { not exists ( this .getABBSuccessor ( ) ) }
42
- }
43
-
44
- class SourceVariable = LocalScopeVariable ;
45
-
46
- predicate variableWrite ( BasicBlock bb , int i , SourceVariable v , boolean certain ) {
47
- bb .getNode ( i ) =
48
- any ( VariableUpdate upd |
49
- v .getAnAccess ( ) = upd .( Assignment ) .getDest ( )
50
- or
51
- v = upd .( LocalVariableDeclExpr ) .getVariable ( )
52
- or
53
- v .getAnAccess ( ) = upd .( UnaryAssignExpr ) .getExpr ( )
54
- ) and
55
- certain = true
56
- or
57
- exists ( Callable c |
58
- bb = c .getBody ( ) and
59
- i = - 1 and
60
- v = c .getAParameter ( ) and
61
- certain = true
62
- )
63
- }
64
-
65
- predicate variableRead ( BasicBlock bb , int i , SourceVariable v , boolean certain ) {
66
- bb .getNode ( i ) .( VarRead ) .getVariable ( ) = v and certain = true
67
- }
68
- }
69
-
70
- module SsaImpl = Make< Location , SsaInput > ;
71
-
72
- module IntegrationInput implements SsaImpl:: DataFlowIntegrationInputSig {
73
- private import java as J
74
-
75
- class Expr instanceof J:: Expr {
76
- string toString ( ) { result = super .toString ( ) }
77
-
78
- Location getLocation ( ) { result = super .getLocation ( ) }
79
-
80
- predicate hasCfgNode ( BasicBlock bb , int i ) { this = bb .( J:: BasicBlock ) .getNode ( i ) }
81
- }
82
-
83
- class Parameter = J:: Parameter ;
84
-
85
- predicate ssaDefAssigns ( SsaImpl:: WriteDefinition def , Expr value ) {
86
- exists ( BasicBlock bb , int i , VariableUpdate upd |
87
- def .definesAt ( _, bb , i ) and
88
- bb .getNode ( i ) = upd
89
- |
90
- value = upd .( VariableAssign ) .getSource ( ) or
91
- value = upd .( AssignOp ) or
92
- value = upd .( RecordBindingVariableExpr )
93
- )
94
- }
95
-
96
- predicate ssaDefInitializesParam ( SsaImpl:: WriteDefinition def , Parameter p ) {
97
- def .definesAt ( p , _, - 1 )
98
- }
99
-
100
- private import semmle.code.java.controlflow.Guards as Guards
101
-
102
- class Guard extends Guards:: Guard {
103
- predicate hasCfgNode ( SsaInput:: BasicBlock bb , int i ) { this = bb .getNode ( i ) }
104
- }
105
-
106
- /** Holds if the guard `guard` controls block `bb` upon evaluating to `branch`. */
107
- predicate guardControlsBlock ( Guard guard , SsaInput:: BasicBlock bb , boolean branch ) {
108
- guard .controls ( bb , branch )
109
- }
110
-
111
- /** Gets an immediate conditional successor of basic block `bb`, if any. */
112
- SsaInput:: BasicBlock getAConditionalBasicBlockSuccessor ( SsaInput:: BasicBlock bb , boolean branch ) {
113
- result = bb .( Guards:: ConditionBlock ) .getTestSuccessor ( branch )
114
- }
115
- }
116
-
117
- module Integration = SsaImpl:: DataFlowIntegration< IntegrationInput > ;
118
-
119
- Integration:: Node asNode ( Node n ) {
28
+ Impl:: Node asNode ( Node n ) {
120
29
n = TSsaNode ( result )
121
30
or
122
- result .( Integration :: ExprNode ) .getExpr ( ) = n .asExpr ( )
31
+ result .( Impl :: ExprNode ) .getExpr ( ) = n .asExpr ( )
123
32
or
124
- result .( Integration:: ExprPostUpdateNode ) .getExpr ( ) =
125
- n .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( )
33
+ result .( Impl:: ExprPostUpdateNode ) .getExpr ( ) = n .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( )
126
34
or
127
- TExplicitParameterNode ( result .( Integration :: ParameterNode ) .getParameter ( ) ) = n
35
+ TExplicitParameterNode ( result .( Impl :: ParameterNode ) .getParameter ( ) ) = n
128
36
}
129
37
130
- predicate localFlowStep ( SsaImpl:: DefinitionExt def , Node nodeFrom , Node nodeTo ) {
131
- Integration :: localFlowStep ( def , asNode ( nodeFrom ) , asNode ( nodeTo ) )
38
+ predicate localFlowStep ( SsaImpl:: Impl :: DefinitionExt def , Node nodeFrom , Node nodeTo ) {
39
+ Impl :: localFlowStep ( def , asNode ( nodeFrom ) , asNode ( nodeTo ) )
132
40
}
133
41
134
- predicate localMustFlowStep ( SsaImpl:: DefinitionExt def , Node nodeFrom , Node nodeTo ) {
135
- Integration :: localMustFlowStep ( def , asNode ( nodeFrom ) , asNode ( nodeTo ) )
42
+ predicate localMustFlowStep ( SsaImpl:: Impl :: DefinitionExt def , Node nodeFrom , Node nodeTo ) {
43
+ Impl :: localMustFlowStep ( def , asNode ( nodeFrom ) , asNode ( nodeTo ) )
136
44
}
137
45
}
138
46
@@ -146,7 +54,7 @@ private module Cached {
146
54
not e .getType ( ) instanceof VoidType and
147
55
not e .getParent * ( ) instanceof Annotation
148
56
} or
149
- TSsaNode ( SsaFlow:: Integration :: SsaNode node ) or
57
+ TSsaNode ( SsaFlow:: Impl :: SsaNode node ) or
150
58
TExplicitParameterNode ( Parameter p ) { exists ( p .getCallable ( ) .getBody ( ) ) } or
151
59
TImplicitVarargsArray ( Call c ) {
152
60
c .getCallee ( ) .isVarargs ( ) and
@@ -317,11 +225,11 @@ module Public {
317
225
}
318
226
319
227
class SsaNode extends Node , TSsaNode {
320
- private SsaFlow:: Integration :: SsaNode node ;
228
+ private SsaFlow:: Impl :: SsaNode node ;
321
229
322
230
SsaNode ( ) { this = TSsaNode ( node ) }
323
231
324
- SsaFlow :: SsaImpl :: DefinitionExt getDefinitionExt ( ) { result = node .getDefinitionExt ( ) }
232
+ SsaImpl :: Impl :: DefinitionExt getDefinitionExt ( ) { result = node .getDefinitionExt ( ) }
325
233
326
234
override Location getLocation ( ) { result = node .getLocation ( ) }
327
235
0 commit comments