Skip to content

Commit 13cde4d

Browse files
committed
C++: Add testcase demonstrating that a ConstantValue IPA branch representing a gcc case range is a bad idea.
1 parent d10d5fd commit 13cde4d

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

cpp/ql/test/library-tests/controlflow/guards/GuardsCompare.expected

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,3 +1296,15 @@
12961296
| test.cpp:318:7:318:12 | ... < ... | a < 42+0 when ... < ... is true |
12971297
| test.cpp:318:7:318:12 | ... < ... | a >= 42 when ... < ... is false |
12981298
| test.cpp:318:7:318:12 | ... < ... | a >= 42+0 when ... < ... is false |
1299+
| test.cpp:327:46:327:46 | b | b != 0 when b is true |
1300+
| test.cpp:327:46:327:46 | b | b != 1 when b is false |
1301+
| test.cpp:327:46:327:46 | b | b == 0 when b is false |
1302+
| test.cpp:327:46:327:46 | b | b == 1 when b is true |
1303+
| test.cpp:330:7:330:7 | b | b != 0 when b is true |
1304+
| test.cpp:330:7:330:7 | b | b != 1 when b is false |
1305+
| test.cpp:330:7:330:7 | b | b == 0 when b is false |
1306+
| test.cpp:330:7:330:7 | b | b == 1 when b is true |
1307+
| test.cpp:334:11:334:11 | x | x < 51 when x is 40..50 |
1308+
| test.cpp:334:11:334:11 | x | x >= 40 when x is 40..50 |
1309+
| test.cpp:338:9:338:9 | x | x < 51 when x is 40..50 |
1310+
| test.cpp:338:9:338:9 | x | x >= 40 when x is 40..50 |

cpp/ql/test/library-tests/controlflow/guards/GuardsControl.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,9 @@
328328
| test.cpp:318:6:318:18 | ... != ... | true | test.cpp:318:21:320:3 | { ... } |
329329
| test.cpp:318:7:318:12 | ... < ... | 0 | test.cpp:320:10:322:3 | { ... } |
330330
| test.cpp:318:7:318:12 | ... < ... | not 0 | test.cpp:318:21:320:3 | { ... } |
331+
| test.cpp:327:46:327:46 | b | false | test.cpp:336:3:338:7 | case ...: |
332+
| test.cpp:327:46:327:46 | b | true | test.cpp:331:3:332:10 | { ... } |
333+
| test.cpp:329:11:329:13 | call to foo | 40..50 | test.cpp:336:3:338:7 | case ...: |
334+
| test.cpp:330:7:330:7 | b | false | test.cpp:336:3:338:7 | case ...: |
335+
| test.cpp:330:7:330:7 | b | true | test.cpp:331:3:332:10 | { ... } |
336+
| test.cpp:334:11:334:11 | x | 40..50 | test.cpp:336:3:338:7 | case ...: |

cpp/ql/test/library-tests/controlflow/guards/GuardsEnsure.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,3 +1294,13 @@ unary
12941294
| test.cpp:318:6:318:18 | ... != ... | test.cpp:318:7:318:7 | a | >= | 42 | test.cpp:320:10:322:3 | { ... } |
12951295
| test.cpp:318:6:318:18 | ... != ... | test.cpp:318:7:318:12 | ... < ... | != | 0 | test.cpp:318:21:320:3 | { ... } |
12961296
| test.cpp:318:6:318:18 | ... != ... | test.cpp:318:7:318:12 | ... < ... | == | 0 | test.cpp:320:10:322:3 | { ... } |
1297+
| test.cpp:327:46:327:46 | b | test.cpp:330:7:330:7 | b | != | 0 | test.cpp:331:3:332:10 | { ... } |
1298+
| test.cpp:327:46:327:46 | b | test.cpp:330:7:330:7 | b | != | 1 | test.cpp:336:3:338:7 | case ...: |
1299+
| test.cpp:327:46:327:46 | b | test.cpp:330:7:330:7 | b | == | 0 | test.cpp:336:3:338:7 | case ...: |
1300+
| test.cpp:327:46:327:46 | b | test.cpp:330:7:330:7 | b | == | 1 | test.cpp:331:3:332:10 | { ... } |
1301+
| test.cpp:330:7:330:7 | b | test.cpp:330:7:330:7 | b | != | 0 | test.cpp:331:3:332:10 | { ... } |
1302+
| test.cpp:330:7:330:7 | b | test.cpp:330:7:330:7 | b | != | 1 | test.cpp:336:3:338:7 | case ...: |
1303+
| test.cpp:330:7:330:7 | b | test.cpp:330:7:330:7 | b | == | 0 | test.cpp:336:3:338:7 | case ...: |
1304+
| test.cpp:330:7:330:7 | b | test.cpp:330:7:330:7 | b | == | 1 | test.cpp:331:3:332:10 | { ... } |
1305+
| test.cpp:334:11:334:11 | x | test.cpp:334:11:334:11 | x | < | 51 | test.cpp:336:3:338:7 | case ...: |
1306+
| test.cpp:334:11:334:11 | x | test.cpp:334:11:334:11 | x | >= | 40 | test.cpp:336:3:338:7 | case ...: |

cpp/ql/test/library-tests/controlflow/guards/test.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,21 @@ void test_cmp_implies_unary(int a) {
320320
} else {
321321

322322
}
323+
}
324+
325+
int foo();
326+
327+
void test_constant_value_and_case_range(bool b)
328+
{
329+
int x = foo();
330+
if (b)
331+
{
332+
x = 42;
333+
}
334+
switch (x)
335+
{
336+
case 40 ... 50:
337+
// should not be guarded by `foo() = 40..50`
338+
use(x);
339+
}
323340
}

0 commit comments

Comments
 (0)