Skip to content

Commit e343604

Browse files
Merge pull request #4109 from peterschrammel/refactor-path-storage
Refactor path storage
2 parents 7811855 + 5281fa6 commit e343604

13 files changed

+127
-228
lines changed

src/goto-checker/bmc_util.cpp

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void output_coverage_report(
302302
}
303303
}
304304

305-
static void postprocess_equation(
305+
void postprocess_equation(
306306
symex_bmct &symex,
307307
symex_target_equationt &equation,
308308
const optionst &options,
@@ -329,44 +329,3 @@ static void postprocess_equation(
329329
symex.validate(validation_modet::INVARIANT);
330330
}
331331
}
332-
333-
void perform_symex(
334-
abstract_goto_modelt &goto_model,
335-
symex_bmct &symex,
336-
symbol_tablet &symex_symbol_table,
337-
symex_target_equationt &equation,
338-
const optionst &options,
339-
const namespacet &ns,
340-
ui_message_handlert &ui_message_handler)
341-
{
342-
auto get_goto_function =
343-
[&goto_model](
344-
const irep_idt &id) -> const goto_functionst::goto_functiont & {
345-
return goto_model.get_goto_function(id);
346-
};
347-
348-
symex.symex_from_entry_point_of(get_goto_function, symex_symbol_table);
349-
350-
postprocess_equation(symex, equation, options, ns, ui_message_handler);
351-
}
352-
353-
void perform_symex(
354-
abstract_goto_modelt &goto_model,
355-
symex_bmct &symex,
356-
path_storaget::patht &resume,
357-
symbol_tablet &symex_symbol_table,
358-
const optionst &options,
359-
const namespacet &ns,
360-
ui_message_handlert &ui_message_handler)
361-
{
362-
auto get_goto_function =
363-
[&goto_model](
364-
const irep_idt &id) -> const goto_functionst::goto_functiont & {
365-
return goto_model.get_goto_function(id);
366-
};
367-
368-
symex.resume_symex_from_saved_state(
369-
get_goto_function, resume.state, &resume.equation, symex_symbol_table);
370-
371-
postprocess_equation(symex, resume.equation, options, ns, ui_message_handler);
372-
}

src/goto-checker/bmc_util.h

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,16 @@ void slice(
7070
const optionst &,
7171
ui_message_handlert &);
7272

73-
/// Perform symbolic execution from the entry point
74-
void perform_symex(
75-
abstract_goto_modelt &,
76-
symex_bmct &,
77-
symbol_tablet &,
78-
symex_target_equationt &,
79-
const optionst &,
80-
const namespacet &,
81-
ui_message_handlert &);
82-
83-
/// Perform symbolic execution starting from \p resume.
84-
void perform_symex(
85-
abstract_goto_modelt &,
86-
symex_bmct &,
87-
path_storaget::patht &resume,
88-
symbol_tablet &,
89-
const optionst &,
90-
const namespacet &,
91-
ui_message_handlert &);
73+
/// Post process the equation
74+
/// - add partial order constraints
75+
/// - slice
76+
/// - perform validation
77+
void postprocess_equation(
78+
symex_bmct &symex,
79+
symex_target_equationt &equation,
80+
const optionst &options,
81+
const namespacet &ns,
82+
ui_message_handlert &ui_message_handler);
9283

9384
/// Output a coverage report as generated by \ref symex_coveraget
9485
/// if \p cov_out is non-empty.

src/goto-checker/multi_path_symex_checker.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,9 @@ operator()(propertiest &properties)
4141
// we haven't got an equation yet
4242
if(!equation_generated)
4343
{
44-
perform_symex(
45-
goto_model,
46-
symex,
47-
symex_symbol_table,
48-
equation,
49-
options,
50-
ns,
51-
ui_message_handler);
44+
symex.symex_from_entry_point_of(
45+
goto_symext::get_goto_function(goto_model), symex_symbol_table);
46+
postprocess_equation(symex, equation, options, ns, ui_message_handler);
5247

5348
output_coverage_report(
5449
options.get_option("symex-coverage-report"),

src/goto-checker/multi_path_symex_only_checker.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,9 @@ multi_path_symex_only_checkert::multi_path_symex_only_checkert(
3939
incremental_goto_checkert::resultt multi_path_symex_only_checkert::
4040
operator()(propertiest &properties)
4141
{
42-
perform_symex(
43-
goto_model,
44-
symex,
45-
symex_symbol_table,
46-
equation,
47-
options,
48-
ns,
49-
ui_message_handler);
42+
symex.symex_from_entry_point_of(
43+
goto_symext::get_goto_function(goto_model), symex_symbol_table);
44+
postprocess_equation(symex, equation, options, ns, ui_message_handler);
5045

5146
output_coverage_report(
5247
options.get_option("symex-coverage-report"),

src/goto-checker/single_path_symex_checker.cpp

Lines changed: 27 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,6 @@ operator()(propertiest &properties)
3030
{
3131
resultt result(resultt::progresst::DONE);
3232

33-
// Unfortunately, the initial symex run is currently handled differently
34-
// from the subsequent runs
35-
if(!initial_symex_has_run)
36-
{
37-
initial_symex_has_run = true;
38-
first_equation = symex_target_equationt();
39-
symex_bmct symex(
40-
ui_message_handler,
41-
goto_model.get_symbol_table(),
42-
first_equation.value(),
43-
options,
44-
*worklist);
45-
46-
setup_symex(symex);
47-
perform_symex(
48-
goto_model,
49-
symex,
50-
symex_symbol_table,
51-
first_equation.value(),
52-
options,
53-
ns,
54-
ui_message_handler);
55-
56-
output_coverage_report(
57-
options.get_option("symex-coverage-report"),
58-
goto_model,
59-
symex,
60-
ui_message_handler);
61-
62-
if(symex.get_remaining_vccs() > 0)
63-
{
64-
prepare(result, properties, first_equation.value());
65-
decide(result, properties);
66-
67-
if(result.progress == resultt::progresst::FOUND_FAIL)
68-
return result;
69-
}
70-
}
71-
7233
// There might be more solutions from the previous equation.
7334
if(property_decider)
7435
{
@@ -77,24 +38,28 @@ operator()(propertiest &properties)
7738
return result;
7839
}
7940

80-
if(first_equation.has_value())
41+
if(!worklist->empty())
8142
{
82-
// We are in the second iteration. We don't need the equation
83-
// from the first iteration anymore.
84-
first_equation = {};
43+
// We pop the item processed in the previous iteration.
44+
worklist->pop();
8545
}
86-
else
46+
47+
if(!symex_initialized)
8748
{
88-
if(!worklist->empty())
89-
{
90-
// We are in iteration 3 or later; we pop the item processed
91-
// in the previous iteration.
92-
worklist->pop();
93-
}
94-
else
95-
{
96-
// We are already done.
97-
}
49+
symex_initialized = true;
50+
51+
// Put initial state into the work list
52+
symex_target_equationt equation;
53+
symex_bmct symex(
54+
ui_message_handler,
55+
goto_model.get_symbol_table(),
56+
equation,
57+
options,
58+
*worklist);
59+
setup_symex(symex);
60+
61+
symex.initialize_path_storage_from_entry_point_of(
62+
goto_symext::get_goto_function(goto_model), symex_symbol_table);
9863
}
9964

10065
while(!worklist->empty())
@@ -106,16 +71,15 @@ operator()(propertiest &properties)
10671
resume.equation,
10772
options,
10873
*worklist);
109-
11074
setup_symex(symex);
111-
perform_symex(
112-
goto_model,
113-
symex,
114-
resume,
115-
symex_symbol_table,
116-
options,
117-
ns,
118-
ui_message_handler);
75+
76+
symex.resume_symex_from_saved_state(
77+
goto_symext::get_goto_function(goto_model),
78+
resume.state,
79+
&resume.equation,
80+
symex_symbol_table);
81+
postprocess_equation(
82+
symex, resume.equation, options, ns, ui_message_handler);
11983

12084
output_coverage_report(
12185
options.get_option("symex-coverage-report"),

src/goto-checker/single_path_symex_checker.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class single_path_symex_checkert : public single_path_symex_only_checkert,
4343
virtual ~single_path_symex_checkert() = default;
4444

4545
protected:
46-
bool initial_symex_has_run = false;
47-
optionalt<symex_target_equationt> first_equation; // for building traces
46+
bool symex_initialized = false;
4847
std::unique_ptr<goto_symex_property_decidert> property_decider;
4948

5049
void prepare(

src/goto-checker/single_path_symex_only_checker.cpp

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,19 @@ operator()(propertiest &properties)
3737
{
3838
resultt result(resultt::progresst::DONE);
3939

40-
// First run goto-symex from entry point to initialize worklist
4140
{
42-
symex_target_equationt first_equation;
41+
// Put initial state into the work list
42+
symex_target_equationt equation;
4343
symex_bmct symex(
4444
ui_message_handler,
4545
goto_model.get_symbol_table(),
46-
first_equation,
46+
equation,
4747
options,
4848
*worklist);
49-
5049
setup_symex(symex);
51-
perform_symex(
52-
goto_model,
53-
symex,
54-
symex_symbol_table,
55-
first_equation,
56-
options,
57-
ns,
58-
ui_message_handler);
5950

60-
equation_output(symex, first_equation);
61-
update_properties_status_from_symex_target_equation(
62-
properties, result.updated_properties, first_equation);
51+
symex.initialize_path_storage_from_entry_point_of(
52+
goto_symext::get_goto_function(goto_model), symex_symbol_table);
6353
}
6454

6555
while(!worklist->empty())
@@ -71,17 +61,18 @@ operator()(propertiest &properties)
7161
resume.equation,
7262
options,
7363
*worklist);
74-
7564
setup_symex(symex);
76-
perform_symex(
77-
goto_model,
78-
symex,
79-
resume,
80-
symex_symbol_table,
81-
options,
82-
ns,
83-
ui_message_handler);
65+
66+
symex.resume_symex_from_saved_state(
67+
goto_symext::get_goto_function(goto_model),
68+
resume.state,
69+
&resume.equation,
70+
symex_symbol_table);
71+
postprocess_equation(
72+
symex, resume.equation, options, ns, ui_message_handler);
73+
8474
equation_output(symex, resume.equation);
75+
8576
update_properties_status_from_symex_target_equation(
8677
properties, result.updated_properties, resume.equation);
8778

src/goto-instrument/accelerate/scratch_program.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ bool scratch_programt::check_sat(bool do_slice)
3535
output(ns, "scratch", std::cout);
3636
#endif
3737

38-
symex.symex_with_state(symex_state, functions, symex_symbol_table);
38+
symex.symex_with_state(
39+
symex_state,
40+
[this](const irep_idt &key) -> const goto_functionst::goto_functiont & {
41+
return functions.function_map.at(key);
42+
},
43+
symex_symbol_table);
3944

4045
if(do_slice)
4146
{

src/goto-symex/goto_symex.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Author: Daniel Kroening, [email protected]
1515
#include <util/options.h>
1616
#include <util/message.h>
1717

18-
#include <goto-programs/goto_functions.h>
18+
#include <goto-programs/abstract_goto_model.h>
1919

2020
#include "goto_symex_state.h"
2121
#include "path_storage.h"
@@ -97,6 +97,9 @@ class goto_symext
9797
std::function<const goto_functionst::goto_functiont &(const irep_idt &)>
9898
get_goto_functiont;
9999

100+
/// Return a function to get/load a goto function from the given goto model
101+
static get_goto_functiont get_goto_function(abstract_goto_modelt &);
102+
100103
/// \brief symex entire program starting from entry point
101104
///
102105
/// The state that goto_symext maintains has a large memory footprint.
@@ -107,6 +110,11 @@ class goto_symext
107110
const get_goto_functiont &get_goto_function,
108111
symbol_tablet &new_symbol_table);
109112

113+
/// Puts the initial state of the entry point function into the path storage
114+
virtual void initialize_path_storage_from_entry_point_of(
115+
const get_goto_functiont &get_goto_function,
116+
symbol_tablet &new_symbol_table);
117+
110118
/// Performs symbolic execution using a state and equation that have
111119
/// already been used to symex part of the program. The state is not
112120
/// re-initialized; instead, symbolic execution resumes from the program
@@ -117,18 +125,6 @@ class goto_symext
117125
symex_target_equationt *saved_equation,
118126
symbol_tablet &new_symbol_table);
119127

120-
//// \brief symex entire program starting from entry point
121-
///
122-
/// This method uses the `state` argument as the symbolic execution
123-
/// state, which is useful for examining the state after this method
124-
/// returns. The state that goto_symext maintains has a large memory
125-
/// footprint, so if keeping the state around is not necessary,
126-
/// clients should instead call goto_symext::symex_from_entry_point_of().
127-
virtual void symex_with_state(
128-
statet &,
129-
const goto_functionst &,
130-
symbol_tablet &);
131-
132128
//// \brief symex entire program starting from entry point
133129
///
134130
/// This method uses the `state` argument as the symbolic execution
@@ -168,6 +164,14 @@ class goto_symext
168164
goto_programt::const_targett pc,
169165
goto_programt::const_targett limit);
170166

167+
/// Initialize the symbolic execution and the given state with
168+
/// the beginning of the entry point function.
169+
/// \param get_goto_function: producer for GOTO functions
170+
/// \param state: Symex state to initialize.
171+
void initialize_entry_point_state(
172+
const get_goto_functiont &get_goto_function,
173+
statet &state);
174+
171175
/// Invokes symex_step and verifies whether additional threads can be
172176
/// executed.
173177
/// \param state: Current GOTO symex step.

0 commit comments

Comments
 (0)