Skip to content

Group symex options into symex_config structure #3431

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 2 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/goto-symex/goto_symex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ unsigned goto_symext::dynamic_counter=0;

void goto_symext::do_simplify(exprt &expr)
{
if(simplify_opt)
if(symex_config.simplify_opt)
simplify(expr, ns);
}

Expand Down
40 changes: 19 additions & 21 deletions src/goto-symex/goto_symex.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ class symex_nondet_generatort
unsigned nondet_count = 0;
};

/// Configuration of the symbolic execution
struct symex_configt final
{
unsigned max_depth;
bool doing_path_exploration;
bool allow_pointer_unsoundness;
bool constant_propagation;
bool self_loops_to_assumptions;
bool simplify_opt;
bool unwinding_assertions;
bool partial_loops;
mp_integer debug_level;

explicit symex_configt(const optionst &options);
};

/// \brief The main class for the forward symbolic simulator
///
/// Higher-level architectural information on symbolic execution is
Expand All @@ -65,18 +81,8 @@ class goto_symext
const optionst &options,
path_storaget &path_storage)
: should_pause_symex(false),
max_depth(options.get_unsigned_int_option("depth")),
doing_path_exploration(options.is_set("paths")),
allow_pointer_unsoundness(
options.get_bool_option("allow-pointer-unsoundness")),
symex_config(options),
language_mode(),
constant_propagation(options.get_bool_option("propagation")),
self_loops_to_assumptions(
options.get_bool_option("self-loops-to-assumptions")),
simplify_opt(options.get_bool_option("simplify")),
unwinding_assertions(options.get_bool_option("unwinding-assertions")),
partial_loops(options.get_bool_option("partial-loops")),
debug_level(options.get_option("debug-level")),
outer_symbol_table(outer_symbol_table),
ns(outer_symbol_table),
target(_target),
Expand Down Expand Up @@ -150,6 +156,8 @@ class goto_symext
bool should_pause_symex;

protected:
const symex_configt symex_config;

/// Initialise the symbolic execution and the given state with <code>pc</code>
/// as entry point.
/// \param state Symex state to initialise.
Expand All @@ -176,23 +184,13 @@ class goto_symext
const get_goto_functiont &,
statet &);

const unsigned max_depth;
const bool doing_path_exploration;
const bool allow_pointer_unsoundness;

public:

/// language_mode: ID_java, ID_C or another language identifier
/// if we know the source language in use, irep_idt() otherwise.
irep_idt language_mode;

protected:
const bool constant_propagation;
const bool self_loops_to_assumptions;
const bool simplify_opt;
const bool unwinding_assertions;
const bool partial_loops;
const std::string debug_level;

/// The symbol table associated with the goto-program that we're
/// executing. This symbol table will not additionally contain objects
Expand Down
6 changes: 3 additions & 3 deletions src/goto-symex/symex_assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ void goto_symext::symex_assign_symbol(
ssa_lhs,
ssa_rhs,
ns,
simplify_opt,
constant_propagation,
allow_pointer_unsoundness);
symex_config.simplify_opt,
symex_config.constant_propagation,
symex_config.allow_pointer_unsoundness);

exprt ssa_full_lhs=full_lhs;
ssa_full_lhs=add_to_lhs(ssa_full_lhs, ssa_lhs);
Expand Down
4 changes: 1 addition & 3 deletions src/goto-symex/symex_builtin_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@ void goto_symext::symex_trace(
{
PRECONDITION(code.arguments().size() >= 2);

int debug_thresh = unsafe_string2int(debug_level);

mp_integer debug_lvl;
optionalt<mp_integer> maybe_debug =
numeric_cast<mp_integer>(code.arguments()[0]);
Expand All @@ -473,7 +471,7 @@ void goto_symext::symex_trace(
code.arguments()[1].op0().id() == ID_string_constant,
"CBMC_trace expects string constant as second argument");

if(mp_integer(debug_thresh)>=debug_lvl)
if(symex_config.debug_level >= debug_lvl)
{
std::list<exprt> vars;

Expand Down
4 changes: 2 additions & 2 deletions src/goto-symex/symex_function_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ void goto_symext::symex_function_call_code(
// see if it's too much
if(stop_recursing)
{
if(partial_loops)
if(symex_config.partial_loops)
{
// it's ok, ignore
}
else
{
if(unwinding_assertions)
if(symex_config.unwinding_assertions)
vcc(false_exprt(), "recursion unwinding assertion", state);

// add to state guard to prevent further assignments
Expand Down
10 changes: 5 additions & 5 deletions src/goto-symex/symex_goto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void goto_symext::symex_goto(statet &state)
{
// is it label: goto label; or while(cond); - popular in SV-COMP
if(
self_loops_to_assumptions &&
symex_config.self_loops_to_assumptions &&
(goto_target == state.source.pc ||
(instruction.incoming_edges.size() == 1 &&
*instruction.incoming_edges.begin() == goto_target)))
Expand Down Expand Up @@ -109,7 +109,7 @@ void goto_symext::symex_goto(statet &state)
(simpl_state_guard.is_true() ||
// or there is another block, but we're doing path exploration so
// we're going to skip over it for now and return to it later.
doing_path_exploration))
symex_config.doing_path_exploration))
{
DATA_INVARIANT(
instruction.targets.size() > 0,
Expand Down Expand Up @@ -176,7 +176,7 @@ void goto_symext::symex_goto(statet &state)
log.debug() << "Resuming from next instruction '"
<< state_pc->source_location << "'" << log.eom;
}
else if(doing_path_exploration)
else if(symex_config.doing_path_exploration)
{
// We should save both the instruction after this goto, and the target of
// the goto.
Expand Down Expand Up @@ -490,9 +490,9 @@ void goto_symext::loop_bound_exceeded(
else
negated_cond=not_exprt(guard);

if(!partial_loops)
if(!symex_config.partial_loops)
{
if(unwinding_assertions)
if(symex_config.unwinding_assertions)
{
// Generate VCC for unwinding assertion.
vcc(negated_cond,
Expand Down
20 changes: 18 additions & 2 deletions src/goto-symex/symex_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,26 @@ Author: Daniel Kroening, kroening@kroening.com
#include <util/make_unique.h>
#include <util/replace_symbol.h>
#include <util/std_expr.h>
#include <util/string2int.h>
#include <util/symbol_table.h>

#include <analyses/dirty.h>

symex_configt::symex_configt(const optionst &options)
: max_depth(options.get_unsigned_int_option("depth")),
doing_path_exploration(options.is_set("paths")),
allow_pointer_unsoundness(
options.get_bool_option("allow-pointer-unsoundness")),
constant_propagation(options.get_bool_option("propagation")),
self_loops_to_assumptions(
options.get_bool_option("self-loops-to-assumptions")),
simplify_opt(options.get_bool_option("simplify")),
unwinding_assertions(options.get_bool_option("unwinding-assertions")),
partial_loops(options.get_bool_option("partial-loops")),
debug_level(unsafe_string2int(options.get_option("debug-level")))
{
}

void symex_transition(
goto_symext::statet &state,
goto_programt::const_targett to,
Expand Down Expand Up @@ -317,11 +333,11 @@ void goto_symext::symex_step(

const goto_programt::instructiont &instruction=*state.source.pc;

if(!doing_path_exploration)
if(!symex_config.doing_path_exploration)
merge_gotos(state);

// depth exceeded?
if(max_depth != 0 && state.depth > max_depth)
if(symex_config.max_depth != 0 && state.depth > symex_config.max_depth)
state.guard.add(false_exprt());
state.depth++;

Expand Down