Skip to content

Commit d849615

Browse files
committed
C++: Add IRGuards test that shows that ternary behaviour is not quite correct
1 parent 6dd941e commit d849615

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,10 @@ int ptr_test(int *x, int *y) {
167167

168168
return 0;
169169
}
170+
171+
int foo(const char*, int);
172+
173+
int ternary_test(const char *path, int mode)
174+
{
175+
return (foo(path, mode) == 0 ? 1 : 0);
176+
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ astGuards
3434
| test.c:159:9:159:19 | ... == ... |
3535
| test.c:162:9:162:18 | ... < ... |
3636
| test.c:165:9:165:18 | ... < ... |
37+
| test.c:175:13:175:32 | ... == ... |
3738
| test.cpp:18:8:18:10 | call to get |
3839
| test.cpp:31:7:31:13 | ... == ... |
3940
| test.cpp:42:13:42:20 | call to getABool |
@@ -158,6 +159,10 @@ astGuardsCompare
158159
| 165 | x >= y+-42 when ... < ... is false |
159160
| 165 | y < x+43 when ... < ... is false |
160161
| 165 | y >= x+43 when ... < ... is true |
162+
| 175 | 0 != call to foo+0 when ... == ... is false |
163+
| 175 | 0 == call to foo+0 when ... == ... is true |
164+
| 175 | call to foo != 0+0 when ... == ... is false |
165+
| 175 | call to foo == 0+0 when ... == ... is true |
161166
astGuardsControl
162167
| test.c:7:9:7:13 | ... > ... | false | 10 | 11 |
163168
| test.c:7:9:7:13 | ... > ... | true | 7 | 9 |
@@ -248,6 +253,10 @@ astGuardsControl
248253
| test.c:159:9:159:19 | ... == ... | true | 159 | 160 |
249254
| test.c:162:9:162:18 | ... < ... | true | 162 | 163 |
250255
| test.c:165:9:165:18 | ... < ... | true | 165 | 166 |
256+
| test.c:175:13:175:32 | ... == ... | false | 174 | 175 |
257+
| test.c:175:13:175:32 | ... == ... | false | 175 | 175 |
258+
| test.c:175:13:175:32 | ... == ... | true | 174 | 175 |
259+
| test.c:175:13:175:32 | ... == ... | true | 175 | 175 |
251260
| test.cpp:18:8:18:10 | call to get | true | 19 | 19 |
252261
| test.cpp:31:7:31:13 | ... == ... | false | 30 | 30 |
253262
| test.cpp:31:7:31:13 | ... == ... | false | 34 | 34 |
@@ -420,6 +429,14 @@ astGuardsEnsure
420429
| test.c:165:9:165:18 | ... < ... | test.c:165:9:165:9 | x | < | test.c:165:13:165:18 | ... - ... | 0 | 165 | 166 |
421430
| test.c:165:9:165:18 | ... < ... | test.c:165:13:165:13 | y | >= | test.c:165:9:165:9 | x | 43 | 165 | 166 |
422431
| test.c:165:9:165:18 | ... < ... | test.c:165:13:165:18 | ... - ... | >= | test.c:165:9:165:9 | x | 1 | 165 | 166 |
432+
| test.c:175:13:175:32 | ... == ... | test.c:175:13:175:15 | call to foo | != | test.c:175:32:175:32 | 0 | 0 | 174 | 175 |
433+
| test.c:175:13:175:32 | ... == ... | test.c:175:13:175:15 | call to foo | != | test.c:175:32:175:32 | 0 | 0 | 175 | 175 |
434+
| test.c:175:13:175:32 | ... == ... | test.c:175:13:175:15 | call to foo | == | test.c:175:32:175:32 | 0 | 0 | 174 | 175 |
435+
| test.c:175:13:175:32 | ... == ... | test.c:175:13:175:15 | call to foo | == | test.c:175:32:175:32 | 0 | 0 | 175 | 175 |
436+
| test.c:175:13:175:32 | ... == ... | test.c:175:32:175:32 | 0 | != | test.c:175:13:175:15 | call to foo | 0 | 174 | 175 |
437+
| test.c:175:13:175:32 | ... == ... | test.c:175:32:175:32 | 0 | != | test.c:175:13:175:15 | call to foo | 0 | 175 | 175 |
438+
| test.c:175:13:175:32 | ... == ... | test.c:175:32:175:32 | 0 | == | test.c:175:13:175:15 | call to foo | 0 | 174 | 175 |
439+
| test.c:175:13:175:32 | ... == ... | test.c:175:32:175:32 | 0 | == | test.c:175:13:175:15 | call to foo | 0 | 175 | 175 |
423440
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | test.cpp:31:12:31:13 | - ... | 0 | 30 | 30 |
424441
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | test.cpp:31:12:31:13 | - ... | 0 | 34 | 34 |
425442
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | == | test.cpp:31:12:31:13 | - ... | 0 | 30 | 30 |
@@ -458,6 +475,7 @@ irGuards
458475
| test.c:159:9:159:19 | CompareEQ: ... == ... |
459476
| test.c:162:9:162:18 | CompareLT: ... < ... |
460477
| test.c:165:9:165:18 | CompareLT: ... < ... |
478+
| test.c:175:13:175:32 | CompareEQ: ... == ... |
461479
| test.cpp:18:8:18:12 | CompareNE: (bool)... |
462480
| test.cpp:31:7:31:13 | CompareEQ: ... == ... |
463481
| test.cpp:42:13:42:20 | Call: call to getABool |
@@ -566,6 +584,10 @@ irGuardsCompare
566584
| 165 | x >= y+-42 when CompareLT: ... < ... is false |
567585
| 165 | y < x+43 when CompareLT: ... < ... is false |
568586
| 165 | y >= x+43 when CompareLT: ... < ... is true |
587+
| 175 | 0 != call to foo+0 when CompareEQ: ... == ... is false |
588+
| 175 | 0 == call to foo+0 when CompareEQ: ... == ... is true |
589+
| 175 | call to foo != 0+0 when CompareEQ: ... == ... is false |
590+
| 175 | call to foo == 0+0 when CompareEQ: ... == ... is true |
569591
irGuardsControl
570592
| test.c:7:9:7:13 | CompareGT: ... > ... | false | 11 | 11 |
571593
| test.c:7:9:7:13 | CompareGT: ... > ... | true | 8 | 8 |
@@ -649,6 +671,8 @@ irGuardsControl
649671
| test.c:159:9:159:19 | CompareEQ: ... == ... | true | 159 | 160 |
650672
| test.c:162:9:162:18 | CompareLT: ... < ... | true | 162 | 163 |
651673
| test.c:165:9:165:18 | CompareLT: ... < ... | true | 165 | 166 |
674+
| test.c:175:13:175:32 | CompareEQ: ... == ... | false | 175 | 175 |
675+
| test.c:175:13:175:32 | CompareEQ: ... == ... | true | 175 | 175 |
652676
| test.cpp:18:8:18:12 | CompareNE: (bool)... | true | 19 | 19 |
653677
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | false | 34 | 34 |
654678
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | true | 30 | 30 |
@@ -804,6 +828,10 @@ irGuardsEnsure
804828
| test.c:165:9:165:18 | CompareLT: ... < ... | test.c:165:9:165:9 | Load: x | < | test.c:165:13:165:18 | PointerSub: ... - ... | 0 | 165 | 166 |
805829
| test.c:165:9:165:18 | CompareLT: ... < ... | test.c:165:13:165:13 | Load: y | >= | test.c:165:9:165:9 | Load: x | 43 | 165 | 166 |
806830
| test.c:165:9:165:18 | CompareLT: ... < ... | test.c:165:13:165:18 | PointerSub: ... - ... | >= | test.c:165:9:165:9 | Load: x | 1 | 165 | 166 |
831+
| test.c:175:13:175:32 | CompareEQ: ... == ... | test.c:175:13:175:15 | Call: call to foo | != | test.c:175:32:175:32 | Constant: 0 | 0 | 175 | 175 |
832+
| test.c:175:13:175:32 | CompareEQ: ... == ... | test.c:175:13:175:15 | Call: call to foo | == | test.c:175:32:175:32 | Constant: 0 | 0 | 175 | 175 |
833+
| test.c:175:13:175:32 | CompareEQ: ... == ... | test.c:175:32:175:32 | Constant: 0 | != | test.c:175:13:175:15 | Call: call to foo | 0 | 175 | 175 |
834+
| test.c:175:13:175:32 | CompareEQ: ... == ... | test.c:175:32:175:32 | Constant: 0 | == | test.c:175:13:175:15 | Call: call to foo | 0 | 175 | 175 |
807835
| test.cpp:18:8:18:12 | CompareNE: (bool)... | test.cpp:18:8:18:10 | Call: call to get | != | test.cpp:18:8:18:12 | Constant: (bool)... | 0 | 19 | 19 |
808836
| test.cpp:18:8:18:12 | CompareNE: (bool)... | test.cpp:18:8:18:12 | Constant: (bool)... | != | test.cpp:18:8:18:10 | Call: call to get | 0 | 19 | 19 |
809837
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | test.cpp:31:7:31:7 | Load: x | != | test.cpp:31:12:31:13 | Constant: - ... | 0 | 34 | 34 |

0 commit comments

Comments
 (0)