@@ -91,13 +91,30 @@ private float wideningUpperBounds(ArithmeticType t) {
9191 result = 1.0 / 0.0 // +Inf
9292}
9393
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+
94111/** Set of expressions which we know how to analyze. */
95112private predicate analyzableExpr ( Expr e ) {
96113 // The type of the expression must be arithmetic. We reuse the logic in
97114 // `exprMinVal` to check this.
98115 exists ( exprMinVal ( e ) ) and
99116 (
100- exists ( e . getValue ( ) .toFloat ( ) ) or
117+ exists ( getValue ( e ) .toFloat ( ) ) or
101118 e instanceof UnaryPlusExpr or
102119 e instanceof UnaryMinusExpr or
103120 e instanceof MinExpr or
@@ -365,8 +382,8 @@ private float getTruncatedLowerBounds(Expr expr) {
365382 then
366383 // If the expression evaluates to a constant, then there is no
367384 // 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 ( )
370387 else (
371388 // Some of the bounds computed by getLowerBoundsImpl might
372389 // overflow, so we replace invalid bounds with exprMinVal.
@@ -418,8 +435,8 @@ private float getTruncatedUpperBounds(Expr expr) {
418435 then
419436 // If the expression evaluates to a constant, then there is no
420437 // 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 ( )
423440 else (
424441 // Some of the bounds computed by `getUpperBoundsImpl`
425442 // might overflow, so we replace invalid bounds with
0 commit comments