Skip to content

Commit 54faba2

Browse files
committed
C++: Add more tests.
1 parent 00a1978 commit 54faba2

File tree

6 files changed

+146
-0
lines changed

6 files changed

+146
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
| test.c:170:9:170:9 | s |
3535
| test.c:176:8:176:15 | ! ... |
3636
| test.c:176:10:176:14 | ... < ... |
37+
| test.c:182:8:182:34 | ! ... |
38+
| test.c:182:10:182:20 | ... >= ... |
39+
| test.c:182:10:182:33 | ... && ... |
40+
| test.c:182:25:182:33 | ... < ... |
3741
| test.cpp:18:8:18:10 | call to get |
3842
| test.cpp:31:7:31:13 | ... == ... |
3943
| test.cpp:42:13:42:20 | call to getABool |
@@ -51,3 +55,5 @@
5155
| test.cpp:135:6:135:21 | call to __builtin_expect |
5256
| test.cpp:141:6:141:21 | call to __builtin_expect |
5357
| test.cpp:145:6:145:21 | call to __builtin_expect |
58+
| test.cpp:152:7:152:8 | ! ... |
59+
| test.cpp:152:8:152:8 | b |

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,42 @@
349349
| 146 | x != 0 when x is true |
350350
| 146 | x == 0 when ! ... is true |
351351
| 146 | x == 0 when x is false |
352+
| 152 | 10 < a+1 when ! ... is true |
353+
| 152 | 10 < a+1 when b is false |
354+
| 152 | 10 >= a+1 when ! ... is false |
355+
| 152 | 10 >= a+1 when b is true |
356+
| 152 | ! ... != 0 when ! ... is true |
357+
| 152 | ! ... != 0 when b is false |
358+
| 152 | ! ... != 1 when ! ... is false |
359+
| 152 | ! ... != 1 when b is true |
360+
| 152 | ! ... == 0 when ! ... is false |
361+
| 152 | ! ... == 0 when b is true |
362+
| 152 | ! ... == 1 when ! ... is true |
363+
| 152 | ! ... == 1 when b is false |
364+
| 152 | ... < ... != 0 when ! ... is false |
365+
| 152 | ... < ... != 0 when b is true |
366+
| 152 | ... < ... != 1 when ! ... is true |
367+
| 152 | ... < ... != 1 when b is false |
368+
| 152 | ... < ... == 0 when ! ... is true |
369+
| 152 | ... < ... == 0 when b is false |
370+
| 152 | ... < ... == 1 when ! ... is false |
371+
| 152 | ... < ... == 1 when b is true |
372+
| 152 | a < 10 when ! ... is false |
373+
| 152 | a < 10 when b is true |
374+
| 152 | a < 10+0 when ! ... is false |
375+
| 152 | a < 10+0 when b is true |
376+
| 152 | a >= 10 when ! ... is true |
377+
| 152 | a >= 10 when b is false |
378+
| 152 | a >= 10+0 when ! ... is true |
379+
| 152 | a >= 10+0 when b is false |
380+
| 152 | b != 0 when ! ... is false |
381+
| 152 | b != 0 when b is true |
382+
| 152 | b != 1 when ! ... is true |
383+
| 152 | b != 1 when b is false |
384+
| 152 | b == 0 when ! ... is true |
385+
| 152 | b == 0 when b is false |
386+
| 152 | b == 1 when ! ... is false |
387+
| 152 | b == 1 when b is true |
352388
| 152 | p != 0 when p is true |
353389
| 152 | p != 1 when p is false |
354390
| 152 | p == 0 when p is false |
@@ -393,3 +429,39 @@
393429
| 176 | ... < ... != 0 when ... < ... is true |
394430
| 176 | ... < ... == 0 when ! ... is true |
395431
| 176 | ... < ... == 0 when ... < ... is false |
432+
| 182 | 1.0 < foo+1 when ... < ... is false |
433+
| 182 | 1.0 >= foo+1 when ... && ... is true |
434+
| 182 | 1.0 >= foo+1 when ... < ... is true |
435+
| 182 | 9.999999999999999547e-07 < foo+1 when ... && ... is true |
436+
| 182 | 9.999999999999999547e-07 < foo+1 when ... >= ... is true |
437+
| 182 | 9.999999999999999547e-07 >= foo+1 when ... >= ... is false |
438+
| 182 | ! ... != 0 when ! ... is true |
439+
| 182 | ! ... != 0 when ... && ... is false |
440+
| 182 | ! ... != 1 when ! ... is false |
441+
| 182 | ! ... != 1 when ... && ... is true |
442+
| 182 | ! ... == 0 when ! ... is false |
443+
| 182 | ! ... == 0 when ... && ... is true |
444+
| 182 | ! ... == 1 when ! ... is true |
445+
| 182 | ! ... == 1 when ... && ... is false |
446+
| 182 | ... && ... != 0 when ! ... is false |
447+
| 182 | ... && ... != 0 when ... && ... is true |
448+
| 182 | ... && ... == 0 when ! ... is true |
449+
| 182 | ... && ... == 0 when ... && ... is false |
450+
| 182 | ... < ... != 0 when ... && ... is true |
451+
| 182 | ... < ... != 0 when ... < ... is true |
452+
| 182 | ... < ... != 1 when ... < ... is false |
453+
| 182 | ... < ... == 0 when ... < ... is false |
454+
| 182 | ... < ... == 1 when ... && ... is true |
455+
| 182 | ... < ... == 1 when ... < ... is true |
456+
| 182 | ... >= ... != 0 when ... && ... is true |
457+
| 182 | ... >= ... != 0 when ... >= ... is true |
458+
| 182 | ... >= ... != 1 when ... >= ... is false |
459+
| 182 | ... >= ... == 0 when ... >= ... is false |
460+
| 182 | ... >= ... == 1 when ... && ... is true |
461+
| 182 | ... >= ... == 1 when ... >= ... is true |
462+
| 182 | foo < 1.0+0 when ... && ... is true |
463+
| 182 | foo < 1.0+0 when ... < ... is true |
464+
| 182 | foo < 9.999999999999999547e-07+0 when ... >= ... is false |
465+
| 182 | foo >= 1.0+0 when ... < ... is false |
466+
| 182 | foo >= 9.999999999999999547e-07+0 when ... && ... is true |
467+
| 182 | foo >= 9.999999999999999547e-07+0 when ... >= ... is true |

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@
8787
| test.c:170:9:170:9 | s | false | 170 | 172 |
8888
| test.c:176:8:176:15 | ! ... | true | 176 | 178 |
8989
| test.c:176:10:176:14 | ... < ... | false | 176 | 178 |
90+
| test.c:182:8:182:34 | ! ... | true | 182 | 184 |
91+
| test.c:182:10:182:20 | ... >= ... | true | 181 | 182 |
92+
| test.c:182:10:182:20 | ... >= ... | true | 182 | 182 |
93+
| test.c:182:10:182:33 | ... && ... | false | 182 | 184 |
94+
| test.c:182:10:182:33 | ... && ... | true | 181 | 182 |
95+
| test.c:182:25:182:33 | ... < ... | true | 181 | 182 |
9096
| test.cpp:18:8:18:10 | call to get | true | 19 | 19 |
9197
| test.cpp:31:7:31:13 | ... == ... | false | 30 | 30 |
9298
| test.cpp:31:7:31:13 | ... == ... | false | 34 | 34 |
@@ -110,3 +116,5 @@
110116
| test.cpp:135:6:135:21 | call to __builtin_expect | true | 135 | 136 |
111117
| test.cpp:141:6:141:21 | call to __builtin_expect | true | 141 | 142 |
112118
| test.cpp:145:6:145:21 | call to __builtin_expect | true | 145 | 146 |
119+
| test.cpp:152:7:152:8 | ! ... | true | 152 | 153 |
120+
| test.cpp:152:8:152:8 | b | false | 152 | 153 |

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ binary
157157
| test.c:109:9:109:23 | ... \|\| ... | test.c:109:23:109:23 | 0 | < | test.c:109:19:109:19 | y | 1 | 113 | 113 |
158158
| test.c:109:19:109:23 | ... < ... | test.c:109:19:109:19 | y | >= | test.c:109:23:109:23 | 0 | 0 | 113 | 113 |
159159
| test.c:109:19:109:23 | ... < ... | test.c:109:23:109:23 | 0 | < | test.c:109:19:109:19 | y | 1 | 113 | 113 |
160+
| test.c:182:10:182:20 | ... >= ... | test.c:182:10:182:12 | foo | >= | test.c:182:17:182:20 | 9.999999999999999547e-07 | 0 | 181 | 182 |
161+
| test.c:182:10:182:20 | ... >= ... | test.c:182:10:182:12 | foo | >= | test.c:182:17:182:20 | 9.999999999999999547e-07 | 0 | 182 | 182 |
162+
| test.c:182:10:182:20 | ... >= ... | test.c:182:17:182:20 | 9.999999999999999547e-07 | < | test.c:182:10:182:12 | foo | 1 | 181 | 182 |
163+
| test.c:182:10:182:20 | ... >= ... | test.c:182:17:182:20 | 9.999999999999999547e-07 | < | test.c:182:10:182:12 | foo | 1 | 182 | 182 |
164+
| test.c:182:10:182:33 | ... && ... | test.c:182:10:182:12 | foo | >= | test.c:182:17:182:20 | 9.999999999999999547e-07 | 0 | 181 | 182 |
165+
| test.c:182:10:182:33 | ... && ... | test.c:182:17:182:20 | 9.999999999999999547e-07 | < | test.c:182:10:182:12 | foo | 1 | 181 | 182 |
166+
| test.c:182:10:182:33 | ... && ... | test.c:182:25:182:27 | foo | < | test.c:182:31:182:33 | 1.0 | 0 | 181 | 182 |
167+
| test.c:182:10:182:33 | ... && ... | test.c:182:31:182:33 | 1.0 | >= | test.c:182:25:182:27 | foo | 1 | 181 | 182 |
168+
| test.c:182:25:182:33 | ... < ... | test.c:182:25:182:27 | foo | < | test.c:182:31:182:33 | 1.0 | 0 | 181 | 182 |
169+
| test.c:182:25:182:33 | ... < ... | test.c:182:31:182:33 | 1.0 | >= | test.c:182:25:182:27 | foo | 1 | 181 | 182 |
160170
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | test.cpp:31:12:31:13 | - ... | 0 | 30 | 30 |
161171
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | test.cpp:31:12:31:13 | - ... | 0 | 34 | 34 |
162172
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | == | test.cpp:31:12:31:13 | - ... | 0 | 30 | 30 |
@@ -181,6 +191,10 @@ binary
181191
| test.cpp:141:6:141:21 | call to __builtin_expect | test.cpp:141:28:141:29 | 42 | == | test.cpp:141:23:141:23 | a | 0 | 141 | 142 |
182192
| test.cpp:145:6:145:21 | call to __builtin_expect | test.cpp:145:23:145:23 | a | != | test.cpp:145:28:145:29 | 42 | 0 | 145 | 146 |
183193
| test.cpp:145:6:145:21 | call to __builtin_expect | test.cpp:145:28:145:29 | 42 | != | test.cpp:145:23:145:23 | a | 0 | 145 | 146 |
194+
| test.cpp:152:7:152:8 | ! ... | test.cpp:151:8:151:8 | a | >= | test.cpp:151:12:151:13 | 10 | 0 | 152 | 153 |
195+
| test.cpp:152:7:152:8 | ! ... | test.cpp:151:12:151:13 | 10 | < | test.cpp:151:8:151:8 | a | 1 | 152 | 153 |
196+
| test.cpp:152:8:152:8 | b | test.cpp:151:8:151:8 | a | >= | test.cpp:151:12:151:13 | 10 | 0 | 152 | 153 |
197+
| test.cpp:152:8:152:8 | b | test.cpp:151:12:151:13 | 10 | < | test.cpp:151:8:151:8 | a | 1 | 152 | 153 |
184198
unary
185199
| test.c:7:9:7:13 | ... > ... | test.c:7:9:7:9 | x | < | 1 | 10 | 11 |
186200
| test.c:7:9:7:13 | ... > ... | test.c:7:9:7:9 | x | >= | 1 | 7 | 9 |
@@ -467,6 +481,25 @@ unary
467481
| test.c:176:10:176:14 | ... < ... | test.c:176:8:176:15 | ! ... | != | 0 | 176 | 178 |
468482
| test.c:176:10:176:14 | ... < ... | test.c:176:8:176:15 | ! ... | == | 1 | 176 | 178 |
469483
| test.c:176:10:176:14 | ... < ... | test.c:176:10:176:14 | ... < ... | == | 0 | 176 | 178 |
484+
| test.c:182:8:182:34 | ! ... | test.c:182:8:182:34 | ! ... | != | 0 | 182 | 184 |
485+
| test.c:182:8:182:34 | ! ... | test.c:182:8:182:34 | ! ... | == | 1 | 182 | 184 |
486+
| test.c:182:8:182:34 | ! ... | test.c:182:10:182:33 | ... && ... | == | 0 | 182 | 184 |
487+
| test.c:182:10:182:20 | ... >= ... | test.c:182:10:182:20 | ... >= ... | != | 0 | 181 | 182 |
488+
| test.c:182:10:182:20 | ... >= ... | test.c:182:10:182:20 | ... >= ... | != | 0 | 182 | 182 |
489+
| test.c:182:10:182:20 | ... >= ... | test.c:182:10:182:20 | ... >= ... | == | 1 | 181 | 182 |
490+
| test.c:182:10:182:20 | ... >= ... | test.c:182:10:182:20 | ... >= ... | == | 1 | 182 | 182 |
491+
| test.c:182:10:182:33 | ... && ... | test.c:182:8:182:34 | ! ... | != | 0 | 182 | 184 |
492+
| test.c:182:10:182:33 | ... && ... | test.c:182:8:182:34 | ! ... | != | 1 | 181 | 182 |
493+
| test.c:182:10:182:33 | ... && ... | test.c:182:8:182:34 | ! ... | == | 0 | 181 | 182 |
494+
| test.c:182:10:182:33 | ... && ... | test.c:182:8:182:34 | ! ... | == | 1 | 182 | 184 |
495+
| test.c:182:10:182:33 | ... && ... | test.c:182:10:182:20 | ... >= ... | != | 0 | 181 | 182 |
496+
| test.c:182:10:182:33 | ... && ... | test.c:182:10:182:20 | ... >= ... | == | 1 | 181 | 182 |
497+
| test.c:182:10:182:33 | ... && ... | test.c:182:10:182:33 | ... && ... | != | 0 | 181 | 182 |
498+
| test.c:182:10:182:33 | ... && ... | test.c:182:10:182:33 | ... && ... | == | 0 | 182 | 184 |
499+
| test.c:182:10:182:33 | ... && ... | test.c:182:25:182:33 | ... < ... | != | 0 | 181 | 182 |
500+
| test.c:182:10:182:33 | ... && ... | test.c:182:25:182:33 | ... < ... | == | 1 | 181 | 182 |
501+
| test.c:182:25:182:33 | ... < ... | test.c:182:25:182:33 | ... < ... | != | 0 | 181 | 182 |
502+
| test.c:182:25:182:33 | ... < ... | test.c:182:25:182:33 | ... < ... | == | 1 | 181 | 182 |
470503
| test.cpp:18:8:18:10 | call to get | test.cpp:18:8:18:10 | call to get | != | 0 | 19 | 19 |
471504
| test.cpp:18:8:18:10 | call to get | test.cpp:18:8:18:10 | call to get | == | 1 | 19 | 19 |
472505
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | -1 | 30 | 30 |
@@ -519,3 +552,17 @@ unary
519552
| test.cpp:145:6:145:21 | call to __builtin_expect | test.cpp:145:6:145:21 | call to __builtin_expect | != | 0 | 145 | 146 |
520553
| test.cpp:145:6:145:21 | call to __builtin_expect | test.cpp:145:6:145:21 | call to __builtin_expect | == | 1 | 145 | 146 |
521554
| test.cpp:145:6:145:21 | call to __builtin_expect | test.cpp:145:23:145:23 | a | != | 42 | 145 | 146 |
555+
| test.cpp:152:7:152:8 | ! ... | test.cpp:151:8:151:8 | a | >= | 10 | 152 | 153 |
556+
| test.cpp:152:7:152:8 | ! ... | test.cpp:151:8:151:13 | ... < ... | != | 1 | 152 | 153 |
557+
| test.cpp:152:7:152:8 | ! ... | test.cpp:151:8:151:13 | ... < ... | == | 0 | 152 | 153 |
558+
| test.cpp:152:7:152:8 | ! ... | test.cpp:152:7:152:8 | ! ... | != | 0 | 152 | 153 |
559+
| test.cpp:152:7:152:8 | ! ... | test.cpp:152:7:152:8 | ! ... | == | 1 | 152 | 153 |
560+
| test.cpp:152:7:152:8 | ! ... | test.cpp:152:8:152:8 | b | != | 1 | 152 | 153 |
561+
| test.cpp:152:7:152:8 | ! ... | test.cpp:152:8:152:8 | b | == | 0 | 152 | 153 |
562+
| test.cpp:152:8:152:8 | b | test.cpp:151:8:151:8 | a | >= | 10 | 152 | 153 |
563+
| test.cpp:152:8:152:8 | b | test.cpp:151:8:151:13 | ... < ... | != | 1 | 152 | 153 |
564+
| test.cpp:152:8:152:8 | b | test.cpp:151:8:151:13 | ... < ... | == | 0 | 152 | 153 |
565+
| test.cpp:152:8:152:8 | b | test.cpp:152:7:152:8 | ! ... | != | 0 | 152 | 153 |
566+
| test.cpp:152:8:152:8 | b | test.cpp:152:7:152:8 | ! ... | == | 1 | 152 | 153 |
567+
| test.cpp:152:8:152:8 | b | test.cpp:152:8:152:8 | b | != | 1 | 152 | 153 |
568+
| test.cpp:152:8:152:8 | b | test.cpp:152:8:152:8 | b | == | 0 | 152 | 153 |

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,11 @@ void test9(short s) {
175175
void test10(int a, int b) {
176176
if(!(a < b)) {
177177

178+
}
179+
}
180+
181+
void test11(double foo) {
182+
if(!(foo >= 1e-6 && foo < 1.0)) {
183+
178184
}
179185
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,11 @@ void unary_test_builtin_expected(int a) {
145145
if(__builtin_expect(a != 42, 0)) {
146146
use(a);
147147
}
148+
}
149+
150+
void test_with_reference(bool& b, int a) {
151+
b = a < 10;
152+
if(!b) {
153+
use(a);
154+
}
148155
}

0 commit comments

Comments
 (0)