Skip to content

Commit 10edd29

Browse files
Merge pull request #3371 from romainbrenguier/refactor/symex-part1
Refactor in symex
2 parents a23797b + 1f9aa83 commit 10edd29

12 files changed

+48
-174
lines changed

src/cbmc/symex_bmc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void symex_bmct::merge_goto(
105105
symex_coverage.covered(prev_pc, state.source.pc);
106106
}
107107

108-
bool symex_bmct::get_unwind(
108+
bool symex_bmct::should_stop_unwind(
109109
const symex_targett::sourcet &source,
110110
const goto_symex_statet::call_stackt &context,
111111
unsigned unwind)

src/cbmc/symex_bmc.h

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,23 @@ class symex_bmct: public goto_symext
9292
/// recursive call
9393
std::vector<recursion_unwind_handlert> recursion_unwind_handlers;
9494

95-
//
96-
// overloaded from goto_symext
97-
//
98-
virtual void symex_step(
99-
const get_goto_functiont &get_goto_function,
100-
statet &state);
101-
102-
virtual void merge_goto(
103-
const statet::goto_statet &goto_state,
104-
statet &state);
105-
106-
// for loop unwinding
107-
virtual bool get_unwind(
95+
void symex_step(const get_goto_functiont &get_goto_function, statet &state)
96+
override;
97+
98+
void
99+
merge_goto(const statet::goto_statet &goto_state, statet &state) override;
100+
101+
bool should_stop_unwind(
108102
const symex_targett::sourcet &source,
109103
const goto_symex_statet::call_stackt &context,
110-
unsigned unwind);
104+
unsigned unwind) override;
111105

112-
virtual bool get_unwind_recursion(
106+
bool get_unwind_recursion(
113107
const irep_idt &identifier,
114108
const unsigned thread_nr,
115-
unsigned unwind);
109+
unsigned unwind) override;
116110

117-
virtual void no_body(const irep_idt &identifier);
111+
void no_body(const irep_idt &identifier) override;
118112

119113
std::unordered_set<irep_idt> body_warnings;
120114

src/goto-symex/goto_symex.h

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,12 @@ class goto_symext
8080
{
8181
}
8282

83-
virtual ~goto_symext()
84-
{
85-
}
83+
virtual ~goto_symext() = default;
8684

8785
typedef
8886
std::function<const goto_functionst::goto_functiont &(const irep_idt &)>
8987
get_goto_functiont;
9088

91-
/// \brief symex entire program starting from entry point
92-
///
93-
/// The state that goto_symext maintains has a large memory footprint.
94-
/// This method deallocates the state as soon as symbolic execution
95-
/// has completed, so use it if you don't care about having the state
96-
/// around afterwards.
97-
virtual void symex_from_entry_point_of(
98-
const goto_functionst &goto_functions,
99-
symbol_tablet &new_symbol_table);
100-
10189
/// \brief symex entire program starting from entry point
10290
///
10391
/// The state that goto_symext maintains has a large memory footprint.
@@ -115,7 +103,7 @@ class goto_symext
115103
virtual void resume_symex_from_saved_state(
116104
const get_goto_functiont &get_goto_function,
117105
const statet &saved_state,
118-
symex_target_equationt *const saved_equation,
106+
symex_target_equationt *saved_equation,
119107
symbol_tablet &new_symbol_table);
120108

121109
//// \brief symex entire program starting from entry point
@@ -142,38 +130,6 @@ class goto_symext
142130
const get_goto_functiont &,
143131
symbol_tablet &);
144132

145-
/// Symexes from the first instruction and the given state, terminating as
146-
/// soon as the last instruction is reached. This is useful to explicitly
147-
/// symex certain ranges of a program, e.g. in an incremental decision
148-
/// procedure.
149-
/// \param state Symex state to start with.
150-
/// \param goto_functions GOTO model to symex.
151-
/// \param function_identifier The function with the instruction range
152-
/// \param first Entry point in form of a first instruction.
153-
/// \param limit Final instruction, which itself will not be symexed.
154-
virtual void symex_instruction_range(
155-
statet &,
156-
const goto_functionst &,
157-
const irep_idt &function_identifier,
158-
goto_programt::const_targett first,
159-
goto_programt::const_targett limit);
160-
161-
/// Symexes from the first instruction and the given state, terminating as
162-
/// soon as the last instruction is reached. This is useful to explicitly
163-
/// symex certain ranges of a program, e.g. in an incremental decision
164-
/// procedure.
165-
/// \param state Symex state to start with.
166-
/// \param get_goto_function retrieves a function body
167-
/// \param function_identifier The function with the instruction range
168-
/// \param first Entry point in form of a first instruction.
169-
/// \param limit Final instruction, which itself will not be symexed.
170-
virtual void symex_instruction_range(
171-
statet &state,
172-
const get_goto_functiont &get_goto_function,
173-
const irep_idt &function_identifier,
174-
goto_programt::const_targett first,
175-
goto_programt::const_targett limit);
176-
177133
/// \brief Have states been pushed onto the workqueue?
178134
///
179135
/// If this flag is set at the end of a symbolic execution run, it means that
@@ -215,8 +171,6 @@ class goto_symext
215171
const bool allow_pointer_unsoundness;
216172

217173
public:
218-
// these bypass the target maps
219-
virtual void symex_step_goto(statet &, bool taken);
220174

