C++: Add range analysis test demonstrating missing measuring bounds.

This commit is contained in:
Mathias Vorreiter Pedersen
2026-02-11 16:45:57 +00:00
parent 522e4d64de
commit b14ece72be
5 changed files with 136 additions and 0 deletions

View File

@@ -17,6 +17,21 @@
| minmax.c:26:37:26:37 | x | 1 |
| minmax.c:26:40:26:40 | y | 2 |
| minmax.c:26:43:26:43 | z | 0 |
| missing_bounds.cpp:40:5:40:20 | x | 0 |
| missing_bounds.cpp:40:5:40:20 | x | 0 |
| missing_bounds.cpp:41:5:41:20 | x | 0 |
| missing_bounds.cpp:41:5:41:20 | x | 0 |
| missing_bounds.cpp:42:5:42:20 | x | 0 |
| missing_bounds.cpp:42:5:42:20 | x | 0 |
| missing_bounds.cpp:43:5:43:20 | x | 0 |
| missing_bounds.cpp:43:5:43:20 | x | 0 |
| missing_bounds.cpp:44:5:44:20 | x | 0 |
| missing_bounds.cpp:44:5:44:20 | x | 0 |
| missing_bounds.cpp:45:5:45:20 | x | 0 |
| missing_bounds.cpp:45:5:45:20 | x | 0 |
| missing_bounds.cpp:46:5:46:20 | x | 0 |
| missing_bounds.cpp:46:5:46:20 | x | 0 |
| missing_bounds.cpp:72:12:72:12 | x | 0 |
| test.c:8:5:8:9 | count | -2147483648 |
| test.c:8:13:8:17 | count | -2147483648 |
| test.c:10:10:10:14 | count | -2147483648 |

View File

@@ -0,0 +1,73 @@
enum MY_ENUM {
A = 0x1, // $ nonFunctionalNrOfBounds
B = 0x2, // $ nonFunctionalNrOfBounds
C = 0x4, // $ nonFunctionalNrOfBounds
D = 0x8, // $ nonFunctionalNrOfBounds
E = 0x10, // $ nonFunctionalNrOfBounds
F = 0x20, // $ nonFunctionalNrOfBounds
G = 0x40, // $ nonFunctionalNrOfBounds
H = 0x80, // $ nonFunctionalNrOfBounds
I = 0x100, // $ nonFunctionalNrOfBounds
J = 0x200, // $ nonFunctionalNrOfBounds
L = 0x400, // $ nonFunctionalNrOfBounds
M = 0x800, // $ nonFunctionalNrOfBounds
N = 0x1000, // $ nonFunctionalNrOfBounds
O = 0x2000, // $ nonFunctionalNrOfBounds
P = 0x4000, // $ nonFunctionalNrOfBounds
Q = 0x8000, // $ nonFunctionalNrOfBounds
R = 0x10000, // $ nonFunctionalNrOfBounds
S = 0x20000, // $ nonFunctionalNrOfBounds
T = 0x40000, // $ nonFunctionalNrOfBounds
U = 0x80000, // $ nonFunctionalNrOfBounds
V = 0x100000, // $ nonFunctionalNrOfBounds
W = 0x200000, // $ nonFunctionalNrOfBounds
X = 0x400000, // $ nonFunctionalNrOfBounds
Y = 0x800000, // $ nonFunctionalNrOfBounds
Z = 0x1000000, // $ nonFunctionalNrOfBounds
AA = 0x2000000, // $ nonFunctionalNrOfBounds
AB = 0x4000000, // $ nonFunctionalNrOfBounds
AC = 0x8000000, // $ nonFunctionalNrOfBounds
AD = 0x10000000, // $ nonFunctionalNrOfBounds
AE = 0x20000000 // $ nonFunctionalNrOfBounds
};
typedef unsigned int MY_ENUM_FLAGS;
MY_ENUM_FLAGS check_and_subs(MY_ENUM_FLAGS x)
{
#define CHECK_AND_SUB(flag) if ((x & flag) == flag) { x -= flag; }
CHECK_AND_SUB(A); // $ nonFunctionalNrOfBounds
CHECK_AND_SUB(B); // $ nonFunctionalNrOfBounds
CHECK_AND_SUB(C); // $ nonFunctionalNrOfBounds
CHECK_AND_SUB(D); // $ nonFunctionalNrOfBounds
CHECK_AND_SUB(E); // $ nonFunctionalNrOfBounds
CHECK_AND_SUB(F); // $ nonFunctionalNrOfBounds
CHECK_AND_SUB(G); // $ nonFunctionalNrOfBounds
// CHECK_AND_SUB(H);
// CHECK_AND_SUB(I);
// CHECK_AND_SUB(J);
// CHECK_AND_SUB(L);
// CHECK_AND_SUB(M);
// CHECK_AND_SUB(N);
// CHECK_AND_SUB(O);
// CHECK_AND_SUB(P);
// CHECK_AND_SUB(Q);
// CHECK_AND_SUB(R);
// CHECK_AND_SUB(S);
// CHECK_AND_SUB(T);
// CHECK_AND_SUB(U);
// CHECK_AND_SUB(V);
// CHECK_AND_SUB(W);
// CHECK_AND_SUB(X);
// CHECK_AND_SUB(Y);
// CHECK_AND_SUB(Z);
// CHECK_AND_SUB(AA);
// CHECK_AND_SUB(AB);
// CHECK_AND_SUB(AC);
// CHECK_AND_SUB(AD);
// CHECK_AND_SUB(AE);
#undef CHECK_AND_SUB
return x; // $ nonFunctionalNrOfBounds
}

