Skip to content

Commit 46e69a4

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 8ab58e6 commit 46e69a4

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
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
@@ -1066,8 +1066,11 @@ void goto_instrument_parse_optionst::instrument_goto_program()
10661066

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

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

src/goto-instrument/reachability_slicer.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Author: Daniel Kroening, [email protected]
1414
/// from the criterion).
1515

1616
#include "full_slicer_class.h"
17-
#include "reachability_slicer.h"
1817
#include "reachability_slicer_class.h"
1918

2019
#include <util/exception_utils.h>
@@ -26,11 +25,20 @@ Author: Daniel Kroening, [email protected]
2625

2726
#include <analyses/is_threaded.h>
2827

28+
#include "reachability_slicer.h"
29+
2930
void reachability_slicert::operator()(
3031
goto_functionst &goto_functions,
3132
const slicing_criteriont &criterion,
3233
bool include_forward_reachability)
3334
{
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+
3442
cfg(goto_functions);
3543
for(const auto &gf_entry : goto_functions.function_map)
3644
{

0 commit comments

Comments
 (0)