Skip to content

Commit e823538

Browse files
committed
Symex paths saved onto abstract data structure
This commit introduces a new data type, path_queuet, representing saved symbolic execution paths, used instead of the std::list. This allows us to implement custom logic for saving and removing paths, rather than simply pushing to the back and popping the front. This commit introduces a concrete instantiation of path_queuet, called path_fifot, with the same functionality as the old std::list. This is in preparation for further instantiations that implement more sophisticated logic for deciding which path should be resumed next.
1 parent 48f1af3 commit e823538

File tree

10 files changed

+163
-53
lines changed

10 files changed

+163
-53
lines changed

src/cbmc/bmc.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,8 @@ int bmct::do_language_agnostic_bmc(
605605
const symbol_tablet &symbol_table = model.get_symbol_table();
606606
message_handlert &mh = message.get_message_handler();
607607
safety_checkert::resultt result;
608-
goto_symext::branch_worklistt worklist;
608+
std::unique_ptr<path_storaget> worklist =
609+
path_storaget::make(path_storaget::disciplinet::FIFO);
609610
try
610611
{
611612
{
@@ -614,17 +615,17 @@ int bmct::do_language_agnostic_bmc(
614615
std::unique_ptr<cbmc_solverst::solvert> cbmc_solver;
615616
cbmc_solver = solvers.get_solver();
616617
prop_convt &pc = cbmc_solver->prop_conv();
617-
bmct bmc(opts, symbol_table, mh, pc, worklist, callback_after_symex);
618+
bmct bmc(opts, symbol_table, mh, pc, *worklist, callback_after_symex);
618619
bmc.set_ui(ui);
619620
if(driver_configure_bmc)
620621
driver_configure_bmc(bmc, symbol_table);
621622
result = bmc.run(model);
622623
}
623624
INVARIANT(
624-
opts.get_bool_option("paths") || worklist.empty(),
625+
opts.get_bool_option("paths") || worklist->empty(),
625626
"the worklist should be empty after doing full-program "
626627
"model checking, but the worklist contains " +
627-
std::to_string(worklist.size()) + " unexplored branches.");
628+
std::to_string(worklist->size()) + " unexplored branches.");
628629

629630
// When model checking, the bmc.run() above will already have explored
630631
// the entire program, and result contains the verification result. The
@@ -641,31 +642,31 @@ int bmct::do_language_agnostic_bmc(
641642
// difference between the implementations of perform_symbolic_exection()
642643
// in bmct and path_explorert, for more information.
643644

644-
while(!worklist.empty())
645+
while(!worklist->empty())
645646
{
646647
message.status() << "___________________________\n"
647-
<< "Starting new path (" << worklist.size()
648+
<< "Starting new path (" << worklist->size()
648649
<< " to go)\n"
649650
<< message.eom;
650651
cbmc_solverst solvers(opts, symbol_table, message.get_message_handler());
651652
solvers.set_ui(ui);
652653
std::unique_ptr<cbmc_solverst::solvert> cbmc_solver;
653654
cbmc_solver = solvers.get_solver();
654655
prop_convt &pc = cbmc_solver->prop_conv();
655-
goto_symext::branch_pointt &resume = worklist.front();
656+
path_storaget::patht &resume = worklist->peek();
656657
path_explorert pe(
657658
opts,
658659
symbol_table,
659660
mh,
660661
pc,
661662
resume.equation,
662663
resume.state,
663-
worklist,
664+
*worklist,
664665
callback_after_symex);
665666
if(driver_configure_bmc)
666667
driver_configure_bmc(pe, symbol_table);
667668
result &= pe.run(model);
668-
worklist.pop_front();
669+
worklist->pop();
669670
}
670671
}
671672
catch(const char *error_msg)
@@ -701,7 +702,7 @@ void bmct::perform_symbolic_execution(
701702
{
702703
symex.symex_from_entry_point_of(get_goto_function, symex_symbol_table);
703704
INVARIANT(
704-
options.get_bool_option("paths") || branch_worklist.empty(),
705+
options.get_bool_option("paths") || path_storage.empty(),
705706
"Branch points were saved even though we should have been "
706707
"executing the entire program and merging paths");
707708
}

src/cbmc/bmc.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Author: Daniel Kroening, [email protected]
2323
#include <goto-programs/goto_trace.h>
2424

2525
#include <goto-symex/symex_target_equation.h>
26+
#include <goto-symex/path_storage.h>
27+
2628
#include <goto-programs/goto_model.h>
2729
#include <goto-programs/safety_checker.h>
2830
#include <goto-symex/memory_model.h>
@@ -49,32 +51,32 @@ class bmct:public safety_checkert
4951
/// constructor is `false` (unset), an instance of this class will
5052
/// symbolically execute the entire program, performing path merging
5153
/// to build a formula corresponding to all executions of the program
52-
/// up to the unwinding limit. In this case, the `branch_worklist`
54+
/// up to the unwinding limit. In this case, the `path_storage`
5355
/// member shall not be touched; this is enforced by the assertion in
5456
/// this class' implementation of bmct::perform_symbolic_execution().
5557
///
5658
/// - If the `--paths` flag is `true`, this `bmct` object will explore a
5759
/// single path through the codebase without doing any path merging.
5860
/// If some paths were not taken, the state at those branch points
59-
/// will be appended to `branch_worklist`. After the single path that
61+
/// will be appended to `path_storage`. After the single path that
6062
/// this `bmct` object executed has been model-checked, you can resume
6163
/// exploring further paths by popping an element from
62-
/// `branch_worklist` and using it to construct a path_explorert
64+
/// `path_storage` and using it to construct a path_explorert
6365
/// object.
6466
bmct(
6567
const optionst &_options,
6668
const symbol_tablet &outer_symbol_table,
6769
message_handlert &_message_handler,
6870
prop_convt &_prop_conv,
69-
goto_symext::branch_worklistt &_branch_worklist,
71+
path_storaget &_path_storage,
7072
std::function<bool(void)> callback_after_symex)
7173
: safety_checkert(ns, _message_handler),
7274
options(_options),
7375
outer_symbol_table(outer_symbol_table),
7476
ns(outer_symbol_table, symex_symbol_table),
7577
equation(),
76-
branch_worklist(_branch_worklist),
77-
symex(_message_handler, outer_symbol_table, equation, branch_worklist),
78+
path_storage(_path_storage),
79+
symex(_message_handler, outer_symbol_table, equation, path_storage),
7880
prop_conv(_prop_conv),
7981
ui(ui_message_handlert::uit::PLAIN),
8082
driver_callback_after_symex(callback_after_symex)
@@ -128,7 +130,7 @@ class bmct:public safety_checkert
128130
///
129131
/// This constructor exists as a delegate for the path_explorert class.
130132
/// It differs from \ref bmct's public constructor in that it actually
131-
/// does something with the branch_worklistt argument, and also takes a
133+
/// does something with the path_storaget argument, and also takes a
132134
/// symex_target_equationt. See the documentation for path_explorert for
133135
/// details.
134136
bmct(
@@ -137,15 +139,15 @@ class bmct:public safety_checkert
137139
message_handlert &_message_handler,
138140
prop_convt &_prop_conv,
139141
symex_target_equationt &_equation,
140-
goto_symext::branch_worklistt &_branch_worklist,
142+
path_storaget &_path_storage,
141143
std::function<bool(void)> callback_after_symex)
142144
: safety_checkert(ns, _message_handler),
143145
options(_options),
144146
outer_symbol_table(outer_symbol_table),
145147
ns(outer_symbol_table),
146148
equation(_equation),
147-
branch_worklist(_branch_worklist),
148-
symex(_message_handler, outer_symbol_table, equation, branch_worklist),
149+
path_storage(_path_storage),
150+
symex(_message_handler, outer_symbol_table, equation, path_storage),
149151
prop_conv(_prop_conv),
150152
ui(ui_message_handlert::uit::PLAIN),
151153
driver_callback_after_symex(callback_after_symex)
@@ -166,7 +168,7 @@ class bmct:public safety_checkert
166168
symbol_tablet symex_symbol_table;
167169
namespacet ns;
168170
symex_target_equationt equation;
169-
goto_symext::branch_worklistt &branch_worklist;
171+
path_storaget &path_storage;
170172
symex_bmct symex;
171173
prop_convt &prop_conv;
172174
std::unique_ptr<memory_model_baset> memory_model;
@@ -257,15 +259,15 @@ class path_explorert : public bmct
257259
prop_convt &_prop_conv,
258260
symex_target_equationt &saved_equation,
259261
const goto_symex_statet &saved_state,
260-
goto_symext::branch_worklistt &branch_worklist,
262+
path_storaget &path_storage,
261263
std::function<bool(void)> callback_after_symex)
262264
: bmct(
263265
_options,
264266
outer_symbol_table,
265267
_message_handler,
266268
_prop_conv,
267269
saved_equation,
268-
branch_worklist,
270+
path_storage,
269271
callback_after_symex),
270272
saved_state(saved_state)
271273
{

src/cbmc/symex_bmc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ symex_bmct::symex_bmct(
2222
message_handlert &mh,
2323
const symbol_tablet &outer_symbol_table,
2424
symex_target_equationt &_target,
25-
goto_symext::branch_worklistt &branch_worklist)
26-
: goto_symext(mh, outer_symbol_table, _target, branch_worklist),
25+
path_storaget &path_storage)
26+
: goto_symext(mh, outer_symbol_table, _target, path_storage),
2727
record_coverage(false),
2828
max_unwind(0),
2929
max_unwind_is_set(false),

src/cbmc/symex_bmc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected]
1515
#include <util/message.h>
1616
#include <util/threeval.h>
1717

18+
#include <goto-symex/path_storage.h>
1819
#include <goto-symex/goto_symex.h>
1920

2021
#include "symex_coverage.h"
@@ -26,7 +27,7 @@ class symex_bmct: public goto_symext
2627
message_handlert &mh,
2728
const symbol_tablet &outer_symbol_table,
2829
symex_target_equationt &_target,
29-
goto_symext::branch_worklistt &branch_worklist);
30+
path_storaget &path_storage);
3031

