Skip to content

Reachability slicer: split cfg walks into two phases #3218

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

Conversation

smowton
Copy link
Contributor

@smowton smowton commented Oct 22, 2018

The first phase walks outwards towards __CPROVER__start, visiting all callers but recording
callsites seen en route, then the second phase walks into callees not seen in the first phase,
restricting the search to known reachable functions. This fixes the previous algorithm, which
attempted the same logic but could visit too few functions when a particular functions was
encountered as a callee before later being seen as a caller -- the latter results in more code
being visited because the calling context is unknown, and so must be done first.

This is an alternative to #2748, see comments there for more detail.

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: 4d1cc88).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/88799021

/// \param criterion the criterion we are trying to hit
void reachability_slicert::fixedpoint_from_assertions(
const is_threadedt &is_threaded,
slicing_criteriont &criterion)
Copy link
Member

Choose a reason for hiding this comment

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

what are the side effects on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

None. Pushed an extra commit to constify these, at the risk of @tautschnig's ire re: scope creep ;)

Copy link
Collaborator

Choose a reason for hiding this comment

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

There you go :-)

^SIGNAL=0$
main\(\)
--
^warning: ignoring
Copy link
Member

Choose a reason for hiding this comment

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

Can you check that b is not in the slice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it is in the slice, since it calls c.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see, the forward walk is not used in the way I assumed.

Copy link
Member

Choose a reason for hiding this comment

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

Is there a test that actually slices away something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original cbmc/reachability-slice has two tests looking for slicing. These new ones were particularly looking for over-slicing since that's the bug @polgreen / @tautschnig encountered.

The first phase walks outwards towards __CPROVER__start, visiting all callers but recording
callsites seen en route, then the second phase walks into callees not seen in the first phase,
restricting the search to known reachable functions. This fixes the previous algorithm, which
attempted the same logic but could visit too few functions when a particular functions was
encountered as a callee before later being seen as a caller -- the latter results in more code
being visited because the calling context is unknown, and so must be done first.
@smowton smowton force-pushed the smowton/fix/reachability-slicer-take-3 branch from 1a7b501 to 0b64e10 Compare October 23, 2018 09:26
This enables us to use a const-ref in the reachability and full slicers.
@smowton smowton force-pushed the smowton/fix/reachability-slicer-take-3 branch from 0b64e10 to 0d8e3c1 Compare October 23, 2018 11:11
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: 0d8e3c1).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/88837602

@tautschnig
Copy link
Collaborator

As a side remark before getting to the key parts: "Constify slicing_criteriont::operator()" would make for a nice separate PR - it could likely be merged more or less immediately, but also it may need to be reverted in future in case someone comes up with a criterion that evolves as you query it (maybe that's weird, but that was my thinking when I originally wrote this code and I thus left it non-const).

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

I think this is ok, but I can hardly believe we'd be the first to solve this problem. @kroening mentioned BEBOP (I think that would be Fig. 3 of https://drona.csa.iisc.ac.in/~deepakd/tpa-2016/bebop.pdf), and there might be others. If at all possible, we should be re-using algorithms and terminology and refer to those for documentation.

@smowton
Copy link
Contributor Author

smowton commented Oct 25, 2018

I find it quite hard to parse those academic code listings with highly abbreviated and subscript-littered function and variable names, but I don't think this particularly relates to their reachability algorithm, because the algorithm described in Figure 3 starts at the head of main and works forwards, meaning it should never deal with a return edge whose callee is unknown. Therefore it won't face our problem, that a given program point can be encountered while walking outwards (off the top of the notional stack) and while walking inwards (with a stack).

@smowton
Copy link
Contributor Author

smowton commented Oct 25, 2018

I'll have a search for something comparable though, and let you know what I find. Merging these meanwhile, then will follow up with a doc PR if I find anything.

@smowton smowton merged commit f7d2983 into diffblue:develop Oct 25, 2018
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.

5 participants