221175
/// language_mode: ID_java, ID_C or another language identifier
222176
/// if we know the source language in use, irep_idt() otherwise.
@@ -263,13 +217,9 @@ class goto_symext
263217
void initialize_auto_object(const exprt &, statet &);
264218
void process_array_expr(exprt &);
265219
exprt make_auto_object(const typet &, statet &);
266-
virtual void dereference(exprt &, statet &, const bool write);
220+
virtual void dereference(exprt &, statet &, bool write);
267221

268-
void dereference_rec(
269-
exprt &,
270-
statet &,
271-
guardt &,
272-
const bool write);
222+
void dereference_rec(exprt &, statet &, guardt &, bool write);
273223

274224
void dereference_rec_address_of(
275225
exprt &,
@@ -292,13 +242,13 @@ class goto_symext
292242
virtual void symex_transition(
293243
statet &,
294244
goto_programt::const_targett to,
295-
bool is_backwards_goto=false);
245+
bool is_backwards_goto);
296246

297247
virtual void symex_transition(statet &state)
298248
{
299249
goto_programt::const_targett next=state.source.pc;
300250
++next;
301-
symex_transition(state, next);
251+
symex_transition(state, next, false);
302252
}
303253

304254
virtual void symex_goto(statet &);
@@ -334,7 +284,7 @@ class goto_symext
334284

335285
// determine whether to unwind a loop -- true indicates abort,
336286
// with false we continue.
337-
virtual bool get_unwind(
287+
virtual bool should_stop_unwind(
338288
const symex_targett::sourcet &source,
339289
const goto_symex_statet::call_stackt &context,
340290
unsigned unwind);
@@ -369,24 +319,20 @@ class goto_symext
369319

370320
virtual bool get_unwind_recursion(
371321
const irep_idt &identifier,
372-
const unsigned thread_nr,
322+
unsigned thread_nr,
373323
unsigned unwind);
374324

375325
void parameter_assignments(
376-
const irep_idt function_identifier,
326+
const irep_idt &function_identifier,
377327
const goto_functionst::goto_functiont &,
378328
statet &,
379329
const exprt::operandst &arguments);
380330

381331
void locality(
382-
const irep_idt function_identifier,
332+
const irep_idt &function_identifier,
383333
statet &,
384334
const goto_functionst::goto_functiont &);
385335

386-
void add_end_of_function(
387-
exprt &code,
388-
const irep_idt &identifier);
389-
390336
nondet_symbol_exprt build_symex_nondet(typet &type);
391337

392338
// exceptions
@@ -471,7 +417,6 @@ class goto_symext
471417
static unsigned nondet_count;
472418
static unsigned dynamic_counter;
473419

474-
void read(exprt &);
475420
void replace_nondet(exprt &);
476421
void rewrite_quantifiers(exprt &, statet &);
477422

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ void goto_symext::symex_allocate(
177177
}
178178
else
179179
{
180-
exprt nondet = build_symex_nondet(object_type);
181-
code_assignt assignment(value_symbol.symbol_expr(), nondet);
180+
const exprt nondet = build_symex_nondet(object_type);
181+
const code_assignt assignment(value_symbol.symbol_expr(), nondet);
182182
symex_assign(state, assignment);
183183
}
184184

src/goto-symex/symex_dereference_state.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,10 @@ class symex_dereference_statet:
3232
goto_symext &goto_symex;
3333
goto_symext::statet &state;
3434

35-
virtual void get_value_set(
36-
const exprt &expr,
37-
value_setst::valuest &value_set);
35+
void
36+
get_value_set(const exprt &expr, value_setst::valuest &value_set) override;
3837

39-
virtual bool has_failed_symbol(
40-
const exprt &expr,
41-
const symbolt *&symbol);
38+
bool has_failed_symbol(const exprt &expr, const symbolt *&symbol) override;
4239
};
4340

4441
#endif // CPROVER_GOTO_SYMEX_SYMEX_DEREFERENCE_STATE_H

src/goto-symex/symex_function_call.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool goto_symext::get_unwind_recursion(
2727
}
2828

2929
void goto_symext::parameter_assignments(
30-
const irep_idt function_identifier,
30+
const irep_idt &function_identifier,
3131
const goto_functionst::goto_functiont &goto_function,
3232
statet &state,
3333
const exprt::operandst &arguments)
@@ -311,7 +311,7 @@ void goto_symext::symex_function_call_code(
311311

312312
state.source.is_set=true;
313313
state.source.function = identifier;
314-
symex_transition(state, goto_function.body.instructions.begin());
314+
symex_transition(state, goto_function.body.instructions.begin(), false);
315315
}
316316

317317
/// pop one call frame
@@ -323,7 +323,7 @@ void goto_symext::pop_frame(statet &state)
323323
statet::framet &frame=state.top();
324324

325325
// restore program counter
326-
symex_transition(state, frame.calling_location.pc);
326+
symex_transition(state, frame.calling_location.pc, false);
327327
state.source.function = frame.calling_location.function;
328328

329329
// restore L1 renaming
@@ -368,7 +368,7 @@ void goto_symext::symex_end_of_function(statet &state)
368368
/// preserves locality of local variables of a given function by applying L1
369369
/// renaming to the local identifiers
370370
void goto_symext::locality(
371-
const irep_idt function_identifier,
371+
const irep_idt &function_identifier,
372372
statet &state,
373373
const goto_functionst::goto_functiont &goto_function)
374374
{

0 commit comments

Comments
 (0)