3132
// To show progress
3233
source_locationt last_source_location;

src/goto-instrument/accelerate/scratch_program.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Author: Matt Lewis
2323
#include <goto-programs/goto_functions.h>
2424

2525
#include <goto-symex/goto_symex.h>
26+
#include <goto-symex/path_storage.h>
2627
#include <goto-symex/symex_target_equation.h>
2728

2829
#include <solvers/smt2/smt2_dec.h>
@@ -41,8 +42,8 @@ class scratch_programt:public goto_programt
4142
symex_symbol_table(),
4243
ns(symbol_table, symex_symbol_table),
4344
equation(),
44-
branch_worklist(),
45-
symex(mh, symbol_table, equation, branch_worklist),
45+
path_storage(),
46+
symex(mh, symbol_table, equation, path_storage),
4647
satcheck(util_make_unique<satcheckt>()),
4748
satchecker(ns, *satcheck),
4849
z3(ns, "accelerate", "", "", smt2_dect::solvert::Z3),
@@ -78,7 +79,7 @@ class scratch_programt:public goto_programt
7879
symbol_tablet symex_symbol_table;
7980
namespacet ns;
8081
symex_target_equationt equation;
81-
goto_symext::branch_worklistt branch_worklist;
82+
path_fifot path_storage;
8283
goto_symext symex;
8384

