-
Notifications
You must be signed in to change notification settings - Fork 274
Move CPROVER_{r,w,rw}_ok processing to back-end #7395
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ Author: Daniel Kroening, [email protected] | |
#include <goto-programs/remove_unused_functions.h> | ||
#include <goto-programs/remove_virtual_functions.h> | ||
#include <goto-programs/restrict_function_pointers.h> | ||
#include <goto-programs/rewrite_rw_ok.h> | ||
#include <goto-programs/rewrite_union.h> | ||
#include <goto-programs/set_properties.h> | ||
#include <goto-programs/show_properties.h> | ||
|
@@ -569,6 +570,7 @@ int goto_instrument_parse_optionst::doit() | |
if(cmdline.isset("show-reaching-definitions")) | ||
{ | ||
do_indirect_call_and_rtti_removal(); | ||
rewrite_rw_ok(goto_model); | ||
|
||
const namespacet ns(goto_model.symbol_table); | ||
reaching_definitions_analysist rd_analysis(ns); | ||
|
@@ -581,6 +583,7 @@ int goto_instrument_parse_optionst::doit() | |
if(cmdline.isset("show-dependence-graph")) | ||
{ | ||
do_indirect_call_and_rtti_removal(); | ||
rewrite_rw_ok(goto_model); | ||
|
||
const namespacet ns(goto_model.symbol_table); | ||
dependence_grapht dependence_graph(ns); | ||
|
@@ -1767,6 +1770,7 @@ void goto_instrument_parse_optionst::instrument_goto_program() | |
{ | ||
do_indirect_call_and_rtti_removal(); | ||
do_remove_returns(); | ||
rewrite_rw_ok(goto_model); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see only the Is there some specific reason the other slices don't want to display the same functionality? Apologies, but I couldn't tell the intent here just by reading the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other forms of slicing don't use expression-level granularity. I have updated the commit message to include this information. |
||
|
||
log.warning() << "**** WARNING: Experimental option --full-slice, " | ||
<< "analysis results may be unsound. See " | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ Author: Martin Brain, [email protected] | |
#include <goto-programs/remove_function_pointers.h> | ||
#include <goto-programs/remove_returns.h> | ||
#include <goto-programs/remove_vector.h> | ||
#include <goto-programs/rewrite_rw_ok.h> | ||
#include <goto-programs/rewrite_union.h> | ||
#include <goto-programs/string_abstraction.h> | ||
#include <goto-programs/string_instrumentation.h> | ||
|
@@ -70,6 +71,9 @@ bool process_goto_program( | |
if(options.get_bool_option("rewrite-union")) | ||
rewrite_union(goto_model); | ||
|
||
if(options.get_bool_option("rewrite-rw-ok")) | ||
rewrite_rw_ok(goto_model); | ||
|
||
// add generic checks | ||
log.status() << "Generic Property Instrumentation" << messaget::eom; | ||
goto_check_c(options, goto_model, log.get_message_handler()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Rewrite {r,w,rw}_ok expressions as required by symbolic execution | ||
|
||
Author: Michael Tautschnig | ||
|
||
\*******************************************************************/ | ||
|
||
#include "rewrite_rw_ok.h" | ||
|
||
#include <util/expr_iterator.h> | ||
#include <util/pointer_expr.h> | ||
|
||
#include <goto-programs/goto_model.h> | ||
|
||
static optionalt<exprt> rewrite_rw_ok(exprt expr, const namespacet &ns) | ||
{ | ||
bool unchanged = true; | ||
|
||
for(auto it = expr.depth_begin(), itend = expr.depth_end(); | ||
it != itend;) // no ++it | ||
{ | ||
if(auto r_or_w_ok = expr_try_dynamic_cast<r_or_w_ok_exprt>(*it)) | ||
{ | ||
const auto &id = it->id(); | ||
exprt replacement = | ||
prophecy_r_or_w_ok_exprt{ | ||
id == ID_r_ok ? ID_prophecy_r_ok | ||
: id == ID_w_ok ? ID_prophecy_w_ok | ||
: ID_prophecy_rw_ok, | ||
r_or_w_ok->pointer(), | ||
r_or_w_ok->size(), | ||
ns.lookup(CPROVER_PREFIX "deallocated").symbol_expr(), | ||
ns.lookup(CPROVER_PREFIX "dead_object").symbol_expr()} | ||
.with_source_location<exprt>(*it); | ||
|
||
it.mutate() = std::move(replacement); | ||
unchanged = false; | ||
it.next_sibling_or_parent(); | ||
} | ||
else if( | ||
auto pointer_in_range = | ||
expr_try_dynamic_cast<pointer_in_range_exprt>(*it)) | ||
{ | ||
exprt replacement = | ||
prophecy_pointer_in_range_exprt{ | ||
pointer_in_range->lower_bound(), | ||
pointer_in_range->pointer(), | ||
pointer_in_range->upper_bound(), | ||
ns.lookup(CPROVER_PREFIX "deallocated").symbol_expr(), | ||
ns.lookup(CPROVER_PREFIX "dead_object").symbol_expr()} | ||
.with_source_location<exprt>(*it); | ||
|
||
it.mutate() = std::move(replacement); | ||
unchanged = false; | ||
it.next_sibling_or_parent(); | ||
} | ||
else | ||
++it; | ||
} | ||
|
||
if(unchanged) | ||
return {}; | ||
else | ||
return std::move(expr); | ||
} | ||
|
||
static void rewrite_rw_ok( | ||
goto_functionst::goto_functiont &goto_function, | ||
const namespacet &ns) | ||
{ | ||
for(auto &instruction : goto_function.body.instructions) | ||
instruction.transform( | ||
[&ns](exprt expr) { return rewrite_rw_ok(expr, ns); }); | ||
} | ||
|
||
void rewrite_rw_ok(goto_modelt &goto_model) | ||
{ | ||
const namespacet ns(goto_model.symbol_table); | ||
|
||
for(auto &gf_entry : goto_model.goto_functions.function_map) | ||
rewrite_rw_ok(gf_entry.second, ns); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Rewrite {r,w,rw}_ok expressions as required by symbolic execution | ||
|
||
Author: Michael Tautschnig | ||
|
||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Rewrite r/w/rw_ok expressions to ones including prophecy variables recording | ||
/// the state. | ||
|
||
#ifndef CPROVER_GOTO_PROGRAMS_REWRITE_RW_OK_H | ||
#define CPROVER_GOTO_PROGRAMS_REWRITE_RW_OK_H | ||
|
||
class goto_modelt; | ||
|
||
/// Replace all occurrences of `r_ok_exprt`, `w_ok_exprt`, `rw_ok_exprt`, | ||
/// `pointer_in_range_exprt` by their prophecy variants | ||
/// `prophecy_r_or_w_ok_exprt` and `prophecy_pointer_in_range_exprt`, | ||
/// respectively. | ||
/// Each analysis may choose to natively support `r_ok_exprt` etc. (like | ||
/// `cprover_parse_optionst` does) or may instead require the expression to be | ||
/// lowered to other primitives (like `goto_symext`). | ||
void rewrite_rw_ok(goto_modelt &); | ||
|
||
#endif // CPROVER_GOTO_PROGRAMS_REWRITE_RW_OK_H |
Uh oh!
There was an error while loading. Please reload this page.