File tree Expand file tree Collapse file tree
cpp/ql/src/semmle/code/cpp/rangeanalysis Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -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 .getType ( ) .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
You can’t perform that action at this time.
0 commit comments