Skip to content

Commit b14ece7

Browse files
committed
C++: Add range analysis test demonstrating missing measuring bounds.
1 parent 522e4d6 commit b14ece7

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
| minmax.c:26:37:26:37 | x | 1 |
1818
| minmax.c:26:40:26:40 | y | 2 |
1919
| minmax.c:26:43:26:43 | z | 0 |
20+
| missing_bounds.cpp:40:5:40:20 | x | 0 |
21+
| missing_bounds.cpp:40:5:40:20 | x | 0 |
22+
| missing_bounds.cpp:41:5:41:20 | x | 0 |
23+
| missing_bounds.cpp:41:5:41:20 | x | 0 |
24+
| missing_bounds.cpp:42:5:42:20 | x | 0 |
25+
| missing_bounds.cpp:42:5:42:20 | x | 0 |
26+
| missing_bounds.cpp:43:5:43:20 | x | 0 |
27+
| missing_bounds.cpp:43:5:43:20 | x | 0 |
28+
| missing_bounds.cpp:44:5:44:20 | x | 0 |
29+
| missing_bounds.cpp:44:5:44:20 | x | 0 |
30+
| missing_bounds.cpp:45:5:45:20 | x | 0 |
31+
| missing_bounds.cpp:45:5:45:20 | x | 0 |
32+
| missing_bounds.cpp:46:5:46:20 | x | 0 |
33+
| missing_bounds.cpp:46:5:46:20 | x | 0 |
34+
| missing_bounds.cpp:72:12:72:12 | x | 0 |
2035
| test.c:8:5:8:9 | count | -2147483648 |
2136
| test.c:8:13:8:17 | count | -2147483648 |
2237
| test.c:10:10:10:14 | count | -2147483648 |
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
enum MY_ENUM {
2+
A = 0x1, // $ nonFunctionalNrOfBounds
3+
B = 0x2, // $ nonFunctionalNrOfBounds
4+
C = 0x4, // $ nonFunctionalNrOfBounds
5+
D = 0x8, // $ nonFunctionalNrOfBounds
6+
E = 0x10, // $ nonFunctionalNrOfBounds
7+
F = 0x20, // $ nonFunctionalNrOfBounds
8+
G = 0x40, // $ nonFunctionalNrOfBounds
9+
H = 0x80, // $ nonFunctionalNrOfBounds
10+
I = 0x100, // $ nonFunctionalNrOfBounds
11+
J = 0x200, // $ nonFunctionalNrOfBounds
12+
L = 0x400, // $ nonFunctionalNrOfBounds
13+
M = 0x800, // $ nonFunctionalNrOfBounds
14+
N = 0x1000, // $ nonFunctionalNrOfBounds
15+
O = 0x2000, // $ nonFunctionalNrOfBounds
16+
P = 0x4000, // $ nonFunctionalNrOfBounds
17+
Q = 0x8000, // $ nonFunctionalNrOfBounds
18+
R = 0x10000, // $ nonFunctionalNrOfBounds
19+
S = 0x20000, // $ nonFunctionalNrOfBounds
20+
T = 0x40000, // $ nonFunctionalNrOfBounds
21+
U = 0x80000, // $ nonFunctionalNrOfBounds
22+
V = 0x100000, // $ nonFunctionalNrOfBounds
23+
W = 0x200000, // $ nonFunctionalNrOfBounds
24+
X = 0x400000, // $ nonFunctionalNrOfBounds
25+
Y = 0x800000, // $ nonFunctionalNrOfBounds
26+
Z = 0x1000000, // $ nonFunctionalNrOfBounds
27+
AA = 0x2000000, // $ nonFunctionalNrOfBounds
28+
AB = 0x4000000, // $ nonFunctionalNrOfBounds
29+
AC = 0x8000000, // $ nonFunctionalNrOfBounds
30+
AD = 0x10000000, // $ nonFunctionalNrOfBounds
31+
AE = 0x20000000 // $ nonFunctionalNrOfBounds
32+
};
33+
34+
typedef unsigned int MY_ENUM_FLAGS;
35+
36+
MY_ENUM_FLAGS check_and_subs(MY_ENUM_FLAGS x)
37+
{
38+
39+
#define CHECK_AND_SUB(flag) if ((x & flag) == flag) { x -= flag; }
40+
CHECK_AND_SUB(A); // $ nonFunctionalNrOfBounds
41+
CHECK_AND_SUB(B); // $ nonFunctionalNrOfBounds
42+
CHECK_AND_SUB(C); // $ nonFunctionalNrOfBounds
43+
CHECK_AND_SUB(D); // $ nonFunctionalNrOfBounds
44+
CHECK_AND_SUB(E); // $ nonFunctionalNrOfBounds
45+
CHECK_AND_SUB(F); // $ nonFunctionalNrOfBounds
46+
CHECK_AND_SUB(G); // $ nonFunctionalNrOfBounds
47+
// CHECK_AND_SUB(H);
48+
// CHECK_AND_SUB(I);
49+
// CHECK_AND_SUB(J);
50+
// CHECK_AND_SUB(L);
51+
// CHECK_AND_SUB(M);
52+
// CHECK_AND_SUB(N);
53+
// CHECK_AND_SUB(O);
54+
// CHECK_AND_SUB(P);
55+
// CHECK_AND_SUB(Q);
56+
// CHECK_AND_SUB(R);
57+
// CHECK_AND_SUB(S);
58+
// CHECK_AND_SUB(T);
59+
// CHECK_AND_SUB(U);
60+
// CHECK_AND_SUB(V);
61+
// CHECK_AND_SUB(W);
62+
// CHECK_AND_SUB(X);
63+
// CHECK_AND_SUB(Y);
64+
// CHECK_AND_SUB(Z);
65+
// CHECK_AND_SUB(AA);
66+
// CHECK_AND_SUB(AB);
67+
// CHECK_AND_SUB(AC);
68+
// CHECK_AND_SUB(AD);
69+
// CHECK_AND_SUB(AE);
70+
#undef CHECK_AND_SUB
71+
72+
return x; // $ nonFunctionalNrOfBounds
73+
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,36 @@ estimateNrOfBounds
3737
| minmax.c:26:37:26:37 | x | 1.0 |
3838
| minmax.c:26:40:26:40 | y | 1.0 |
3939
| minmax.c:26:43:26:43 | z | 2.0 |
40+
| missing_bounds.cpp:40:5:40:19 | ... == ... | 1.0 |
41+
| missing_bounds.cpp:40:5:40:20 | x | 1.0 |
42+
| missing_bounds.cpp:40:5:40:20 | x | 1.0 |
43+
| missing_bounds.cpp:40:19:40:19 | (unsigned int)... | 1.0 |
44+
| missing_bounds.cpp:40:19:40:19 | (unsigned int)... | 1.0 |
45+
| missing_bounds.cpp:40:19:40:19 | (unsigned int)... | 1.0 |
46+
| missing_bounds.cpp:41:5:41:19 | ... == ... | 1.0 |
47+
| missing_bounds.cpp:41:19:41:19 | (unsigned int)... | 1.0 |
48+
| missing_bounds.cpp:41:19:41:19 | (unsigned int)... | 1.0 |
49+
| missing_bounds.cpp:41:19:41:19 | (unsigned int)... | 1.0 |
50+
| missing_bounds.cpp:42:5:42:19 | ... == ... | 1.0 |
51+
| missing_bounds.cpp:42:19:42:19 | (unsigned int)... | 1.0 |
52+
| missing_bounds.cpp:42:19:42:19 | (unsigned int)... | 1.0 |
53+
| missing_bounds.cpp:42:19:42:19 | (unsigned int)... | 1.0 |
54+
| missing_bounds.cpp:43:5:43:19 | ... == ... | 1.0 |
55+
| missing_bounds.cpp:43:19:43:19 | (unsigned int)... | 1.0 |
56+
| missing_bounds.cpp:43:19:43:19 | (unsigned int)... | 1.0 |
57+
| missing_bounds.cpp:43:19:43:19 | (unsigned int)... | 1.0 |
58+
| missing_bounds.cpp:44:5:44:19 | ... == ... | 1.0 |
59+
| missing_bounds.cpp:44:19:44:19 | (unsigned int)... | 1.0 |
60+
| missing_bounds.cpp:44:19:44:19 | (unsigned int)... | 1.0 |
61+
| missing_bounds.cpp:44:19:44:19 | (unsigned int)... | 1.0 |
62+
| missing_bounds.cpp:45:5:45:19 | ... == ... | 1.0 |
63+
| missing_bounds.cpp:45:19:45:19 | (unsigned int)... | 1.0 |
64+
| missing_bounds.cpp:45:19:45:19 | (unsigned int)... | 1.0 |
65+
| missing_bounds.cpp:45:19:45:19 | (unsigned int)... | 1.0 |
66+
| missing_bounds.cpp:46:5:46:19 | ... == ... | 1.0 |
67+
| missing_bounds.cpp:46:19:46:19 | (unsigned int)... | 1.0 |
68+
| missing_bounds.cpp:46:19:46:19 | (unsigned int)... | 1.0 |
69+
| missing_bounds.cpp:46:19:46:19 | (unsigned int)... | 1.0 |
4070
| test.c:6:14:6:15 | 0 | 1.0 |
4171
| test.c:8:5:8:9 | count | 1.0 |
4272
| test.c:8:5:8:19 | ... = ... | 13.0 |

cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/nrOfBounds.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ query predicate estimateNrOfBounds(Expr e, float nrOfBounds) {
1212
*/
1313
private predicate nonFunctionalNrOfBounds(Expr e) {
1414
strictcount(SimpleRangeAnalysisInternal::estimateNrOfBounds(e)) > 1
15+
or
16+
e.getFile().getBaseName() = "missing_bounds.cpp" and
17+
count(SimpleRangeAnalysisInternal::estimateNrOfBounds(e)) != 1
1518
}
1619

1720
module FunctionalityTest implements TestSig {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
| minmax.c:26:37:26:37 | x | 1 |
1818
| minmax.c:26:40:26:40 | y | 2 |
1919
| minmax.c:26:43:26:43 | z | 1 |
20+
| missing_bounds.cpp:40:5:40:20 | x | 4294967295 |
21+
| missing_bounds.cpp:40:5:40:20 | x | 4294967295 |
22+
| missing_bounds.cpp:41:5:41:20 | x | 4294967295 |
23+
| missing_bounds.cpp:41:5:41:20 | x | 4294967295 |
24+
| missing_bounds.cpp:42:5:42:20 | x | 4294967295 |
25+
| missing_bounds.cpp:42:5:42:20 | x | 4294967295 |
26+
| missing_bounds.cpp:43:5:43:20 | x | 4294967295 |
27+
| missing_bounds.cpp:43:5:43:20 | x | 4294967295 |
28+
| missing_bounds.cpp:44:5:44:20 | x | 4294967295 |
29+
| missing_bounds.cpp:44:5:44:20 | x | 4294967295 |
30+
| missing_bounds.cpp:45:5:45:20 | x | 4294967295 |
31+
| missing_bounds.cpp:45:5:45:20 | x | 4294967295 |
32+
| missing_bounds.cpp:46:5:46:20 | x | 4294967295 |
33+
| missing_bounds.cpp:46:5:46:20 | x | 4294967295 |
34+
| missing_bounds.cpp:72:12:72:12 | x | 4294967295 |
2035
| test.c:8:5:8:9 | count | 2147483647 |
2136
| test.c:8:13:8:17 | count | 2147483647 |
2237
| test.c:10:10:10:14 | count | 2147483647 |

0 commit comments

Comments
 (0)