Skip to content

Commit d86701c

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
slicer: add function path to goto-instrument
This commit adds the command line argument handling for the function path slicer. To keep all possible exeuction traces that hit both function a and b, an example invocation could look as follows: goto-instrument --fp-reachability-slice a,b input output Note, any trace that touches only a, but not b, will not be kept in the program.
1 parent 4146cc3 commit d86701c

7 files changed

+46
-16
lines changed

src/cbmc/cbmc_parse_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ void cbmc_parse_optionst::help()
933933
" --cover CC create test-suite with coverage criterion CC\n" // NOLINT(*)
934934
" --mm MM memory consistency model for concurrent programs\n" // NOLINT(*)
935935
HELP_REACHABILITY_SLICER
936+
HELP_REACHABILITY_SLICER_FB
936937
" --full-slice run full slicer (experimental)\n" // NOLINT(*)
937938
" --drop-unused-functions drop functions trivially unreachable from main function\n" // NOLINT(*)
938939
"\n"

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,15 @@ void goto_instrument_parse_optionst::instrument_goto_program()
14301430
reachability_slicer(goto_model);
14311431
}
14321432

1433+
if(cmdline.isset("fp-reachability-slice"))
1434+
{
1435+
do_indirect_call_and_rtti_removal();
1436+
1437+
status() << "Performing a function pointer reachability slice" << eom;
1438+
function_path_reachability_slicer(
1439+
goto_model, cmdline.get_comma_separated_values("fp-reachability-slice"));
1440+
}
1441+
14331442
// full slice?
14341443
if(cmdline.isset("full-slice"))
14351444
{
@@ -1610,7 +1619,7 @@ void goto_instrument_parse_optionst::help()
16101619
" --render-cluster-function clusterises the dot by functions\n"
16111620
"\n"
16121621
"Slicing:\n"
1613-
" --reachability-slice slice away instructions that can't reach assertions\n" // NOLINT(*)
1622+
HELP_REACHABILITY_SLICER
16141623
" --full-slice slice away instructions that don't affect assertions\n" // NOLINT(*)
16151624
" --property id slice with respect to specific property only\n" // NOLINT(*)
16161625
" --slice-global-inits slice away initializations of unused global variables\n" // NOLINT(*)

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Author: Daniel Kroening, [email protected]
7171
"(show-struct-alignment)(interval-analysis)(show-intervals)" \
7272
"(show-uninitialized)(show-locations)" \
7373
"(full-slice)(reachability-slice)(slice-global-inits)" \
74+
"(fp-reachability-slice):" \
7475
"(inline)(partial-inline)(function-inline):(log):(no-caching)" \
7576
OPT_REMOVE_CONST_FUNCTION_POINTERS \
7677
"(print-internal-representation)" \

src/goto-instrument/reachability_slicer.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,15 @@ void reachability_slicer(
245245
/// Perform reachability slicing on goto_model for selected functions.
246246
/// \param goto_model Goto program to slice
247247
/// \param functions_list The functions relevant for the slicing (i.e. starting
248-
/// point for the search in the cfg). Anything that is reachable in the CFG
248+
/// point for the search in the CFG). Anything that is reachable in the CFG
249249
/// starting from these functions will be kept.
250250
void function_path_reachability_slicer(
251251
goto_modelt &goto_model,
252-
const std::string &functions_list)
252+
const std::list<std::string> &functions_list)
253253
{
254-
std::istringstream functions_stream(functions_list);
255-
std::string single_function;
256-
while(std::getline(functions_stream, single_function, ','))
254+
for(const auto &function : functions_list)
257255
{
258-
in_function_criteriont matching_criterion(single_function);
256+
in_function_criteriont matching_criterion(function);
259257
reachability_slicert slicer;
260258
slicer(goto_model.goto_functions, matching_criterion, true);
261259
}

src/goto-instrument/reachability_slicer.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void reachability_slicer(
2525

2626
void function_path_reachability_slicer(
2727
goto_modelt &goto_model,
28-
const std::string &functions_list);
28+
const std::list<std::string> &functions_list);
2929

3030
void reachability_slicer(
3131
goto_modelt &,
@@ -40,13 +40,15 @@ void reachability_slicer(
4040
#define OPT_REACHABILITY_SLICER \
4141
"(fp-reachability-slice):(reachability-slice)(reachability-slice-fb)" // NOLINT(*)
4242

43-
#define HELP_REACHABILITY_SLICER \
44-
" --fp-reachability-slice <f> remove instructions that cannot appear on a " \
45-
"trace that visits all given functions. The list of functions has to be " \
46-
"given as a comma separated list.\n" \
47-
" --reachability-slice remove instructions that cannot appear on a " \
48-
"trace from entry point to a property\n" \
49-
" --reachability-slice-fb remove instructions that cannot appear on a " \
50-
"trace from entry point through a property\n" // NOLINT(*)
43+
#define HELP_REACHABILITY_SLICER \
44+
" --fp-reachability-slice f remove instructions that cannot appear on a trace\n" \
45+
" that visits all given functions. The list of\n" \
46+
" functions has to be given as a comma separated\n" \
47+
" list f.\n" \
48+
" --reachability-slice remove instructions that cannot appear on a trace\n" \
49+
" from entry point to a property\n" // NOLINT(*)
50+
#define HELP_REACHABILITY_SLICER_FB \
51+
" --reachability-slice-fb remove instructions that cannot appear on a trace\n" \
52+
" from entry point through a property\n" // NOLINT(*)
5153
// clang-format on
5254
#endif // CPROVER_GOTO_INSTRUMENT_REACHABILITY_SLICER_H

src/util/cmdline.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ const std::list<std::string> &cmdlinet::get_values(
118118
return immutable_empty_list;
119119
}
120120

121+
std::list<std::string>
122+
cmdlinet::get_comma_separated_values(const char *option) const
123+
{
124+
std::list<std::string> separated_values;
125+
auto i = getoptnr(option);
126+
if(i.has_value() && !options[*i].values.empty())
127+
{
128+
std::istringstream values_stream(options[*i].values.front());
129+
std::string single_value;
130+
while(std::getline(values_stream, single_value, ','))
131+
{
132+
separated_values.push_back(single_value);
133+
}
134+
}
135+
return separated_values;
136+
}
137+
121138
optionalt<std::size_t> cmdlinet::getoptnr(char option) const
122139
{
123140
for(std::size_t i=0; i<options.size(); i++)

src/util/cmdline.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class cmdlinet
2727
const std::list<std::string> &get_values(const std::string &option) const;
2828
const std::list<std::string> &get_values(char option) const;
2929

30+
std::list<std::string> get_comma_separated_values(const char *option) const;
31+
3032
virtual bool isset(char option) const;
3133
virtual bool isset(const char *option) const;
3234
virtual void set(const std::string &option);

0 commit comments

Comments
 (0)