Skip to content

Commit 6d908a4

Browse files
committed
C++: Add a testcase that was discussed during PR reviews.
1 parent 42c1937 commit 6d908a4

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@
4949
| test.cpp:135:6:135:21 | call to __builtin_expect |
5050
| test.cpp:141:6:141:21 | call to __builtin_expect |
5151
| test.cpp:145:6:145:21 | call to __builtin_expect |
52+
| test.cpp:151:6:151:14 | ! ... |
53+
| test.cpp:151:8:151:13 | ... + ... |

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,16 @@
267267
| 146 | x != 0 when ! ... is false |
268268
| 146 | x != 0 when x is true |
269269
| 146 | x == 0 when x is false |
270+
| 151 | ! ... != 0 when ! ... is true |
271+
| 151 | ! ... == 0 when ! ... is false |
272+
| 151 | ... + ... != 0 when ! ... is false |
273+
| 151 | ... + ... != 0 when ... + ... is true |
274+
| 151 | ... + ... == 0 when ! ... is true |
275+
| 151 | ... + ... == 0 when ... + ... is false |
276+
| 151 | a != -10 when ! ... is false |
277+
| 151 | a != -10 when ... + ... is true |
278+
| 151 | a == -10 when ! ... is true |
279+
| 151 | a == -10 when ... + ... is false |
270280
| 152 | p != 0 when p is true |
271281
| 152 | p == 0 when p is false |
272282
| 158 | ! ... != 0 when ! ... is true |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,5 @@
108108
| test.cpp:135:6:135:21 | call to __builtin_expect | true | 135 | 136 |
109109
| test.cpp:141:6:141:21 | call to __builtin_expect | true | 141 | 142 |
110110
| test.cpp:145:6:145:21 | call to __builtin_expect | true | 145 | 146 |
111+
| test.cpp:151:6:151:14 | ! ... | true | 151 | 152 |
112+
| test.cpp:151:8:151:13 | ... + ... | false | 151 | 152 |

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,8 @@ unary
399399
| test.cpp:145:6:145:21 | call to __builtin_expect | test.cpp:145:6:145:21 | call to __builtin_expect | != | 0 | 145 | 146 |
400400
| test.cpp:145:6:145:21 | call to __builtin_expect | test.cpp:145:23:145:23 | a | != | 42 | 145 | 146 |
401401
| test.cpp:145:6:145:21 | call to __builtin_expect | test.cpp:145:23:145:29 | ... != ... | != | 0 | 145 | 146 |
402+
| test.cpp:151:6:151:14 | ! ... | test.cpp:151:6:151:14 | ! ... | != | 0 | 151 | 152 |
403+
| test.cpp:151:6:151:14 | ! ... | test.cpp:151:8:151:8 | a | == | -10 | 151 | 152 |
404+
| test.cpp:151:6:151:14 | ! ... | test.cpp:151:8:151:13 | ... + ... | == | 0 | 151 | 152 |
405+
| test.cpp:151:8:151:13 | ... + ... | test.cpp:151:8:151:8 | a | == | -10 | 151 | 152 |
406+
| test.cpp:151:8:151:13 | ... + ... | test.cpp:151:8:151:13 | ... + ... | == | 0 | 151 | 152 |

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,10 @@ void unary_test_builtin_expected(int a) {
145145
if(__builtin_expect(a != 42, 0)) {
146146
use(a);
147147
}
148+
}
149+
150+
void addition_and_negation(int a) {
151+
if(!(a + 10)) {
152+
use(a); // a is -10 here
153+
}
148154
}

0 commit comments

Comments
 (0)