Skip to content

Commit c9bbd53

Browse files
committed
goto-symex interface: return symbol tables by value
Use copy elision instead of passing the desired return value by reference.
1 parent 49e246f commit c9bbd53

File tree

7 files changed

+36
-47
lines changed

7 files changed

+36
-47
lines changed

src/goto-checker/multi_path_symex_only_checker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ void multi_path_symex_only_checkert::generate_equation()
7676
{
7777
const auto symex_start = std::chrono::steady_clock::now();
7878

79-
symex.symex_from_entry_point_of(
80-
goto_symext::get_goto_function(goto_model), symex_symbol_table);
79+
symex_symbol_table =
80+
symex.symex_from_entry_point_of(goto_symext::get_goto_function(goto_model));
8181

8282
const auto symex_stop = std::chrono::steady_clock::now();
8383
std::chrono::duration<double> symex_runtime =

src/goto-checker/single_path_symex_only_checker.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,8 @@ bool single_path_symex_only_checkert::resume_path(path_storaget::patht &path)
101101
unwindset);
102102
setup_symex(symex);
103103

104-
symex.resume_symex_from_saved_state(
105-
goto_symext::get_goto_function(goto_model),
106-
path.state,
107-
&path.equation,
108-
symex_symbol_table);
104+
symex_symbol_table = symex.resume_symex_from_saved_state(
105+
goto_symext::get_goto_function(goto_model), path.state, &path.equation);
109106

110107
const auto symex_stop = std::chrono::steady_clock::now();
111108
symex_runtime += std::chrono::duration<double>(symex_stop - symex_start);