8485
std::unique_ptr<propt> satcheck;

src/goto-symex/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ SRC = adjust_float_expressions.cpp \
88
memory_model_sc.cpp \
99
memory_model_tso.cpp \
1010
partial_order_concurrency.cpp \
11+
path_storage.cpp \
1112
postcondition.cpp \
1213
precondition.cpp \
1314
rewrite_union.cpp \

src/goto-symex/goto_symex.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected]
1818
#include <goto-programs/goto_functions.h>
1919

2020
#include "goto_symex_state.h"
21+
#include "path_storage.h"
2122
#include "symex_target_equation.h"
2223

2324
class byte_extract_exprt;
@@ -47,30 +48,11 @@ class goto_symext
4748
public:
4849
typedef goto_symex_statet statet;
4950

50-
/// \brief Information saved at a conditional goto to resume execution
51-
struct branch_pointt
52-
{
53-
symex_target_equationt equation;
54-
statet state;
55-
56-
explicit branch_pointt(const symex_target_equationt &e, const statet &s)
57-
: equation(e), state(s, &equation)
58-
{
59-
}
60-
61-
explicit branch_pointt(const branch_pointt &other)
62-
: equation(other.equation), state(other.state, &equation)
63-
{
64-
}
65-
};
66-
67-
typedef std::list<branch_pointt> branch_worklistt;
68-
6951
goto_symext(
7052
message_handlert &mh,
7153
const symbol_tablet &outer_symbol_table,
7254
symex_target_equationt &_target,
73-
branch_worklistt &branch_worklist)
55+
path_storaget &path_storage)
7456
: total_vccs(0),
7557
remaining_vccs(0),
7658
constant_propagation(true),
@@ -81,7 +63,7 @@ class goto_symext
8163
atomic_section_counter(0),
8264
log(mh),
8365
guard_identifier("goto_symex::\\guard"),
84-
branch_worklist(branch_worklist)
66+
path_storage(path_storage)
8567
{
8668
options.set_option("simplify", true);
8769
options.set_option("assertions", true);
@@ -462,7 +444,7 @@ class goto_symext
462444
void replace_nondet(exprt &);
463445
void rewrite_quantifiers(exprt &, statet &);
464446

465-
branch_worklistt &branch_worklist;
447+
path_storaget &path_storage;
466448
};
467449

468450
#endif // CPROVER_GOTO_SYMEX_GOTO_SYMEX_H

src/goto-symex/path_storage.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*******************************************************************\
2+
3+
Module: Path Storage
4+
5+
Author: Kareem Khazem <[email protected]>
6+
7+
\*******************************************************************/
8+
9+
#include "path_storage.h"
10+
11+
std::unique_ptr<path_storaget>
12+
path_storaget::make(path_storaget::disciplinet discipline)
13+
{
14+
switch(discipline)
15+
{
16+
case path_storaget::disciplinet::FIFO:
17+
return std::unique_ptr<path_fifot>(new path_fifot());
18+
}
19+
UNREACHABLE;
20+
}
21+
22+
path_storaget::patht &path_fifot::peek()
23+
{
24+
return paths.front();
25+
}
26+
27+
void path_fifot::push(const path_storaget::patht &bp)
28+
{
29+
paths.push_back(bp);
30+
}
31+
32+
void path_fifot::pop()
33+
{
34+
paths.pop_front();
35+
}
36+
37+
std::size_t path_fifot::size() const
38+
{
39+
return paths.size();
40+
}

0 commit comments

Comments
 (0)