-
Notifications
You must be signed in to change notification settings - Fork 273
Reachability slice requires function bodies #6505
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
NlightNFotis
merged 3 commits into
diffblue:develop
from
tautschnig:fix-reachability-slicer
Feb 24, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <stdlib.h> | ||
|
||
void undefined_function(); | ||
|
||
void a() | ||
{ | ||
undefined_function(); | ||
} | ||
|
||
void b() | ||
{ | ||
int should_be_sliced_away; | ||
} | ||
|
||
int main() | ||
{ | ||
int *p = malloc(sizeof(int)); | ||
a(); | ||
__CPROVER_assert(0, "reach me"); | ||
b(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
main.c | ||
--reachability-slice | ||
Removing call to undefined_function, which has no body | ||
^VERIFICATION FAILED$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
should_be_sliced_away |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,17 +13,46 @@ Author: Daniel Kroening, [email protected] | |
/// (and possibly, depending on the parameters, keep those that can be reached | ||
/// from the criterion). | ||
|
||
#include "reachability_slicer.h" | ||
#include "full_slicer_class.h" | ||
#include "reachability_slicer_class.h" | ||
|
||
#include <util/exception_utils.h> | ||
|
||
#include <goto-programs/cfg.h> | ||
#include <goto-programs/remove_calls_no_body.h> | ||
#include <goto-programs/remove_skip.h> | ||
#include <goto-programs/remove_unreachable.h> | ||
|
||
#include <util/exception_utils.h> | ||
#include <analyses/is_threaded.h> | ||
|
||
#include "full_slicer_class.h" | ||
#include "reachability_slicer_class.h" | ||
#include "reachability_slicer.h" | ||
|
||
void reachability_slicert::operator()( | ||
goto_functionst &goto_functions, | ||
const slicing_criteriont &criterion, | ||
bool include_forward_reachability, | ||
message_handlert &message_handler) | ||
{ | ||
// Replace function calls without body by non-deterministic return values to | ||
// ensure the CFG does not consider instructions after such a call to be | ||
// unreachable. | ||
remove_calls_no_bodyt remove_calls_no_body; | ||
remove_calls_no_body(goto_functions, message_handler); | ||
goto_functions.update(); | ||
|
||
cfg(goto_functions); | ||
for(const auto &gf_entry : goto_functions.function_map) | ||
{ | ||
forall_goto_program_instructions(i_it, gf_entry.second.body) | ||
cfg[cfg.entry_map[i_it]].function_id = gf_entry.first; | ||
} | ||
|
||
is_threadedt is_threaded(goto_functions); | ||
fixedpoint_to_assertions(is_threaded, criterion); | ||
if(include_forward_reachability) | ||
fixedpoint_from_assertions(is_threaded, criterion); | ||
slice(goto_functions); | ||
} | ||
|
||
/// Get the set of nodes that correspond to the given criterion, or that can | ||
/// appear in concurrent execution. None of these should be sliced away so | ||
|
@@ -364,13 +393,18 @@ void reachability_slicert::slice(goto_functionst &goto_functions) | |
/// \param include_forward_reachability: Determines if only instructions | ||
/// from which the criterion is reachable should be kept (false) or also | ||
/// those reachable from the criterion (true) | ||
/// \param message_handler: message handler | ||
void reachability_slicer( | ||
goto_modelt &goto_model, | ||
const bool include_forward_reachability) | ||
const bool include_forward_reachability, | ||
message_handlert &message_handler) | ||
{ | ||
reachability_slicert s; | ||
assert_criteriont a; | ||
s(goto_model.goto_functions, a, include_forward_reachability); | ||
s(goto_model.goto_functions, | ||
a, | ||
include_forward_reachability, | ||
message_handler); | ||
} | ||
|
||
/// Perform reachability slicing on goto_model for selected properties. | ||
|
@@ -380,34 +414,42 @@ void reachability_slicer( | |
/// \param include_forward_reachability: Determines if only instructions | ||
/// from which the criterion is reachable should be kept (false) or also | ||
/// those reachable from the criterion (true) | ||
/// \param message_handler: message handler | ||
void reachability_slicer( | ||
goto_modelt &goto_model, | ||
const std::list<std::string> &properties, | ||
const bool include_forward_reachability) | ||
const bool include_forward_reachability, | ||
message_handlert &message_handler) | ||
{ | ||
reachability_slicert s; | ||
properties_criteriont p(properties); | ||
s(goto_model.goto_functions, p, include_forward_reachability); | ||
s(goto_model.goto_functions, | ||
p, | ||
include_forward_reachability, | ||
message_handler); | ||
} | ||
|
||
/// 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 | ||
/// starting from these functions will be kept. | ||
/// \param message_handler: message handler | ||
void function_path_reachability_slicer( | ||
goto_modelt &goto_model, | ||
const std::list<std::string> &functions_list) | ||
const std::list<std::string> &functions_list, | ||
message_handlert &message_handler) | ||
{ | ||
for(const auto &function : functions_list) | ||
{ | ||
in_function_criteriont matching_criterion(function); | ||
reachability_slicert slicer; | ||
slicer(goto_model.goto_functions, matching_criterion, true); | ||
slicer( | ||
goto_model.goto_functions, matching_criterion, true, message_handler); | ||
} | ||
|
||
remove_calls_no_bodyt remove_calls_no_body; | ||
remove_calls_no_body(goto_model.goto_functions); | ||
remove_calls_no_body(goto_model.goto_functions, message_handler); | ||
|
||
goto_model.goto_functions.update(); | ||
goto_model.goto_functions.compute_loop_numbers(); | ||
|
@@ -417,19 +459,24 @@ void function_path_reachability_slicer( | |
/// comprising all properties. Only instructions from which the criterion | ||
/// is reachable will be kept. | ||
/// \param goto_model: Goto program to slice | ||
void reachability_slicer(goto_modelt &goto_model) | ||
/// \param message_handler: message handler | ||
void reachability_slicer( | ||
goto_modelt &goto_model, | ||
message_handlert &message_handler) | ||
{ | ||
reachability_slicer(goto_model, false); | ||
reachability_slicer(goto_model, false, message_handler); | ||
} | ||
|
||
/// Perform reachability slicing on goto_model for selected properties. Only | ||
/// instructions from which the criterion is reachable will be kept. | ||
/// \param goto_model: Goto program to slice | ||
/// \param properties: The properties relevant for the slicing (i.e. starting | ||
/// point for the search in the cfg) | ||
/// \param message_handler: message handler | ||
void reachability_slicer( | ||
goto_modelt &goto_model, | ||
const std::list<std::string> &properties) | ||
const std::list<std::string> &properties, | ||
message_handlert &message_handler) | ||
{ | ||
reachability_slicer(goto_model, properties, false); | ||
reachability_slicer(goto_model, properties, false, message_handler); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,25 +16,30 @@ Author: Daniel Kroening, [email protected] | |
#include <string> | ||
|
||
class goto_modelt; | ||
class message_handlert; | ||
|
||
void reachability_slicer(goto_modelt &); | ||
void reachability_slicer(goto_modelt &, message_handlert &); | ||
|
||
void reachability_slicer( | ||
goto_modelt &, | ||
const std::list<std::string> &properties); | ||
const std::list<std::string> &properties, | ||
message_handlert &); | ||
|
||
void function_path_reachability_slicer( | ||
goto_modelt &goto_model, | ||
const std::list<std::string> &functions_list); | ||
const std::list<std::string> &functions_list, | ||
message_handlert &); | ||
|
||
void reachability_slicer( | ||
goto_modelt &, | ||
const bool include_forward_reachability); | ||
const bool include_forward_reachability, | ||
message_handlert &); | ||
|
||
void reachability_slicer( | ||
goto_modelt &, | ||
const std::list<std::string> &properties, | ||
const bool include_forward_reachability); | ||
const bool include_forward_reachability, | ||
message_handlert &); | ||
|
||
// clang-format off | ||
#define OPT_REACHABILITY_SLICER \ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,10 @@ Author: Daniel Kroening, [email protected] | |
#ifndef CPROVER_GOTO_INSTRUMENT_REACHABILITY_SLICER_CLASS_H | ||
#define CPROVER_GOTO_INSTRUMENT_REACHABILITY_SLICER_CLASS_H | ||
|
||
#include <goto-programs/goto_functions.h> | ||
#include <goto-programs/cfg.h> | ||
|
||
#include <analyses/is_threaded.h> | ||
#include <goto-programs/goto_program.h> | ||
|
||
class goto_functionst; | ||
class message_handlert; | ||
class slicing_criteriont; | ||
|
||
class reachability_slicert | ||
|
@@ -25,21 +24,8 @@ class reachability_slicert | |
void operator()( | ||
goto_functionst &goto_functions, | ||
const slicing_criteriont &criterion, | ||
bool include_forward_reachability) | ||
{ | ||
cfg(goto_functions); | ||
for(const auto &gf_entry : goto_functions.function_map) | ||
{ | ||
forall_goto_program_instructions(i_it, gf_entry.second.body) | ||
cfg[cfg.entry_map[i_it]].function_id = gf_entry.first; | ||
} | ||
|
||
is_threadedt is_threaded(goto_functions); | ||
fixedpoint_to_assertions(is_threaded, criterion); | ||
if(include_forward_reachability) | ||
fixedpoint_from_assertions(is_threaded, criterion); | ||
slice(goto_functions); | ||
} | ||
bool include_forward_reachability, | ||
message_handlert &); | ||
|
||
protected: | ||
struct slicer_entryt | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once upon a future... it'd be lovely if we had proper feature flags, grouping of feature flags, etc.... rather than sprinkling hardcoded strings all over the place :-)