@@ -91,13 +91,30 @@ private float wideningUpperBounds(ArithmeticType t) {
91
91
result = 1.0 / 0.0 // +Inf
92
92
}
93
93
94
+ /**
95
+ * Gets the value of the expression `e`, if it is a constant.
96
+ * This predicate also handles the case of constant variables initialized in compilation units,
97
+ * which doesn't necessarily have a getValue() result from the extractor.
98
+ */
99
+ private string getValue ( Expr e ) {
100
+ if exists ( e .getValue ( ) )
101
+ then result = e .getValue ( )
102
+ else
103
+ exists ( VariableAccess access , Variable v |
104
+ e = access and
105
+ v = access .getTarget ( ) and
106
+ v .getUnderlyingType ( ) .isConst ( ) and
107
+ result = getValue ( v .getAnAssignedValue ( ) )
108
+ )
109
+ }
110
+
94
111
/** Set of expressions which we know how to analyze. */
95
112
private predicate analyzableExpr ( Expr e ) {
96
113
// The type of the expression must be arithmetic. We reuse the logic in
97
114
// `exprMinVal` to check this.
98
115
exists ( exprMinVal ( e ) ) and
99
116
(
100
- exists ( e . getValue ( ) .toFloat ( ) ) or
117
+ exists ( getValue ( e ) .toFloat ( ) ) or
101
118
e instanceof UnaryPlusExpr or
102
119
e instanceof UnaryMinusExpr or
103
120
e instanceof MinExpr or
@@ -365,8 +382,8 @@ private float getTruncatedLowerBounds(Expr expr) {
365
382
then
366
383
// If the expression evaluates to a constant, then there is no
367
384
// need to call getLowerBoundsImpl.
368
- if exists ( expr . getValue ( ) .toFloat ( ) )
369
- then result = expr . getValue ( ) .toFloat ( )
385
+ if exists ( getValue ( expr ) .toFloat ( ) )
386
+ then result = getValue ( expr ) .toFloat ( )
370
387
else (
371
388
// Some of the bounds computed by getLowerBoundsImpl might
372
389
// overflow, so we replace invalid bounds with exprMinVal.
@@ -418,8 +435,8 @@ private float getTruncatedUpperBounds(Expr expr) {
418
435
then
419
436
// If the expression evaluates to a constant, then there is no
420
437
// need to call getUpperBoundsImpl.
421
- if exists ( expr . getValue ( ) .toFloat ( ) )
422
- then result = expr . getValue ( ) .toFloat ( )
438
+ if exists ( getValue ( expr ) .toFloat ( ) )
439
+ then result = getValue ( expr ) .toFloat ( )
423
440
else (
424
441
// Some of the bounds computed by `getUpperBoundsImpl`
425
442
// might overflow, so we replace invalid bounds with
0 commit comments