@@ -156,10 +156,29 @@ private int validBitSize() { result = [7, 8, 15, 16, 31, 32, 63, 64] }
156
156
private newtype TArchitectureBitSize =
157
157
TMk32Bit ( ) or
158
158
TMk64Bit ( ) or
159
- TMkArchitectureIndependent ( )
159
+ TMkUnknown ( )
160
+
161
+ private class ArchitectureBitSize extends TArchitectureBitSize {
162
+ /** Gets an integer for the architecture bit size, if known. */
163
+ int toInt ( ) {
164
+ this = TMk32Bit ( ) and result = 32
165
+ or
166
+ this = TMk64Bit ( ) and result = 64
167
+ }
168
+
169
+ /** Holds if the architecture bit size is unknown. */
170
+ predicate isUnknown ( ) { this = TMkUnknown ( ) }
171
+
172
+ /** Gets a textual representation of this element. */
173
+ string toString ( ) {
174
+ result = this .toInt ( ) + "-bit"
175
+ or
176
+ this .isUnknown ( ) and result = "unknown"
177
+ }
178
+ }
160
179
161
180
private newtype TMaxValueState =
162
- TMkMaxValueState ( int bitSize , TArchitectureBitSize architectureBitSize ) {
181
+ TMkMaxValueState ( int bitSize , ArchitectureBitSize architectureBitSize ) {
163
182
bitSize = validBitSize ( )
164
183
}
165
184
@@ -176,15 +195,8 @@ private class MaxValueState extends TMaxValueState {
176
195
*/
177
196
int getBitSize ( ) { this = TMkMaxValueState ( result , _) }
178
197
179
- /**
180
- * Gets whether the architecture is 32 bit or 64 bit, if that has been
181
- * determined already.
182
- */
183
- int getArchitectureBitSize ( ) {
184
- this = TMkMaxValueState ( _, TMk32Bit ( ) ) and result = 32
185
- or
186
- this = TMkMaxValueState ( _, TMk64Bit ( ) ) and result = 64
187
- }
198
+ /** Gets whether the architecture is 32 bit or 64 bit, or if it is unknown. */
199
+ ArchitectureBitSize getArchitectureBitSize ( ) { this = TMkMaxValueState ( _, result ) }
188
200
189
201
/**
190
202
* Gets the bitsize we should use for a sink.
@@ -201,9 +213,9 @@ private class MaxValueState extends TMaxValueState {
201
213
/** Gets a textual representation of this element. */
202
214
string toString ( ) {
203
215
exists ( string suffix |
204
- if exists ( this .getArchitectureBitSize ( ) )
205
- then suffix = " (on " + this . getArchitectureBitSize ( ) + "-bit architecture)"
206
- else suffix = ""
216
+ suffix = " (on " + this .getArchitectureBitSize ( ) . toInt ( ) + "-bit architecture)"
217
+ or
218
+ this . getArchitectureBitSize ( ) . isUnknown ( ) and suffix = ""
207
219
|
208
220
result = "MaxValueState(max value <= 2^(" + this .getBitSize ( ) + ")-1" + suffix
209
221
)
@@ -339,9 +351,7 @@ class UpperBoundCheck extends BarrierFlowStateTransformer {
339
351
// this will find results that only exist on 32-bit architectures.
340
352
not g .isBoundFor ( bitsize , state .getSinkBitSize ( 32 ) )
341
353
) and
342
- if exists ( state .getArchitectureBitSize ( ) )
343
- then result .getArchitectureBitSize ( ) = state .getArchitectureBitSize ( )
344
- else not exists ( result .getArchitectureBitSize ( ) )
354
+ result .getArchitectureBitSize ( ) = state .getArchitectureBitSize ( )
345
355
}
346
356
}
347
357
@@ -385,10 +395,10 @@ private module ConversionWithoutBoundsCheckConfig implements DataFlow::StateConf
385
395
then
386
396
exists ( int b | b = [ 32 , 64 ] |
387
397
state .getBitSize ( ) = adjustBitSize ( 0 , sourceIsSigned , b ) and
388
- state .getArchitectureBitSize ( ) = b
398
+ state .getArchitectureBitSize ( ) . toInt ( ) = b
389
399
)
390
400
else (
391
- not exists ( state .getArchitectureBitSize ( ) ) and
401
+ state .getArchitectureBitSize ( ) . isUnknown ( ) and
392
402
state .getBitSize ( ) =
393
403
min ( int bitsize |
394
404
bitsize = validBitSize ( ) and
@@ -412,7 +422,7 @@ private module ConversionWithoutBoundsCheckConfig implements DataFlow::StateConf
412
422
// Use a default value of 32 for `MaxValueState.getSinkBitSize` because
413
423
// this will find results that only exist on 32-bit architectures.
414
424
architectureBitSize = getIntTypeBitSize ( sink .getFile ( ) , state .getSinkBitSize ( 32 ) ) and
415
- not ( state .getArchitectureBitSize ( ) = 32 and architectureBitSize = 64 ) and
425
+ not ( state .getArchitectureBitSize ( ) . toInt ( ) = 32 and architectureBitSize = 64 ) and
416
426
sink .getResultType ( ) .getUnderlyingType ( ) = integerType and
417
427
(
418
428
sinkBitsize = integerType .getSize ( )
0 commit comments