Skip to content

Commit 178c6d8

Browse files
Put initial state into path_storage
Allows us to perform the actual pathwise symex work in a uniform way. Required making path_storaget::push accept a single state.
1 parent 55302b7 commit 178c6d8

File tree

5 files changed

+48
-28
lines changed

5 files changed

+48
-28
lines changed

src/goto-symex/goto_symex.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ class goto_symext
107107
const get_goto_functiont &get_goto_function,
108108
symbol_tablet &new_symbol_table);
109109

110+
/// Puts the initial state of the entry point function into the path storage
111+
virtual void initialize_path_storage_from_entry_point_of(
112+
const get_goto_functiont &get_goto_function,
113+
symbol_tablet &new_symbol_table);
114+
110115
/// Performs symbolic execution using a state and equation that have
111116
/// already been used to symex part of the program. The state is not
112117
/// re-initialized; instead, symbolic execution resumes from the program
@@ -168,6 +173,14 @@ class goto_symext
168173
goto_programt::const_targett pc,
169174
goto_programt::const_targett limit);
170175

176+
/// Initialize the symbolic execution and the given state with
177+
/// the beginning of the entry point function.
178+
/// \param get_goto_function: producer for GOTO functions
179+
/// \param state: Symex state to initialize.
180+
void initialize_entry_point_state(
181+
const get_goto_functiont &get_goto_function,
182+
statet &state);
183+
171184
/// Invokes symex_step and verifies whether additional threads can be
172185
/// executed.
173186
/// \param state: Current GOTO symex step.

src/goto-symex/path_storage.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ path_storaget::patht &path_lifot::private_peek()
2929
return paths.back();
3030
}
3131

32-
void path_lifot::push(
33-
const path_storaget::patht &next_instruction,
34-
const path_storaget::patht &jump_target)
32+
void path_lifot::push(const path_storaget::patht &path)
3533
{
36-
paths.push_back(next_instruction);
37-
paths.push_back(jump_target);
34+
paths.push_back(path);
3835
}
3936

4037
void path_lifot::private_pop()
@@ -62,12 +59,9 @@ path_storaget::patht &path_fifot::private_peek()
6259
return paths.front();
6360
}
6461

65-
void path_fifot::push(
66-
const path_storaget::patht &next_instruction,
67-
const path_storaget::patht &jump_target)
62+
void path_fifot::push(const path_storaget::patht &path)
6863
{
69-
paths.push_back(next_instruction);
70-
paths.push_back(jump_target);
64+
paths.push_back(path);
7165
}
7266

7367
void path_fifot::private_pop()

src/goto-symex/path_storage.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,8 @@ class path_storaget
6868
/// that check that the worklist is always empty when symex finishes.
6969
virtual void clear() = 0;
7070

71-
/// \brief Add paths to resume to the storage
72-
///
73-
/// Symbolic execution is suspended when we reach a conditional goto
74-
/// instruction with two successors. Thus, we always add a pair of paths to
75-
/// the path storage.
76-
///
77-
/// \param next_instruction: the instruction following the goto instruction
78-
/// \param jump_target: the target instruction of the goto instruction
79-
virtual void
80-
push(const patht &next_instruction, const patht &jump_target) = 0;
71+
/// \brief Add a path to resume to the storage
72+
virtual void push(const patht &) = 0;
8173

8274
/// \brief Remove the next path to resume from the storage
8375
void pop()
@@ -109,7 +101,7 @@ class path_storaget
109101
class path_lifot : public path_storaget
110102
{
111103
public:
112-
void push(const patht &, const patht &) override;
104+
void push(const patht &) override;
113105
std::size_t size() const override;
114106
void clear() override;
115107

@@ -126,7 +118,7 @@ class path_lifot : public path_storaget
126118
class path_fifot : public path_storaget
127119
{
128120
public:
129-
void push(const patht &, const patht &) override;
121+
void push(const patht &) override;
130122
std::size_t size() const override;
131123
void clear() override;
132124

src/goto-symex/symex_goto.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ void goto_symext::symex_goto(statet &state)
207207
log.debug() << "Saving jump target '"
208208
<< jump_target.state.saved_target->source_location << "'"
209209
<< log.eom;
210-
path_storage.push(next_instruction, jump_target);
210+
path_storage.push(next_instruction);
211+
path_storage.push(jump_target);
211212

212213
// It is now up to the caller of symex to decide which path to continue
213214
// executing. Signal to the caller that states have been pushed (therefore

src/goto-symex/symex_main.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ void goto_symext::resume_symex_from_saved_state(
325325
new_symbol_table);
326326
}
327327

328-
void goto_symext::symex_from_entry_point_of(
328+
void goto_symext::initialize_entry_point_state(
329329
const get_goto_functiont &get_goto_function,
330-
symbol_tablet &new_symbol_table)
330+
statet &state)
331331
{
332332
const goto_functionst::goto_functiont *start_function;
333333
try
@@ -339,21 +339,41 @@ void goto_symext::symex_from_entry_point_of(
339339
throw unsupported_operation_exceptiont("the program has no entry point");
340340
}
341341

342-
statet state;
343-
344342
state.run_validation_checks = symex_config.run_validation_checks;
345343

346344
initialize_entry_point(
347345
state,
348346
get_goto_function,
349347
goto_functionst::entry_point(),
350348
start_function->body.instructions.begin(),
351-
prev(start_function->body.instructions.end()));
349+
std::prev(start_function->body.instructions.end()));
350+
}
351+
352+
void goto_symext::symex_from_entry_point_of(
353+
const get_goto_functiont &get_goto_function,
354+
symbol_tablet &new_symbol_table)
355+
{
356+
statet state;
357+
initialize_entry_point_state(get_goto_function, state);
352358

353359
symex_with_state(
354360
state, get_goto_function, new_symbol_table);
355361
}
356362

363+
void goto_symext::initialize_path_storage_from_entry_point_of(
364+
const get_goto_functiont &get_goto_function,
365+
symbol_tablet &new_symbol_table)
366+
{
367+
statet state;
368+
initialize_entry_point_state(get_goto_function, state);
369+
370+
path_storaget::patht entry_point_start(target, state);
371+
entry_point_start.state.saved_target = state.source.pc;
372+
entry_point_start.state.has_saved_next_instruction = true;
373+
374+
path_storage.push(entry_point_start);
375+
}
376+
357377
/// do just one step
358378
void goto_symext::symex_step(
359379
const get_goto_functiont &get_goto_function,

0 commit comments

Comments
 (0)