Skip to content

C++: Fix handling of unreached instructions in IRGuards #15021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ private class GuardConditionFromIR extends GuardCondition {
or
instr = tce.getInstruction(ConditionValueFalseTempAddressTag())
)
or
// Exclude unreached instructions, as their AST is the whole function and not a block.
instr instanceof UnreachedInstruction
}
}

Expand Down
10 changes: 10 additions & 0 deletions cpp/ql/test/library-tests/controlflow/guards-ir/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,13 @@ int ternary_test(const char *path, int mode)
{
return (foo(path, mode) == 0 ? 1 : 0);
}

void abort(void);

int abort_test(int x) {
if (x) {
x += 1;
} else {
abort();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ astGuards
| test.c:162:9:162:18 | ... < ... |
| test.c:165:9:165:18 | ... < ... |
| test.c:175:13:175:32 | ... == ... |
| test.c:181:9:181:9 | x |
| test.cpp:18:8:18:10 | call to get |
| test.cpp:31:7:31:13 | ... == ... |
| test.cpp:42:13:42:20 | call to getABool |
Expand Down Expand Up @@ -255,6 +256,9 @@ astGuardsControl
| test.c:165:9:165:18 | ... < ... | true | 165 | 166 |
| test.c:175:13:175:32 | ... == ... | false | 175 | 175 |
| test.c:175:13:175:32 | ... == ... | true | 175 | 175 |
| test.c:181:9:181:9 | x | false | 183 | 184 |
| test.c:181:9:181:9 | x | true | 181 | 182 |
| test.c:181:9:181:9 | x | true | 186 | 180 |
| test.cpp:18:8:18:10 | call to get | true | 19 | 19 |
| test.cpp:31:7:31:13 | ... == ... | false | 30 | 30 |
| test.cpp:31:7:31:13 | ... == ... | false | 34 | 34 |
Expand Down Expand Up @@ -470,6 +474,7 @@ irGuards
| test.c:162:9:162:18 | CompareLT: ... < ... |
| test.c:165:9:165:18 | CompareLT: ... < ... |
| test.c:175:13:175:32 | CompareEQ: ... == ... |
| test.c:181:9:181:9 | Load: x |
| test.cpp:18:8:18:12 | CompareNE: (bool)... |
| test.cpp:31:7:31:13 | CompareEQ: ... == ... |
| test.cpp:42:13:42:20 | Call: call to getABool |
Expand Down Expand Up @@ -667,6 +672,8 @@ irGuardsControl
| test.c:165:9:165:18 | CompareLT: ... < ... | true | 165 | 166 |
| test.c:175:13:175:32 | CompareEQ: ... == ... | false | 175 | 175 |
| test.c:175:13:175:32 | CompareEQ: ... == ... | true | 175 | 175 |
| test.c:181:9:181:9 | Load: x | false | 184 | 184 |
| test.c:181:9:181:9 | Load: x | true | 182 | 182 |
| test.cpp:18:8:18:12 | CompareNE: (bool)... | true | 19 | 19 |
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | false | 34 | 34 |
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | true | 30 | 30 |
Expand Down