Skip to content

Commit db1dc6f

Browse files
authored
Merge pull request #15021 from jketema/ir-guards-unreached-fix
C++: Fix handling of unreached instructions in IRGuards
2 parents db0fc37 + 4390e4c commit db1dc6f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll

+3
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ private class GuardConditionFromIR extends GuardCondition {
223223
or
224224
instr = tce.getInstruction(ConditionValueFalseTempAddressTag())
225225
)
226+
or
227+
// Exclude unreached instructions, as their AST is the whole function and not a block.
228+
instr instanceof UnreachedInstruction
226229
}
227230
}
228231

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

+10
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,13 @@ int ternary_test(const char *path, int mode)
174174
{
175175
return (foo(path, mode) == 0 ? 1 : 0);
176176
}
177+
178+
void abort(void);
179+
180+
int abort_test(int x) {
181+
if (x) {
182+
x += 1;
183+
} else {
184+
abort();
185+
}
186+
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ astGuards
3535
| test.c:162:9:162:18 | ... < ... |
3636
| test.c:165:9:165:18 | ... < ... |
3737
| test.c:175:13:175:32 | ... == ... |
38+
| test.c:181:9:181:9 | x |
3839
| test.cpp:18:8:18:10 | call to get |
3940
| test.cpp:31:7:31:13 | ... == ... |
4041
| test.cpp:42:13:42:20 | call to getABool |
@@ -255,6 +256,9 @@ astGuardsControl
255256
| test.c:165:9:165:18 | ... < ... | true | 165 | 166 |
256257
| test.c:175:13:175:32 | ... == ... | false | 175 | 175 |
257258
| test.c:175:13:175:32 | ... == ... | true | 175 | 175 |
259+
| test.c:181:9:181:9 | x | false | 183 | 184 |
260+
| test.c:181:9:181:9 | x | true | 181 | 182 |
261+
| test.c:181:9:181:9 | x | true | 186 | 180 |
258262
| test.cpp:18:8:18:10 | call to get | true | 19 | 19 |
259263
| test.cpp:31:7:31:13 | ... == ... | false | 30 | 30 |
260264
| test.cpp:31:7:31:13 | ... == ... | false | 34 | 34 |
@@ -470,6 +474,7 @@ irGuards
470474
| test.c:162:9:162:18 | CompareLT: ... < ... |
471475
| test.c:165:9:165:18 | CompareLT: ... < ... |
472476
| test.c:175:13:175:32 | CompareEQ: ... == ... |
477+
| test.c:181:9:181:9 | Load: x |
473478
| test.cpp:18:8:18:12 | CompareNE: (bool)... |
474479
| test.cpp:31:7:31:13 | CompareEQ: ... == ... |
475480
| test.cpp:42:13:42:20 | Call: call to getABool |
@@ -667,6 +672,8 @@ irGuardsControl
667672
| test.c:165:9:165:18 | CompareLT: ... < ... | true | 165 | 166 |
668673
| test.c:175:13:175:32 | CompareEQ: ... == ... | false | 175 | 175 |
669674
| test.c:175:13:175:32 | CompareEQ: ... == ... | true | 175 | 175 |
675+
| test.c:181:9:181:9 | Load: x | false | 184 | 184 |
676+
| test.c:181:9:181:9 | Load: x | true | 182 | 182 |
670677
| test.cpp:18:8:18:12 | CompareNE: (bool)... | true | 19 | 19 |
671678
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | false | 34 | 34 |
672679
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | true | 30 | 30 |

0 commit comments

Comments
 (0)