Skip to content

Commit eaea860

Browse files
committed
C++: Test for overriding existing simple range analysis ranges.
1 parent 084992d commit eaea860

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

cpp/ql/test/experimental/library-tests/rangeanalysis/extensibility/extensibility.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ int test_extensibility_add(int x) {
77
return result; // 90 .. 110
88
}
99
}
10+
11+
int test_overridability_sub(int x) {
12+
int result = x - x; // Returns 0 due to custom modeling in QL
13+
return result; // 0
14+
}

cpp/ql/test/experimental/library-tests/rangeanalysis/extensibility/extensibility.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
| extensibility.c:5:19:5:19 | x | -10.0 | 2.147483647E9 |
33
| extensibility.c:6:38:6:38 | x | -10.0 | 10.0 |
44
| extensibility.c:7:12:7:17 | result | 90.0 | 110.0 |
5+
| extensibility.c:12:16:12:16 | x | -2.147483648E9 | 2.147483647E9 |
6+
| extensibility.c:12:20:12:20 | x | -2.147483648E9 | 2.147483647E9 |
7+
| extensibility.c:13:10:13:15 | result | 0.0 | 0.0 |

cpp/ql/test/experimental/library-tests/rangeanalysis/extensibility/extensibility.ql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ class CustomAddFunctionCall extends SimpleRangeAnalysisExpr, FunctionCall {
2525
override predicate dependsOnChild(Expr child) { child = this.getAnArgument() }
2626
}
2727

28+
class SelfSub extends SimpleRangeAnalysisExpr, SubExpr {
29+
SelfSub() {
30+
getLeftOperand().(VariableAccess).getTarget() = getRightOperand().(VariableAccess).getTarget()
31+
}
32+
33+
override float getLowerBounds() { result = 0 }
34+
35+
override float getUpperBounds() { result = 0 }
36+
37+
override predicate dependsOnChild(Expr child) { child = this.getAnOperand() }
38+
}
39+
2840
from VariableAccess expr, float lower, float upper
2941
where
3042
lower = lowerBound(expr) and

0 commit comments

Comments
 (0)