src/goto-checker/symex_bmc_incremental_one_loop.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ bool symex_bmc_incremental_one_loopt::from_entry_point_of(
128128
{
129129
state = initialize_entry_point_state(get_goto_function);
130130

131-
symex_with_state(*state, get_goto_function, new_symbol_table);
131+
new_symbol_table = symex_with_state(*state, get_goto_function);
132132

133133
return should_pause_symex;
134134
}
@@ -138,7 +138,7 @@ bool symex_bmc_incremental_one_loopt::resume(
138138
{
139139
should_pause_symex = false;
140140

141-
symex_with_state(*state, get_goto_function, state->symbol_table);
141+
state->symbol_table = symex_with_state(*state, get_goto_function);
142142

143143
return should_pause_symex;
144144
}

src/goto-instrument/accelerate/scratch_program.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool scratch_programt::check_sat(bool do_slice, guard_managert &guard_manager)
4747

4848
symex_state = symex.initialize_entry_point_state(get_goto_function);
4949

50-
symex.symex_with_state(*symex_state, get_goto_function, symex_symbol_table);
50+
symex_symbol_table = symex.symex_with_state(*symex_state, get_goto_function);
5151

5252
if(do_slice)
5353
{

src/goto-symex/goto_symex.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ class goto_symext
9898
/// having the state around afterwards.
9999
/// \param get_goto_function: The delegate to retrieve function bodies (see
100100
/// \ref get_goto_functiont)
101-
/// \param new_symbol_table: A symbol table to store the symbols added during
102-
/// symbolic execution
103-
virtual void symex_from_entry_point_of(
104-
const get_goto_functiont &get_goto_function,
105-
symbol_tablet &new_symbol_table);
101+
/// \return A symbol table holding the symbols added during symbolic
102+
/// execution.
103+
NODISCARD
104+
virtual symbol_tablet
105+
symex_from_entry_point_of(const get_goto_functiont &get_goto_function);
106106

107107
/// Puts the initial state of the entry point function into the path storage
108108
virtual void initialize_path_storage_from_entry_point_of(
@@ -117,13 +117,13 @@ class goto_symext
117117
/// \ref get_goto_functiont)
118118
/// \param saved_state: The symbolic execution state to resume from
119119
/// \param saved_equation: The equation as previously built up
120-
/// \param new_symbol_table: A symbol table to store the symbols added during
121-
/// symbolic execution
122-
virtual void resume_symex_from_saved_state(
120+
/// \return A symbol table holding the symbols added during symbolic
121+
/// execution.
122+
NODISCARD
123+
virtual symbol_tablet resume_symex_from_saved_state(
123124
const get_goto_functiont &get_goto_function,
124125
const statet &saved_state,
125-
symex_target_equationt *saved_equation,
126-
symbol_tablet &new_symbol_table);
126+
symex_target_equationt *saved_equation);
127127

128128
//// \brief Symbolically execute the entire program starting from entry point
129129
///
@@ -135,12 +135,11 @@ class goto_symext
135135
/// \param state: The symbolic execution state to use for the execution
136136
/// \param get_goto_functions: A functor to retrieve function bodies to
137137
/// execute
138-
/// \param new_symbol_table: A symbol table to store the symbols added during
139-
/// symbolic execution
140-
virtual void symex_with_state(
141-
statet &state,
142-
const get_goto_functiont &get_goto_functions,
143-
symbol_tablet &new_symbol_table);
138+
/// \return A symbol table holding the symbols added during symbolic
139+
/// execution.
140+
NODISCARD
141+
virtual symbol_tablet
142+
symex_with_state(statet &state, const get_goto_functiont &get_goto_functions);
144143

145144
/// \brief Set when states are pushed onto the workqueue
146145
/// If this flag is set at the end of a symbolic execution run, it means that

src/goto-symex/symex_main.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,9 @@ void goto_symext::symex_threaded_step(
321321
}
322322
}
323323

324-
void goto_symext::symex_with_state(
324+
symbol_tablet goto_symext::symex_with_state(
325325
statet &state,
326-
const get_goto_functiont &get_goto_function,
327-
symbol_tablet &new_symbol_table)
326+
const get_goto_functiont &get_goto_function)
328327
{
329328
// resets the namespace to only wrap a single symbol table, and does so upon
330329
// destruction of an object of this type; instantiating the type is thus all
@@ -361,28 +360,27 @@ void goto_symext::symex_with_state(
361360

362361
symex_threaded_step(state, get_goto_function);
363362
if(should_pause_symex)
364-
return;
363+
return state.symbol_table;
364+
365365
while(!state.call_stack().empty())
366366
{
367367
state.has_saved_jump_target = false;
368368
state.has_saved_next_instruction = false;
369369
symex_threaded_step(state, get_goto_function);
370370
if(should_pause_symex)
371-
return;
371+
return state.symbol_table;
372372
}
373373

374374
// Clients may need to construct a namespace with both the names in
375375
// the original goto-program and the names generated during symbolic
376376
// execution, so return the names generated through symbolic execution
377-
// through `new_symbol_table`.
378-
new_symbol_table = state.symbol_table;
377+
return state.symbol_table;
379378
}
380379

381-
void goto_symext::resume_symex_from_saved_state(
380+
symbol_tablet goto_symext::resume_symex_from_saved_state(
382381
const get_goto_functiont &get_goto_function,
383382
const statet &saved_state,
384-
symex_target_equationt *const saved_equation,
385-
symbol_tablet &new_symbol_table)
383+
symex_target_equationt *const saved_equation)
386384
{
387385
// saved_state contains a pointer to a symex_target_equationt that is
388386
// almost certainly stale. This is because equations are owned by bmcts,
@@ -394,10 +392,7 @@ void goto_symext::resume_symex_from_saved_state(
394392

395393
// Do NOT do the same initialization that `symex_with_state` does for a
396394
// fresh state, as that would clobber the saved state's program counter
397-
symex_with_state(
398-
state,
399-
get_goto_function,
400-
new_symbol_table);
395+
return symex_with_state(state, get_goto_function);
401396
}
402397

403398
std::unique_ptr<goto_symext::statet> goto_symext::initialize_entry_point_state(
@@ -467,13 +462,12 @@ std::unique_ptr<goto_symext::statet> goto_symext::initialize_entry_point_state(
467462
return state;
468463
}
469464

470-
void goto_symext::symex_from_entry_point_of(
471-
const get_goto_functiont &get_goto_function,
472-
symbol_tablet &new_symbol_table)
465+
symbol_tablet goto_symext::symex_from_entry_point_of(
466+
const get_goto_functiont &get_goto_function)
473467
{
474468
auto state = initialize_entry_point_state(get_goto_function);
475469

476-
symex_with_state(*state, get_goto_function, new_symbol_table);
470+
return symex_with_state(*state, get_goto_function);
477471
}
478472

479473
void goto_symext::initialize_path_storage_from_entry_point_of(

unit/path_strategies.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,10 @@ void _check_with_strategy(
446446
unwindset);
447447
setup_symex(symex, ns, options, ui_message_handler);
448448

449-
symex.resume_symex_from_saved_state(
449+
symex_symbol_table = symex.resume_symex_from_saved_state(
450450
goto_symext::get_goto_function(goto_model),
451451
resume.state,
452-
&resume.equation,
453-
symex_symbol_table);
452+
&resume.equation);
454453
postprocess_equation(
455454
symex, resume.equation, options, ns, ui_message_handler);
456455

0 commit comments

Comments
 (0)