Skip to content

Commit 1b5b374

Browse files
committed
C++: Move getFullyConverted{Upper,Lower}Bounds
Rather than being public, these internal predicates are now exposed through a `SimpleRangeAnalysisInternal` module so it's clear that they are not for general use.
1 parent 18ba562 commit 1b5b374

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed
Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
/**
2+
* EXPERIMENTAL: The API of this module may change without notice.
3+
*
24
* Provides a class for modeling `Expr`s with a restricted range.
35
*/
46

57
import cpp
8+
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
69

710
/**
8-
* An expression for which a range can be deduced.
11+
* EXPERIMENTAL: The API of this class may change without notice.
12+
*
13+
* An expression for which a range can be deduced. Extend this class to add
14+
* functionality to the range analysis library.
915
*/
1016
abstract class SimpleRangeAnalysisExpr extends Expr {
11-
/** Gets the lower bound of the expression. */
17+
/**
18+
* Gets the lower bound of the expression.
19+
*
20+
* Implementations of this predicate should use
21+
* `getFullyConvertedLowerBounds` and `getFullyConvertedUpperBounds` for
22+
* recursive calls to get the bounds of their children.
23+
*/
1224
abstract float getLowerBounds();
1325

14-
/** Gets the upper bound of the expression. */
26+
/**
27+
* Gets the upper bound of the expression.
28+
*
29+
* Implementations of this predicate should use
30+
* `getFullyConvertedLowerBounds` and `getFullyConvertedUpperBounds` for
31+
* recursive calls to get the bounds of their children.
32+
*/
1533
abstract float getUpperBounds();
1634

1735
/** Holds if this expression depends on the definition `srcDef` for StackVariable `srcVar`. */
1836
predicate dependsOnDef(RangeSsaDefinition srcDef, StackVariable srcVar) { none() }
1937
}
38+
39+
import SimpleRangeAnalysisInternal

cpp/ql/src/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,6 @@ private float addRoundingDownSmall(float x, float small) {
452452
if (x + small) - x > small then result = (x + small).nextDown() else result = (x + small)
453453
}
454454

455-
/**
456-
* Gets the truncated lower bounds of the fully converted expression.
457-
*/
458-
float getFullyConvertedLowerBounds(Expr expr) {
459-
result = getTruncatedLowerBounds(expr.getFullyConverted())
460-
}
461-
462455
/**
463456
* Gets the lower bounds of the expression.
464457
*
@@ -505,13 +498,6 @@ private float getTruncatedLowerBounds(Expr expr) {
505498
result = exprMinVal(expr)
506499
}
507500

508-
/**
509-
* Gets the truncated upper bounds of the fully converted expression.
510-
*/
511-
float getFullyConvertedUpperBounds(Expr expr) {
512-
result = getTruncatedUpperBounds(expr.getFullyConverted())
513-
}
514-
515501
/**
516502
* Gets the upper bounds of the expression.
517503
*
@@ -1527,3 +1513,25 @@ private module SimpleRangeAnalysisCached {
15271513
convertedExprMightOverflowPositively(expr)
15281514
}
15291515
}
1516+
1517+
/**
1518+
* INTERNAL: do not use. This module contains utilities for use in the
1519+
* experimental `SimpleRangeAnalysisExpr` module.
1520+
*/
1521+
module SimpleRangeAnalysisInternal {
1522+
/**
1523+
* Gets the truncated lower bounds of the fully converted expression.
1524+
*/
1525+
float getFullyConvertedLowerBounds(Expr expr) {
1526+
result = getTruncatedLowerBounds(expr.getFullyConverted())
1527+
}
1528+
1529+
/**
1530+
* Gets the truncated upper bounds of the fully converted expression.
1531+
*/
1532+
float getFullyConvertedUpperBounds(Expr expr) {
1533+
result = getTruncatedUpperBounds(expr.getFullyConverted())
1534+
}
1535+
}
1536+
1537+
private import SimpleRangeAnalysisInternal

0 commit comments

Comments
 (0)