File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed
cpp/ql/test/experimental/library-tests/rangeanalysis/extensibility Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 1- /// Adds its arguments (requires custom modeling in QL)
1+ /// Adds its arguments (has custom modeling in QL)
22int custom_add_function (int a , int b );
33
44int test_extensibility_add (int x ) {
55 if (x >= -10 && x <= 10 ) {
66 int result = custom_add_function (x , 100 );
7- return result ; // should be 90 .. 110
7+ return result ; // 90 .. 110
88 }
99}
Original file line number Diff line number Diff line change 11| extensibility.c:5:7:5:7 | x | -2.147483648E9 | 2.147483647E9 |
22| extensibility.c:5:19:5:19 | x | -10.0 | 2.147483647E9 |
33| extensibility.c:6:38:6:38 | x | -10.0 | 10.0 |
4- | extensibility.c:7:12:7:17 | result | -2.147483648E9 | 2.147483647E9 |
4+ | extensibility.c:7:12:7:17 | result | 90.0 | 110.0 |
Original file line number Diff line number Diff line change 11import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
22import experimental.semmle.code.cpp.models.interfaces.SimpleRangeAnalysisExpr
33
4+ class CustomAddFunctionCall extends SimpleRangeAnalysisExpr , FunctionCall {
5+ CustomAddFunctionCall ( ) { this .getTarget ( ) .hasGlobalName ( "custom_add_function" ) }
6+
7+ override float getLowerBounds ( ) {
8+ exists ( float lower0 , float lower1 |
9+ lower0 = getFullyConvertedLowerBounds ( this .getArgument ( 0 ) ) and
10+ lower1 = getFullyConvertedLowerBounds ( this .getArgument ( 1 ) ) and
11+ // Note: this rounds toward 0, not -Inf as it should
12+ result = lower0 + lower1
13+ )
14+ }
15+
16+ override float getUpperBounds ( ) {
17+ exists ( float upper0 , float upper1 |
18+ upper0 = getFullyConvertedUpperBounds ( this .getArgument ( 0 ) ) and
19+ upper1 = getFullyConvertedUpperBounds ( this .getArgument ( 1 ) ) and
20+ // Note: this rounds toward 0, not Inf as it should
21+ result = upper0 + upper1
22+ )
23+ }
24+
25+ override predicate dependsOnChild ( Expr child ) { child = this .getAnArgument ( ) }
26+ }
27+
428from VariableAccess expr , float lower , float upper
529where
630 lower = lowerBound ( expr ) and
You can’t perform that action at this time.
0 commit comments