Skip to content

Commit 7555440

Browse files
committed
C++: Remove safeFloor in simple range analysis
1 parent bd24fb0 commit 7555440

3 files changed

Lines changed: 4 additions & 20 deletions

File tree

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

cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/lowerBound.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
| test.c:330:14:330:14 | r | -2147483648 |
352352
| test.c:333:10:333:14 | total | -2147483648 |
353353
| test.c:341:32:341:34 | odd | 9007199254740991 |
354-
| test.c:343:10:343:16 | shifted | 4503599627370495.5 |
354+
| test.c:343:10:343:16 | shifted | 4503599627370495 |
355355
| test.c:348:7:348:7 | x | -2147483648 |
356356
| test.c:352:10:352:10 | i | 0 |
357357
| test.c:353:5:353:5 | i | 0 |

cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/upperBound.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
| test.c:330:14:330:14 | r | 2147483647 |
352352
| test.c:333:10:333:14 | total | 2147483647 |
353353
| test.c:341:32:341:34 | odd | 9007199254740991 |
354-
| test.c:343:10:343:16 | shifted | 4503599627370495.5 |
354+
| test.c:343:10:343:16 | shifted | 4503599627370495 |
355355
| test.c:348:7:348:7 | x | 2147483647 |
356356
| test.c:352:10:352:10 | i | 7 |
357357
| test.c:353:5:353:5 | i | 2 |

0 commit comments

Comments
 (0)