Skip to content

Upstream slice functions #2758

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 3 commits into from
Oct 2, 2018
Merged

Conversation

nmanthey
Copy link
Contributor

This change allows to slice based on functions remaining reachable. This slicing allows to reduce the search space to a user chosen subset of the prorgam.

@kroening
Copy link
Member

(I'll get someone to produce a set of tests)

@nmanthey
Copy link
Contributor Author

I can certainly add a test case here, I just learned from #2748 that I can show the goto-program to compare it in the test case.

@nmanthey nmanthey force-pushed the upstream-slice-functions branch from f9edad3 to 392cdf5 Compare August 22, 2018 07:45
@nmanthey nmanthey force-pushed the upstream-slice-functions branch from 392cdf5 to 19f303a Compare September 11, 2018 07:28
@xbauch
Copy link
Contributor

xbauch commented Sep 26, 2018

3 small fixes:

  1. option parser ignored colon-separated list
  2. running slicer multiple times broke an invariant about end-function nodes
  3. on test was called with wrong options

@xbauch xbauch force-pushed the upstream-slice-functions branch from 78cabc8 to 3091abd Compare September 26, 2018 15:14
--fp-reachability-slice c
^EXIT=0$
^SIGNAL=0$
--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit easy to pass at the moment, especially if the precise pretty-printing of "dead f" were to change. Suggest adding some positive requirements too, to make the test more robust.

--fp-reachability-slice a,c
^EXIT=0$
^SIGNAL=0$
dead d;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for comparison, this is better)

main.c
--fp-reachability-slice b,c
^EXIT=0$
^SIGNAL=0$
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No meaningful positive conditions

stack.emplace_back(edge.first, true);
stack.emplace_back(
cfg.entry_map[std::prev(node.PC)], caller_is_known);
if(std::prev(node.PC)->is_function_call())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment about when this might be false?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really shouldn't happen, but something broke in the slicer during multiple calls and the cfg-predecessor of a successor-of-callsite was not a function call. Now that a new slicer is created it does not happen, so I replaced it back with the original invariant.

if(
!e.reaches_assertion && !e.reachable_from_assertion &&
!i_it->is_end_function())
i_it->make_assumption(false_exprt());
e.reaches_assertion = e.reachable_from_assertion = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment in-inline about why these are reset here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It looks like the slicer might be run more than once, in which case perhaps it should be reset before use, rather than upon executing the transformation?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that slicer is not really supposed to be called multiple times; or it would require a much more thorough resetting that just the reachability flags. I changed the code to build a new slicer before every call.

goto_modelt &goto_model,
const std::string &functions_list)
{
reachability_slicert s;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s->slicer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and the following) were renamed as suggested. Thanks.

{
reachability_slicert s;

std::istringstream multiple_functions(functions_list);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple_functions->functions_stream?

std::string single_function;
while(std::getline(multiple_functions, single_function, ','))
{
in_function_criteriont p(single_function);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p->matching_criterion?

@kroening
Copy link
Member

This is nearly there; it needs a bit of commit squashing, i.e., the tests should come with the code that is tested.

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the prompt fixes!

Petr Bauch added 2 commits September 27, 2018 12:24
This criterion marks all instructions of a given function
as slicer starting point. This is useful when the slicing does
not aim at properties, but path that hit a certain function.
This slicer keeps any function in the program, in case it is backward
or forward reachable from the target function. The analysis can be
repeated for multiple functions.

Note: This implementation cannot deal with order of function calls, e.g.
if functions a,b and c should be kept, then a path that has
a, which calls c, which calls b
will also be kept. However, path where not all functions will be called,
will be dropped.
@xbauch xbauch force-pushed the upstream-slice-functions branch from 424e30e to ed85c7f Compare September 27, 2018 11:27
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR failed Diffblue compatibility checks (cbmc commit: ed85c7f).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/86137585
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

Copy link
Member

@peterschrammel peterschrammel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of nitpicks

@@ -1610,6 +1619,9 @@ void goto_instrument_parse_optionst::help()
" --render-cluster-function clusterises the dot by functions\n"
"\n"
"Slicing:\n"
" --fp-reachability-slice <f> remove instructions that cannot appear on a\n" // NOLINT(*)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--fp-reachability-slice f
The list of functions has to be given as a comma-separated list f.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this use HELP_REACHABILITY_SLICER from below?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this help macro is for CBMC options, e.g. --reachability-slice-fb is not a valid option for goto-instrument.

{
std::istringstream functions_stream(functions_list);
std::string single_function;
while(std::getline(functions_stream, single_function, ','))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to provide the splitting as a list<string> cmdlinet::get_comma_separated_values(string) function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


#define HELP_REACHABILITY_SLICER \
" --fp-reachability-slice <f> remove instructions that cannot appear on a " \
"trace that visits all given functions. The list of functions has to be " \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text help text should be broken after 80 chars and properly aligned (e.g. trace should start below remove).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

/// Perform reachability slicing on goto_model for selected functions.
/// \param goto_model Goto program to slice
/// \param functions_list The functions relevant for the slicing (i.e. starting
/// point for the search in the cfg). Anything that is reachable in the CFG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CFG

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR failed Diffblue compatibility checks (cbmc commit: bfe3dd2).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/86266130
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).


#define HELP_REACHABILITY_SLICER \
" --fp-reachability-slice f remove instructions that cannot appear on a " \
"trace\n that visits all given functions. The " \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The layout looks a bit odd. Since clang-format is already off for this section, I'm sure you can make this nicer manually.

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.
@xbauch xbauch force-pushed the upstream-slice-functions branch from bfe3dd2 to d86701c Compare October 2, 2018 07:42
@xbauch xbauch merged commit 744f918 into diffblue:develop Oct 2, 2018
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: d86701c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/86571560

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants