Skip to content

Commit 0202baf

Browse files
authored
Merge pull request github#12709 from MathiasVP/disable-rounding-2
C++: Disable floating point rounding in range analysis
2 parents dde37c6 + 27d8f98 commit 0202baf

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/semantic/analysis/FloatDelta.qll

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,5 @@ module FloatDelta implements DeltaSig {
1616
Delta fromInt(int n) { result = n }
1717

1818
bindingset[f]
19-
Delta fromFloat(float f) {
20-
result =
21-
min(float diff, float res |
22-
diff = (res - f) and res = f.ceil()
23-
or
24-
diff = (f - res) and res = f.floor()
25-
|
26-
res order by diff
27-
)
28-
}
19+
Delta fromFloat(float f) { result = f }
2920
}

cpp/ql/test/library-tests/ir/range-analysis/RangeAnalysis.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ private string getDirectionString(boolean d) {
2929
}
3030

3131
bindingset[value]
32-
private string getOffsetString(int value) {
32+
private string getOffsetString(float value) {
3333
if value >= 0 then result = "+" + value.toString() else result = value.toString()
3434
}
3535

3636
bindingset[s]
3737
string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s }
3838

3939
bindingset[delta]
40-
private string getBoundString(SemBound b, int delta) {
40+
private string getBoundString(SemBound b, float delta) {
4141
b instanceof SemZeroBound and result = delta.toString()
4242
or
4343
result =
@@ -51,7 +51,7 @@ private string getBoundString(SemBound b, int delta) {
5151
}
5252

5353
private string getARangeString(SemExpr e) {
54-
exists(SemBound b, int delta, boolean upper |
54+
exists(SemBound b, float delta, boolean upper |
5555
semBounded(e, b, delta, upper, _) and
5656
if semBounded(e, b, delta, upper.booleanNot(), _)
5757
then delta != 0 and result = "==" + getBoundString(b, delta)

cpp/ql/test/library-tests/ir/range-analysis/SimpleRangeAnalysis_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ unsigned long mult_rounding() {
741741
range(y); // $ range===1000000003
742742
range(x); // $ range===1000000003
743743
xy = x * y;
744-
range(xy); // $ range===2147483647
744+
range(xy); // $ range===1000000006000000000
745745
return xy; // BUG: upper bound should be >= 1000000006000000009UL
746746
}
747747

0 commit comments

Comments
 (0)