mirror of
https://github.com/github/codeql.git
synced 2026-05-01 11:45:14 +02:00
C++: RangeAnalysis tests for bool conversions
This commit is contained in:
@@ -563,6 +563,25 @@
|
||||
| test.c:601:7:601:7 | n | -32768 |
|
||||
| test.c:601:22:601:22 | n | -32767 |
|
||||
| test.c:602:9:602:9 | n | -32766 |
|
||||
| test.c:605:7:605:7 | n | -32768 |
|
||||
| test.c:606:5:606:5 | n | 0 |
|
||||
| test.c:606:10:606:10 | n | 0 |
|
||||
| test.c:606:14:606:14 | n | 0 |
|
||||
| test.c:607:6:607:6 | n | 0 |
|
||||
| test.c:607:10:607:10 | n | 0 |
|
||||
| test.c:607:14:607:14 | n | 0 |
|
||||
| test.c:618:7:618:8 | ss | -32768 |
|
||||
| test.c:619:9:619:10 | ss | 0 |
|
||||
| test.c:622:7:622:8 | ss | -32768 |
|
||||
| test.c:623:9:623:10 | ss | -32768 |
|
||||
| test.c:626:14:626:15 | us | 0 |
|
||||
| test.c:627:9:627:10 | us | 0 |
|
||||
| test.c:630:14:630:15 | us | 0 |
|
||||
| test.c:631:9:631:10 | us | 0 |
|
||||
| test.c:634:7:634:8 | ss | -32768 |
|
||||
| test.c:635:9:635:10 | ss | -32768 |
|
||||
| test.c:638:7:638:8 | ss | -32768 |
|
||||
| test.c:639:9:639:10 | ss | -1 |
|
||||
| test.cpp:10:7:10:7 | b | -2147483648 |
|
||||
| test.cpp:11:5:11:5 | x | -2147483648 |
|
||||
| test.cpp:13:10:13:10 | x | -2147483648 |
|
||||
@@ -616,3 +635,16 @@
|
||||
| test.cpp:97:10:97:10 | i | -2147483648 |
|
||||
| test.cpp:97:22:97:22 | i | -2147483648 |
|
||||
| test.cpp:98:5:98:5 | i | -2147483648 |
|
||||
| test.cpp:105:7:105:7 | n | -32768 |
|
||||
| test.cpp:108:7:108:7 | n | 0 |
|
||||
| test.cpp:109:5:109:5 | n | 0 |
|
||||
| test.cpp:111:5:111:5 | n | 0 |
|
||||
| test.cpp:114:8:114:8 | n | 0 |
|
||||
| test.cpp:115:5:115:5 | n | 0 |
|
||||
| test.cpp:117:5:117:5 | n | 0 |
|
||||
| test.cpp:120:3:120:3 | n | 0 |
|
||||
| test.cpp:120:8:120:8 | n | 0 |
|
||||
| test.cpp:120:12:120:12 | n | 0 |
|
||||
| test.cpp:121:4:121:4 | n | 0 |
|
||||
| test.cpp:121:8:121:8 | n | 0 |
|
||||
| test.cpp:121:12:121:12 | n | 0 |
|
||||
|
||||
@@ -13,3 +13,7 @@
|
||||
| test.c:386:10:386:21 | ... ? ... : ... | 100.0 | 100.0 | 5.0 |
|
||||
| test.c:387:10:387:38 | ... ? ... : ... | 0.0 | 100.0 | 5.0 |
|
||||
| test.c:394:20:394:36 | ... ? ... : ... | 0.0 | 0.0 | 100.0 |
|
||||
| test.c:606:5:606:14 | ... ? ... : ... | 0.0 | 0.0 | 0.0 |
|
||||
| test.c:607:5:607:14 | ... ? ... : ... | 0.0 | 0.0 | 0.0 |
|
||||
| test.cpp:120:3:120:12 | ... ? ... : ... | 0.0 | 0.0 | 0.0 |
|
||||
| test.cpp:121:3:121:12 | ... ? ... : ... | 0.0 | 0.0 | 0.0 |
|
||||
|
||||
@@ -13,3 +13,7 @@
|
||||
| test.c:386:10:386:21 | ... ? ... : ... | 4.294967295E9 | 4.294967295E9 | 5.0 |
|
||||
| test.c:387:10:387:38 | ... ? ... : ... | 255.0 | 4.294967295E9 | 5.0 |
|
||||
| test.c:394:20:394:36 | ... ? ... : ... | 100.0 | 99.0 | 100.0 |
|
||||
| test.c:606:5:606:14 | ... ? ... : ... | 32767.0 | 32767.0 | 32767.0 |
|
||||
| test.c:607:5:607:14 | ... ? ... : ... | 32767.0 | 32767.0 | 32767.0 |
|
||||
| test.cpp:120:3:120:12 | ... ? ... : ... | 32767.0 | 32767.0 | 32767.0 |
|
||||
| test.cpp:121:3:121:12 | ... ? ... : ... | 32767.0 | 32767.0 | 32767.0 |
|
||||
|
||||
@@ -549,7 +549,7 @@ int notequal_type_endpoint(unsigned n) {
|
||||
}
|
||||
|
||||
if (!n) {
|
||||
out(n); // 0 .. 0
|
||||
out(n); // 0 .. 0 [BUG: upper bound is deduced to be 2^32-1]
|
||||
} else {
|
||||
out(n); // 1 .. [BUG: lower bound is deduced to be 0]
|
||||
}
|
||||
@@ -574,7 +574,7 @@ void notequal_refinement(short n) {
|
||||
if (n) {
|
||||
out(n); // 1 .. [BUG: lower bound is deduced to be 0]
|
||||
} else {
|
||||
out(n); // 0 .. 0
|
||||
out(n); // 0 .. 0 [BUG: upper bound is deduced to be 32767]
|
||||
}
|
||||
|
||||
while (n != 0) {
|
||||
@@ -601,4 +601,41 @@ void notequal_variations(short n, float f) {
|
||||
if (n != -32768 && n != -32767) {
|
||||
out(n); // -32766 ..
|
||||
}
|
||||
|
||||
if (n >= 0) {
|
||||
n ? n : n; // ? 1.. : 0..0 [BUG: no useful bounds]
|
||||
!n ? n : n; // ? 0..0 : 1.. [BUG: no useful bounds]
|
||||
}
|
||||
}
|
||||
|
||||
void two_bounds_from_one_test(short ss, unsigned short us) {
|
||||
// These tests demonstrate how the range analysis is often able to deduce
|
||||
// both an upper bound and a lower bound even when there is only one
|
||||
// inequality in the source. For example `signedInt < 4U` establishes that
|
||||
// `signedInt >= 0` since if `signedInt` were negative then it would be
|
||||
// greater than 4 in the unsigned comparison.
|
||||
|
||||
if (ss < sizeof(int)) { // Lower bound added in `linearBoundFromGuard`
|
||||
out(ss); // 0 .. 3
|
||||
}
|
||||
|
||||
if (ss < 0x8001) { // Lower bound removed in `getDefLowerBounds`
|
||||
out(ss); // -32768 .. 32767
|
||||
}
|
||||
|
||||
if ((short)us >= 0) {
|
||||
out(us); // 0 .. 32767
|
||||
}
|
||||
|
||||
if ((short)us >= -1) {
|
||||
out(us); // 0 .. 65535
|
||||
}
|
||||
|
||||
if (ss >= sizeof(int)) { // test is true for negative numbers
|
||||
out(ss); // -32768 .. 32767
|
||||
}
|
||||
|
||||
if (ss + 1 < sizeof(int)) {
|
||||
out(ss); // -1 .. 2
|
||||
}
|
||||
}
|
||||
@@ -100,3 +100,23 @@ int ref_to_number(int &i, const int &ci, int &aliased) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void notequal_refinement(short n) {
|
||||
if (n < 0)
|
||||
return;
|
||||
|
||||
if (n) {
|
||||
n; // 1 .. [BUG: lower bound is deduced to be 0]
|
||||
} else {
|
||||
n; // 0 .. 0 [BUG: upper bound is deduced to be 32767]
|
||||
}
|
||||
|
||||
if (!n) {
|
||||
n; // 0 .. 0 [BUG: upper bound is deduced to be 32767]
|
||||
} else {
|
||||
n; // 1 .. [BUG: lower bound is deduced to be 0]
|
||||
}
|
||||
|
||||
n ? n : n; // ? 1.. : 0..0 [BUG: no useful bounds]
|
||||
!n ? n : n; // ? 0..0 : 1.. [BUG: no useful bounds]
|
||||
}
|
||||
|
||||
@@ -563,6 +563,25 @@
|
||||
| test.c:601:7:601:7 | n | 32767 |
|
||||
| test.c:601:22:601:22 | n | 32767 |
|
||||
| test.c:602:9:602:9 | n | 32767 |
|
||||
| test.c:605:7:605:7 | n | 32767 |
|
||||
| test.c:606:5:606:5 | n | 32767 |
|
||||
| test.c:606:10:606:10 | n | 32767 |
|
||||
| test.c:606:14:606:14 | n | 32767 |
|
||||
| test.c:607:6:607:6 | n | 32767 |
|
||||
| test.c:607:10:607:10 | n | 32767 |
|
||||
| test.c:607:14:607:14 | n | 32767 |
|
||||
| test.c:618:7:618:8 | ss | 32767 |
|
||||
| test.c:619:9:619:10 | ss | 3 |
|
||||
| test.c:622:7:622:8 | ss | 32767 |
|
||||
| test.c:623:9:623:10 | ss | 32767 |
|
||||
| test.c:626:14:626:15 | us | 65535 |
|
||||
| test.c:627:9:627:10 | us | 32767 |
|
||||
| test.c:630:14:630:15 | us | 65535 |
|
||||
| test.c:631:9:631:10 | us | 65535 |
|
||||
| test.c:634:7:634:8 | ss | 32767 |
|
||||
| test.c:635:9:635:10 | ss | 32767 |
|
||||
| test.c:638:7:638:8 | ss | 32767 |
|
||||
| test.c:639:9:639:10 | ss | 2 |
|
||||
| test.cpp:10:7:10:7 | b | 2147483647 |
|
||||
| test.cpp:11:5:11:5 | x | 2147483647 |
|
||||
| test.cpp:13:10:13:10 | x | 2147483647 |
|
||||
@@ -616,3 +635,16 @@
|
||||
| test.cpp:97:10:97:10 | i | 65535 |
|
||||
| test.cpp:97:22:97:22 | i | 32767 |
|
||||
| test.cpp:98:5:98:5 | i | 32767 |
|
||||
| test.cpp:105:7:105:7 | n | 32767 |
|
||||
| test.cpp:108:7:108:7 | n | 32767 |
|
||||
| test.cpp:109:5:109:5 | n | 32767 |
|
||||
| test.cpp:111:5:111:5 | n | 32767 |
|
||||
| test.cpp:114:8:114:8 | n | 32767 |
|
||||
| test.cpp:115:5:115:5 | n | 32767 |
|
||||
| test.cpp:117:5:117:5 | n | 32767 |
|
||||
| test.cpp:120:3:120:3 | n | 32767 |
|
||||
| test.cpp:120:8:120:8 | n | 32767 |
|
||||
| test.cpp:120:12:120:12 | n | 32767 |
|
||||
| test.cpp:121:4:121:4 | n | 32767 |
|
||||
| test.cpp:121:8:121:8 | n | 32767 |
|
||||
| test.cpp:121:12:121:12 | n | 32767 |
|
||||
|
||||
Reference in New Issue
Block a user