@@ -11,7 +11,9 @@ private import internal.rangeanalysis.SsaReadPositionCommon
11
11
/**
12
12
* Holds if `e + delta` equals `v` at `pos`.
13
13
*/
14
- private predicate valueFlowStepSsa ( SsaVariable v , SsaReadPosition pos , Expr e , int delta ) {
14
+ private predicate valueFlowStepSsa (
15
+ SsaVariable v , SsaReadPosition pos , Expr e , QlBuiltins:: BigInt delta
16
+ ) {
15
17
ssaUpdateStep ( v , e , delta ) and pos .hasReadOfVar ( v )
16
18
or
17
19
exists ( Guard guard , boolean testIsTrue |
@@ -47,17 +49,17 @@ private predicate nonConstSubtraction(Expr sub, Expr larg, Expr rarg) {
47
49
}
48
50
49
51
/** Gets an expression that is the remainder modulo `mod` of `arg`. */
50
- private Expr modExpr ( Expr arg , int mod ) {
52
+ private Expr modExpr ( Expr arg , QlBuiltins :: BigInt mod ) {
51
53
exists ( RemExpr rem |
52
54
result = rem and
53
55
arg = rem .getLeftOperand ( ) and
54
56
rem .getRightOperand ( ) .( ConstantIntegerExpr ) .getIntValue ( ) = mod and
55
- mod >= 2
57
+ mod >= 2 . toBigInt ( )
56
58
)
57
59
or
58
60
exists ( ConstantIntegerExpr c |
59
- mod = 2 .pow ( [ 1 .. 30 ] ) and
60
- c .getIntValue ( ) = mod - 1 and
61
+ mod = 2 .toBigInt ( ) . pow ( [ 1 .. 30 ] ) and
62
+ c .getIntValue ( ) = mod - 1 . toBigInt ( ) and
61
63
result .( BitwiseAndExpr ) .hasOperands ( arg , c )
62
64
)
63
65
}
@@ -66,26 +68,30 @@ private Expr modExpr(Expr arg, int mod) {
66
68
* Gets a guard that tests whether `v` is congruent with `val` modulo `mod` on
67
69
* its `testIsTrue` branch.
68
70
*/
69
- private Guard moduloCheck ( SsaVariable v , int val , int mod , boolean testIsTrue ) {
70
- exists ( Expr rem , ConstantIntegerExpr c , int r , boolean polarity |
71
+ private Guard moduloCheck (
72
+ SsaVariable v , QlBuiltins:: BigInt val , QlBuiltins:: BigInt mod , boolean testIsTrue
73
+ ) {
74
+ exists ( Expr rem , ConstantIntegerExpr c , QlBuiltins:: BigInt r , boolean polarity |
71
75
result .isEquality ( rem , c , polarity ) and
72
76
c .getIntValue ( ) = r and
73
77
rem = modExpr ( v .getAUse ( ) , mod ) and
74
78
(
75
79
testIsTrue = polarity and val = r
76
80
or
77
81
testIsTrue = polarity .booleanNot ( ) and
78
- mod = 2 and
79
- val = 1 - r and
80
- ( r = 0 or r = 1 )
82
+ mod = 2 . toBigInt ( ) and
83
+ val = 1 . toBigInt ( ) - r and
84
+ ( r = 0 . toBigInt ( ) or r = 1 . toBigInt ( ) )
81
85
)
82
86
)
83
87
}
84
88
85
89
/**
86
90
* Holds if a guard ensures that `v` at `pos` is congruent with `val` modulo `mod`.
87
91
*/
88
- private predicate moduloGuardedRead ( SsaVariable v , SsaReadPosition pos , int val , int mod ) {
92
+ private predicate moduloGuardedRead (
93
+ SsaVariable v , SsaReadPosition pos , QlBuiltins:: BigInt val , QlBuiltins:: BigInt mod
94
+ ) {
89
95
exists ( Guard guard , boolean testIsTrue |
90
96
pos .hasReadOfVar ( v ) and
91
97
guard = moduloCheck ( v , val , mod , testIsTrue ) and
@@ -101,13 +107,14 @@ private predicate andmaskFactor(int mask, int factor) {
101
107
}
102
108
103
109
/** Holds if `e` is evenly divisible by `factor`. */
104
- private predicate evenlyDivisibleExpr ( Expr e , int factor ) {
105
- exists ( ConstantIntegerExpr c , int k | k = c .getIntValue ( ) |
106
- e .( MulExpr ) .getAnOperand ( ) = c and factor = k .abs ( ) and factor >= 2
110
+ private predicate evenlyDivisibleExpr ( Expr e , QlBuiltins :: BigInt factor ) {
111
+ exists ( ConstantIntegerExpr c , QlBuiltins :: BigInt k | k = c .getIntValue ( ) |
112
+ e .( MulExpr ) .getAnOperand ( ) = c and factor = k .abs ( ) and factor >= 2 . toBigInt ( )
107
113
or
108
- e .( LeftShiftExpr ) .getRhs ( ) = c and factor = 2 .pow ( k ) and k > 0
114
+ e .( LeftShiftExpr ) .getRhs ( ) = c and factor = 2 .toBigInt ( ) . pow ( k . toInt ( ) ) and k > 0 . toBigInt ( )
109
115
or
110
- e .( BitwiseAndExpr ) .getAnOperand ( ) = c and factor = max ( int f | andmaskFactor ( k , f ) )
116
+ e .( BitwiseAndExpr ) .getAnOperand ( ) = c and
117
+ factor = max ( int f | andmaskFactor ( k .toInt ( ) , f ) ) .toBigInt ( )
111
118
)
112
119
}
113
120
@@ -118,31 +125,33 @@ private predicate evenlyDivisibleExpr(Expr e, int factor) {
118
125
* the range `[0 .. mod-1]`.
119
126
*/
120
127
bindingset [ val, mod]
121
- private int remainder ( int val , int mod ) {
122
- mod = 0 and result = val
128
+ private QlBuiltins :: BigInt remainder ( QlBuiltins :: BigInt val , QlBuiltins :: BigInt mod ) {
129
+ mod = 0 . toBigInt ( ) and result = val
123
130
or
124
- mod > 1 and result = ( ( val % mod ) + mod ) % mod
131
+ mod > 1 . toBigInt ( ) and result = ( ( val % mod ) + mod ) % mod
125
132
}
126
133
127
134
/**
128
135
* Holds if `inp` is an input to `phi` and equals `phi` modulo `mod` along `edge`.
129
136
*/
130
137
private predicate phiSelfModulus (
131
- SsaPhiNode phi , SsaVariable inp , SsaReadPositionPhiInputEdge edge , int mod
138
+ SsaPhiNode phi , SsaVariable inp , SsaReadPositionPhiInputEdge edge , QlBuiltins :: BigInt mod
132
139
) {
133
- exists ( SsaBound phibound , int v , int m |
140
+ exists ( SsaBound phibound , QlBuiltins :: BigInt v , QlBuiltins :: BigInt m |
134
141
edge .phiInput ( phi , inp ) and
135
142
phibound .getSsa ( ) = phi and
136
143
ssaModulus ( inp , edge , phibound , v , m ) and
137
144
mod = m .gcd ( v ) and
138
- mod != 1
145
+ mod != 1 . toBigInt ( )
139
146
)
140
147
}
141
148
142
149
/**
143
150
* Holds if `b + val` modulo `mod` is a candidate congruence class for `phi`.
144
151
*/
145
- private predicate phiModulusInit ( SsaPhiNode phi , Bound b , int val , int mod ) {
152
+ private predicate phiModulusInit (
153
+ SsaPhiNode phi , Bound b , QlBuiltins:: BigInt val , QlBuiltins:: BigInt mod
154
+ ) {
146
155
exists ( SsaVariable inp , SsaReadPositionPhiInputEdge edge |
147
156
edge .phiInput ( phi , inp ) and
148
157
ssaModulus ( inp , edge , b , val , mod )
@@ -152,22 +161,26 @@ private predicate phiModulusInit(SsaPhiNode phi, Bound b, int val, int mod) {
152
161
/**
153
162
* Holds if all inputs to `phi` numbered `1` to `rix` are equal to `b + val` modulo `mod`.
154
163
*/
155
- private predicate phiModulusRankStep ( SsaPhiNode phi , Bound b , int val , int mod , int rix ) {
164
+ private predicate phiModulusRankStep (
165
+ SsaPhiNode phi , Bound b , QlBuiltins:: BigInt val , QlBuiltins:: BigInt mod , int rix
166
+ ) {
156
167
rix = 0 and
157
168
phiModulusInit ( phi , b , val , mod )
158
169
or
159
- exists ( SsaVariable inp , SsaReadPositionPhiInputEdge edge , int v1 , int m1 |
160
- mod != 1 and
170
+ exists (
171
+ SsaVariable inp , SsaReadPositionPhiInputEdge edge , QlBuiltins:: BigInt v1 , QlBuiltins:: BigInt m1
172
+ |
173
+ mod != 1 .toBigInt ( ) and
161
174
val = remainder ( v1 , mod )
162
175
|
163
- exists ( int v2 , int m2 |
176
+ exists ( QlBuiltins :: BigInt v2 , QlBuiltins :: BigInt m2 |
164
177
rankedPhiInput ( phi , inp , edge , rix ) and
165
178
phiModulusRankStep ( phi , b , v1 , m1 , rix - 1 ) and
166
179
ssaModulus ( inp , edge , b , v2 , m2 ) and
167
180
mod = m1 .gcd ( m2 ) .gcd ( v1 - v2 )
168
181
)
169
182
or
170
- exists ( int m2 |
183
+ exists ( QlBuiltins :: BigInt m2 |
171
184
rankedPhiInput ( phi , inp , edge , rix ) and
172
185
phiModulusRankStep ( phi , b , v1 , m1 , rix - 1 ) and
173
186
phiSelfModulus ( phi , inp , edge , m2 ) and
@@ -179,7 +192,7 @@ private predicate phiModulusRankStep(SsaPhiNode phi, Bound b, int val, int mod,
179
192
/**
180
193
* Holds if `phi` is equal to `b + val` modulo `mod`.
181
194
*/
182
- private predicate phiModulus ( SsaPhiNode phi , Bound b , int val , int mod ) {
195
+ private predicate phiModulus ( SsaPhiNode phi , Bound b , QlBuiltins :: BigInt val , QlBuiltins :: BigInt mod ) {
183
196
exists ( int r |
184
197
maxPhiInputRank ( phi , r ) and
185
198
phiModulusRankStep ( phi , b , val , mod , r )
@@ -189,12 +202,14 @@ private predicate phiModulus(SsaPhiNode phi, Bound b, int val, int mod) {
189
202
/**
190
203
* Holds if `v` at `pos` is equal to `b + val` modulo `mod`.
191
204
*/
192
- private predicate ssaModulus ( SsaVariable v , SsaReadPosition pos , Bound b , int val , int mod ) {
205
+ private predicate ssaModulus (
206
+ SsaVariable v , SsaReadPosition pos , Bound b , QlBuiltins:: BigInt val , QlBuiltins:: BigInt mod
207
+ ) {
193
208
phiModulus ( v , b , val , mod ) and pos .hasReadOfVar ( v )
194
209
or
195
- b .( SsaBound ) .getSsa ( ) = v and pos .hasReadOfVar ( v ) and val = 0 and mod = 0
210
+ b .( SsaBound ) .getSsa ( ) = v and pos .hasReadOfVar ( v ) and val = 0 . toBigInt ( ) and mod = 0 . toBigInt ( )
196
211
or
197
- exists ( Expr e , int val0 , int delta |
212
+ exists ( Expr e , QlBuiltins :: BigInt val0 , QlBuiltins :: BigInt delta |
198
213
exprModulus ( e , b , val0 , mod ) and
199
214
valueFlowStepSsa ( v , pos , e , delta ) and
200
215
val = remainder ( val0 + delta , mod )
@@ -211,68 +226,80 @@ private predicate ssaModulus(SsaVariable v, SsaReadPosition pos, Bound b, int va
211
226
* - `mod > 1`: `val` lies within the range `[0 .. mod-1]`.
212
227
*/
213
228
cached
214
- predicate exprModulus ( Expr e , Bound b , int val , int mod ) {
215
- e = b .getExpr ( val ) and mod = 0
229
+ predicate exprModulus ( Expr e , Bound b , QlBuiltins :: BigInt val , QlBuiltins :: BigInt mod ) {
230
+ e = b .getExpr ( val ) and mod = 0 . toBigInt ( )
216
231
or
217
- evenlyDivisibleExpr ( e , mod ) and val = 0 and b instanceof ZeroBound
232
+ evenlyDivisibleExpr ( e , mod ) and val = 0 . toBigInt ( ) and b instanceof ZeroBound
218
233
or
219
234
exists ( SsaVariable v , SsaReadPositionBlock bb |
220
235
ssaModulus ( v , bb , b , val , mod ) and
221
236
e = v .getAUse ( ) and
222
237
getABasicBlockExpr ( bb .getBlock ( ) ) = e
223
238
)
224
239
or
225
- exists ( Expr mid , int val0 , int delta |
240
+ exists ( Expr mid , QlBuiltins :: BigInt val0 , QlBuiltins :: BigInt delta |
226
241
exprModulus ( mid , b , val0 , mod ) and
227
242
valueFlowStep ( e , mid , delta ) and
228
243
val = remainder ( val0 + delta , mod )
229
244
)
230
245
or
231
- exists ( ConditionalExpr cond , int v1 , int v2 , int m1 , int m2 |
246
+ exists (
247
+ ConditionalExpr cond , QlBuiltins:: BigInt v1 , QlBuiltins:: BigInt v2 , QlBuiltins:: BigInt m1 ,
248
+ QlBuiltins:: BigInt m2
249
+ |
232
250
cond = e and
233
251
condExprBranchModulus ( cond , true , b , v1 , m1 ) and
234
252
condExprBranchModulus ( cond , false , b , v2 , m2 ) and
235
253
mod = m1 .gcd ( m2 ) .gcd ( v1 - v2 ) and
236
- mod != 1 and
254
+ mod != 1 . toBigInt ( ) and
237
255
val = remainder ( v1 , mod )
238
256
)
239
257
or
240
- exists ( Bound b1 , Bound b2 , int v1 , int v2 , int m1 , int m2 |
258
+ exists (
259
+ Bound b1 , Bound b2 , QlBuiltins:: BigInt v1 , QlBuiltins:: BigInt v2 , QlBuiltins:: BigInt m1 ,
260
+ QlBuiltins:: BigInt m2
261
+ |
241
262
addModulus ( e , true , b1 , v1 , m1 ) and
242
263
addModulus ( e , false , b2 , v2 , m2 ) and
243
264
mod = m1 .gcd ( m2 ) and
244
- mod != 1 and
265
+ mod != 1 . toBigInt ( ) and
245
266
val = remainder ( v1 + v2 , mod )
246
267
|
247
268
b = b1 and b2 instanceof ZeroBound
248
269
or
249
270
b = b2 and b1 instanceof ZeroBound
250
271
)
251
272
or
252
- exists ( int v1 , int v2 , int m1 , int m2 |
273
+ exists (
274
+ QlBuiltins:: BigInt v1 , QlBuiltins:: BigInt v2 , QlBuiltins:: BigInt m1 , QlBuiltins:: BigInt m2
275
+ |
253
276
subModulus ( e , true , b , v1 , m1 ) and
254
277
subModulus ( e , false , any ( ZeroBound zb ) , v2 , m2 ) and
255
278
mod = m1 .gcd ( m2 ) and
256
- mod != 1 and
279
+ mod != 1 . toBigInt ( ) and
257
280
val = remainder ( v1 - v2 , mod )
258
281
)
259
282
}
260
283
261
284
private predicate condExprBranchModulus (
262
- ConditionalExpr cond , boolean branch , Bound b , int val , int mod
285
+ ConditionalExpr cond , boolean branch , Bound b , QlBuiltins :: BigInt val , QlBuiltins :: BigInt mod
263
286
) {
264
287
exprModulus ( cond .getBranchExpr ( branch ) , b , val , mod )
265
288
}
266
289
267
- private predicate addModulus ( Expr add , boolean isLeft , Bound b , int val , int mod ) {
290
+ private predicate addModulus (
291
+ Expr add , boolean isLeft , Bound b , QlBuiltins:: BigInt val , QlBuiltins:: BigInt mod
292
+ ) {
268
293
exists ( Expr larg , Expr rarg | nonConstAddition ( add , larg , rarg ) |
269
294
exprModulus ( larg , b , val , mod ) and isLeft = true
270
295
or
271
296
exprModulus ( rarg , b , val , mod ) and isLeft = false
272
297
)
273
298
}
274
299
275
- private predicate subModulus ( Expr sub , boolean isLeft , Bound b , int val , int mod ) {
300
+ private predicate subModulus (
301
+ Expr sub , boolean isLeft , Bound b , QlBuiltins:: BigInt val , QlBuiltins:: BigInt mod
302
+ ) {
276
303
exists ( Expr larg , Expr rarg | nonConstSubtraction ( sub , larg , rarg ) |
277
304
exprModulus ( larg , b , val , mod ) and isLeft = true
278
305
or
0 commit comments