Skip to content

Commit 26bd332

Browse files
authored
Merge pull request #21113 from paldepind/cpp/range-analysis-float-ceil
C++: Remove `safeFloor` in simple range analysis
2 parents 0c8fd83 + 7c0054b commit 26bd332

File tree

9 files changed

+4899
-4892
lines changed

9 files changed

+4899
-4892
lines changed

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,6 @@ private class UnsignedBitwiseAndExpr extends BitwiseAndExpr {
158158
}
159159
}
160160

161-
/**
162-
* Gets the floor of `v`, with additional logic to work around issues with
163-
* large numbers.
164-
*/
165-
bindingset[v]
166-
float safeFloor(float v) {
167-
// return the floor of v
168-
v.abs() < 2.pow(31) and
169-
result = v.floor()
170-
or
171-
// `floor()` doesn't work correctly on large numbers (since it returns an integer),
172-
// so fall back to unrounded numbers at this scale.
173-
not v.abs() < 2.pow(31) and
174-
result = v
175-
}
176-
177161
/** A `MulExpr` where exactly one operand is constant. */
178162
private class MulByConstantExpr extends MulExpr {
179163
float constant;
@@ -1266,7 +1250,7 @@ private float getLowerBoundsImpl(Expr expr) {
12661250
rsExpr = expr and
12671251
left = getFullyConvertedLowerBounds(rsExpr.getLeftOperand()) and
12681252
right = getValue(rsExpr.getRightOperand().getFullyConverted()).toInt() and
1269-
result = safeFloor(left / 2.pow(right))
1253+
result = (left / 2.pow(right)).floorFloat()
12701254
)
12711255
// Not explicitly modeled by a SimpleRangeAnalysisExpr
12721256
) and
@@ -1475,7 +1459,7 @@ private float getUpperBoundsImpl(Expr expr) {
14751459
rsExpr = expr and
14761460
left = getFullyConvertedUpperBounds(rsExpr.getLeftOperand()) and
14771461
right = getValue(rsExpr.getRightOperand().getFullyConverted()).toInt() and
1478-
result = safeFloor(left / 2.pow(right))
1462+
result = (left / 2.pow(right)).floorFloat()
14791463
)
14801464
// Not explicitly modeled by a SimpleRangeAnalysisExpr
14811465
) and

0 commit comments

Comments
 (0)