C++: Test for overriding existing simple range analysis ranges.

This commit is contained in:
lcartey@github.com
2020-09-15 15:34:48 +01:00
parent 084992d40b
commit eaea860d3e
3 changed files with 20 additions and 0 deletions

View File

@@ -7,3 +7,8 @@ int test_extensibility_add(int x) {
return result; // 90 .. 110 return result; // 90 .. 110
} }
} }
int test_overridability_sub(int x) {
int result = x - x; // Returns 0 due to custom modeling in QL
return result; // 0
}

View File

@@ -2,3 +2,6 @@
| extensibility.c:5:19:5:19 | x | -10.0 | 2.147483647E9 | | extensibility.c:5:19:5:19 | x | -10.0 | 2.147483647E9 |
| extensibility.c:6:38:6:38 | x | -10.0 | 10.0 | | extensibility.c:6:38:6:38 | x | -10.0 | 10.0 |
| extensibility.c:7:12:7:17 | result | 90.0 | 110.0 | | extensibility.c:7:12:7:17 | result | 90.0 | 110.0 |
| extensibility.c:12:16:12:16 | x | -2.147483648E9 | 2.147483647E9 |
| extensibility.c:12:20:12:20 | x | -2.147483648E9 | 2.147483647E9 |
| extensibility.c:13:10:13:15 | result | 0.0 | 0.0 |

View File

@@ -25,6 +25,18 @@ class CustomAddFunctionCall extends SimpleRangeAnalysisExpr, FunctionCall {
override predicate dependsOnChild(Expr child) { child = this.getAnArgument() } override predicate dependsOnChild(Expr child) { child = this.getAnArgument() }
} }
class SelfSub extends SimpleRangeAnalysisExpr, SubExpr {
SelfSub() {
getLeftOperand().(VariableAccess).getTarget() = getRightOperand().(VariableAccess).getTarget()
}
override float getLowerBounds() { result = 0 }
override float getUpperBounds() { result = 0 }
override predicate dependsOnChild(Expr child) { child = this.getAnOperand() }
}
from VariableAccess expr, float lower, float upper from VariableAccess expr, float lower, float upper
where where
lower = lowerBound(expr) and lower = lowerBound(expr) and