C++: SimpleRangeAnalysis for *= by constant

This commit is contained in:
Jonas Jensen
2020-08-18 14:17:42 +02:00
parent b6b72729f6
commit b316644ac2
4 changed files with 108 additions and 10 deletions

View File

@@ -519,9 +519,9 @@
| test.c:513:9:513:9 | i | -5 |
| test.c:514:9:514:9 | i | -30 |
| test.c:516:5:516:5 | i | -30 |
| test.c:517:9:517:9 | i | -2147483648 |
| test.c:519:5:519:5 | i | -2147483648 |
| test.c:520:9:520:9 | i | -2147483648 |
| test.c:517:9:517:9 | i | -210 |
| test.c:519:5:519:5 | i | -210 |
| test.c:520:9:520:9 | i | -1155 |
| test.c:522:7:522:7 | i | -2147483648 |
| test.c:523:5:523:5 | i | -2147483648 |
| test.c:523:9:523:9 | i | -1 |
@@ -529,6 +529,9 @@
| test.c:526:3:526:3 | i | -2147483648 |
| test.c:526:7:526:7 | i | -2147483648 |
| test.c:527:10:527:10 | i | -2147483648 |
| test.c:530:3:530:3 | i | -2147483648 |
| test.c:530:10:530:11 | sc | 1 |
| test.c:532:7:532:7 | i | -128 |
| test.cpp:10:7:10:7 | b | -2147483648 |
| test.cpp:11:5:11:5 | x | -2147483648 |
| test.cpp:13:10:13:10 | x | -2147483648 |

View File

@@ -514,15 +514,22 @@ int mul_by_constant(int i, int j) {
out(i); // -30 .. 15
i *= 7;
out(i); // -210 .. 105 [BUG: not supported]
out(i); // -210 .. 105
i *= -11;
out(i); // -1155 .. 2310 [BUG: not supported]
out(i); // -1155 .. 2310
}
if (i == -1) {
i = i * (int)0xffFFffFF; // fully converted literal is -1
out(i); // 1 .. 1
}
i = i * -1;
return i; // -2^31 .. 2^31-1
out( i); // -2^31 .. 2^31-1
signed char sc = 1;
i = (*&sc *= 2);
out(sc); // demonstrate that we couldn't analyze the LHS of the `*=` above...
out(i); // -128 .. 127 // ... but we can still bound its result by its type.
return 0;
}

View File

@@ -519,9 +519,9 @@
| test.c:513:9:513:9 | i | 10 |
| test.c:514:9:514:9 | i | 15 |
| test.c:516:5:516:5 | i | 15 |
| test.c:517:9:517:9 | i | 2147483647 |
| test.c:519:5:519:5 | i | 2147483647 |
| test.c:520:9:520:9 | i | 2147483647 |
| test.c:517:9:517:9 | i | 105 |
| test.c:519:5:519:5 | i | 105 |
| test.c:520:9:520:9 | i | 2310 |
| test.c:522:7:522:7 | i | 2147483647 |
| test.c:523:5:523:5 | i | 2147483647 |
| test.c:523:9:523:9 | i | -1 |
@@ -529,6 +529,9 @@
| test.c:526:3:526:3 | i | 2147483647 |
| test.c:526:7:526:7 | i | 2147483647 |
| test.c:527:10:527:10 | i | 2147483647 |
| test.c:530:3:530:3 | i | 2147483647 |
| test.c:530:10:530:11 | sc | 1 |
| test.c:532:7:532:7 | i | 127 |
| test.cpp:10:7:10:7 | b | 2147483647 |
| test.cpp:11:5:11:5 | x | 2147483647 |
| test.cpp:13:10:13:10 | x | 2147483647 |