@@ -10,7 +10,15 @@ private import semmle.code.java.Constants
1010private import semmle.code.java.dataflow.RangeAnalysis
1111private import codeql.rangeanalysis.internal.RangeUtils
1212
13- private predicate backEdge = MakeUtils< Sem , IntDelta > :: backEdge / 3 ;
13+ private module U = MakeUtils< Sem , IntDelta > ;
14+
15+ private predicate backEdge = U:: backEdge / 3 ;
16+
17+ predicate ssaRead = U:: ssaRead / 2 ;
18+
19+ predicate guardDirectlyControlsSsaRead = U:: guardDirectlyControlsSsaRead / 3 ;
20+
21+ predicate guardControlsSsaRead = U:: guardControlsSsaRead / 3 ;
1422
1523/**
1624 * Holds if `v` is an input to `phi` that is not along a back edge, and the
@@ -149,67 +157,6 @@ class ConstantStringExpr extends Expr {
149157 string getStringValue ( ) { constantStringExpr ( this , result ) }
150158}
151159
152- bindingset [ f]
153- private predicate okInt ( float f ) { - 2 .pow ( 31 ) <= f and f <= 2 .pow ( 31 ) - 1 }
154-
155- /**
156- * Gets an expression that equals `v - d`.
157- */
158- Expr ssaRead ( SsaVariable v , int delta ) {
159- result = v .getAUse ( ) and delta = 0
160- or
161- exists ( int d1 , ConstantIntegerExpr c |
162- result .( AddExpr ) .hasOperands ( ssaRead ( v , d1 ) , c ) and
163- delta = d1 - c .getIntValue ( ) and
164- okInt ( d1 .( float ) - c .getIntValue ( ) .( float ) )
165- )
166- or
167- exists ( SubExpr sub , int d1 , ConstantIntegerExpr c |
168- result = sub and
169- sub .getLeftOperand ( ) = ssaRead ( v , d1 ) and
170- sub .getRightOperand ( ) = c and
171- delta = d1 + c .getIntValue ( ) and
172- okInt ( d1 .( float ) + c .getIntValue ( ) .( float ) )
173- )
174- or
175- v .( SsaExplicitUpdate ) .getDefiningExpr ( ) .( PreIncExpr ) = result and delta = 0
176- or
177- v .( SsaExplicitUpdate ) .getDefiningExpr ( ) .( PreDecExpr ) = result and delta = 0
178- or
179- v .( SsaExplicitUpdate ) .getDefiningExpr ( ) .( PostIncExpr ) = result and delta = 1 // x++ === ++x - 1
180- or
181- v .( SsaExplicitUpdate ) .getDefiningExpr ( ) .( PostDecExpr ) = result and delta = - 1 // x-- === --x + 1
182- or
183- v .( SsaExplicitUpdate ) .getDefiningExpr ( ) .( Assignment ) = result and delta = 0
184- or
185- result .( AssignExpr ) .getSource ( ) = ssaRead ( v , delta )
186- }
187-
188- /**
189- * Holds if `guard` directly controls the position `controlled` with the
190- * value `testIsTrue`.
191- */
192- predicate guardDirectlyControlsSsaRead ( Guard guard , SsaReadPosition controlled , boolean testIsTrue ) {
193- guard .directlyControls ( controlled .( SsaReadPositionBlock ) .getBlock ( ) , testIsTrue )
194- or
195- exists ( SsaReadPositionPhiInputEdge controlledEdge | controlledEdge = controlled |
196- guard .directlyControls ( controlledEdge .getOrigBlock ( ) , testIsTrue ) or
197- guard .hasBranchEdge ( controlledEdge .getOrigBlock ( ) , controlledEdge .getPhiBlock ( ) , testIsTrue )
198- )
199- }
200-
201- /**
202- * Holds if `guard` controls the position `controlled` with the value `testIsTrue`.
203- */
204- predicate guardControlsSsaRead ( Guard guard , SsaReadPosition controlled , boolean testIsTrue ) {
205- guardDirectlyControlsSsaRead ( guard , controlled , testIsTrue )
206- or
207- exists ( Guard guard0 , boolean testIsTrue0 |
208- implies_v2 ( guard0 , testIsTrue0 , guard , testIsTrue ) and
209- guardControlsSsaRead ( guard0 , controlled , testIsTrue0 )
210- )
211- }
212-
213160/**
214161 * Gets a condition that tests whether `v` equals `e + delta`.
215162 *
0 commit comments