View File

@@ -37,6 +37,36 @@ estimateNrOfBounds
| minmax.c:26:37:26:37 | x | 1.0 |
| minmax.c:26:40:26:40 | y | 1.0 |
| minmax.c:26:43:26:43 | z | 2.0 |
| missing_bounds.cpp:40:5:40:19 | ... == ... | 1.0 |
| missing_bounds.cpp:40:5:40:20 | x | 1.0 |
| missing_bounds.cpp:40:5:40:20 | x | 1.0 |
| missing_bounds.cpp:40:19:40:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:40:19:40:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:40:19:40:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:41:5:41:19 | ... == ... | 1.0 |
| missing_bounds.cpp:41:19:41:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:41:19:41:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:41:19:41:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:42:5:42:19 | ... == ... | 1.0 |
| missing_bounds.cpp:42:19:42:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:42:19:42:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:42:19:42:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:43:5:43:19 | ... == ... | 1.0 |
| missing_bounds.cpp:43:19:43:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:43:19:43:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:43:19:43:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:44:5:44:19 | ... == ... | 1.0 |
| missing_bounds.cpp:44:19:44:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:44:19:44:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:44:19:44:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:45:5:45:19 | ... == ... | 1.0 |
| missing_bounds.cpp:45:19:45:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:45:19:45:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:45:19:45:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:46:5:46:19 | ... == ... | 1.0 |
| missing_bounds.cpp:46:19:46:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:46:19:46:19 | (unsigned int)... | 1.0 |
| missing_bounds.cpp:46:19:46:19 | (unsigned int)... | 1.0 |
| test.c:6:14:6:15 | 0 | 1.0 |
| test.c:8:5:8:9 | count | 1.0 |
| test.c:8:5:8:19 | ... = ... | 13.0 |

View File

@@ -12,6 +12,9 @@ query predicate estimateNrOfBounds(Expr e, float nrOfBounds) {
*/
private predicate nonFunctionalNrOfBounds(Expr e) {
strictcount(SimpleRangeAnalysisInternal::estimateNrOfBounds(e)) > 1
or
e.getFile().getBaseName() = "missing_bounds.cpp" and
count(SimpleRangeAnalysisInternal::estimateNrOfBounds(e)) != 1
}
module FunctionalityTest implements TestSig {

View File

@@ -17,6 +17,21 @@
| minmax.c:26:37:26:37 | x | 1 |
| minmax.c:26:40:26:40 | y | 2 |
| minmax.c:26:43:26:43 | z | 1 |
| missing_bounds.cpp:40:5:40:20 | x | 4294967295 |
| missing_bounds.cpp:40:5:40:20 | x | 4294967295 |
| missing_bounds.cpp:41:5:41:20 | x | 4294967295 |
| missing_bounds.cpp:41:5:41:20 | x | 4294967295 |
| missing_bounds.cpp:42:5:42:20 | x | 4294967295 |
| missing_bounds.cpp:42:5:42:20 | x | 4294967295 |
| missing_bounds.cpp:43:5:43:20 | x | 4294967295 |
| missing_bounds.cpp:43:5:43:20 | x | 4294967295 |
| missing_bounds.cpp:44:5:44:20 | x | 4294967295 |
| missing_bounds.cpp:44:5:44:20 | x | 4294967295 |
| missing_bounds.cpp:45:5:45:20 | x | 4294967295 |
| missing_bounds.cpp:45:5:45:20 | x | 4294967295 |
| missing_bounds.cpp:46:5:46:20 | x | 4294967295 |
| missing_bounds.cpp:46:5:46:20 | x | 4294967295 |
| missing_bounds.cpp:72:12:72:12 | x | 4294967295 |
| test.c:8:5:8:9 | count | 2147483647 |
| test.c:8:13:8:17 | count | 2147483647 |
| test.c:10:10:10:14 | count | 2147483647 |