Skip to content

Commit b2d7f31

Browse files
committed
Reachability slice requires function bodies
Reachability slicing relies on the CFG. The CFG, however, will not contain edges from a function call to the next instruction when no body is available for the function call. Therefore, reachability slicing requires two steps: - The model library needs to be applied. CBMC already did so, goto-instrument now does with this commit. - Remaining function calls without body need to be replaced by nondet-return-value assignments. Fixes: #6394
1 parent acbe997 commit b2d7f31

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdlib.h>
2+
3+
void undefined_function();
4+
5+
void a()
6+
{
7+
undefined_function();
8+
}
9+
10+
void b()
11+
{
12+
int should_be_sliced_away;
13+
}
14+
15+
int main()
16+
{
17+
int *p = malloc(sizeof(int));
18+
a();
19+
__CPROVER_assert(0, "reach me");
20+
b();
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--reachability-slice
4+
^VERIFICATION FAILED$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
should_be_sliced_away

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,11 @@ void goto_instrument_parse_optionst::instrument_goto_program()
10671067

10681068
// we add the library in some cases, as some analyses benefit
10691069

1070-
if(cmdline.isset("add-library") ||
1071-
cmdline.isset("mm"))
1070+
if(
1071+
cmdline.isset("add-library") || cmdline.isset("mm") ||
1072+
cmdline.isset("reachability-slice") ||
1073+
cmdline.isset("reachability-slice-fb") ||
1074+
cmdline.isset("fp-reachability-slice"))
10721075
{
10731076
if(cmdline.isset("show-custom-bitvector-analysis") ||
10741077
cmdline.isset("custom-bitvector-analysis"))

src/goto-instrument/reachability_slicer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ void reachability_slicert::operator()(
3232
const slicing_criteriont &criterion,
3333
bool include_forward_reachability)
3434
{
35+
// Replace function calls without body by non-deterministic return values to
36+
// ensure the CFG does not consider instructions after such a call to be
37+
// unreachable.
38+
remove_calls_no_bodyt remove_calls_no_body;
39+
remove_calls_no_body(goto_functions);
40+
goto_functions.update();
41+
3542
cfg(goto_functions);
3643
for(const auto &gf_entry : goto_functions.function_map)
3744
{

0 commit comments

Comments
 (0)