Skip to content

Commit 8a75ce4

Browse files
Merge pull request #3445 from romainbrenguier/refactor/symex-part4
Goto symex state clean-up
2 parents f5f870b + 27b4b03 commit 8a75ce4

File tree

5 files changed

+36
-80
lines changed

5 files changed

+36
-80
lines changed

src/goto-symex/goto_symex_state.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -407,23 +407,20 @@ bool goto_symex_statet::l2_thread_read_encoding(
407407
guardt write_guard;
408408
write_guard.add(false_exprt());
409409

410-
written_in_atomic_sectiont::const_iterator a_s_writes=
411-
written_in_atomic_section.find(ssa_l1);
410+
const auto a_s_writes = written_in_atomic_section.find(ssa_l1);
412411
if(a_s_writes!=written_in_atomic_section.end())
413412
{
414-
for(a_s_w_entryt::const_iterator it=a_s_writes->second.begin();
415-
it!=a_s_writes->second.end();
416-
++it)
413+
for(const auto &guard_in_list : a_s_writes->second)
417414
{
418-
guardt g=*it;
415+
guardt g = guard_in_list;
419416
g-=guard;
420417
if(g.is_true())
421418
// there has already been a write to l1_identifier within
422419
// this atomic section under the same guard, or a guard
423420
// that implies the current one
424421
return false;
425422

426-
write_guard|=*it;
423+
write_guard |= guard_in_list;
427424
}
428425
}
429426

src/goto-symex/goto_symex_state.h

+14-44
Original file line numberDiff line numberDiff line change
@@ -173,47 +173,31 @@ class goto_symex_statet final
173173

174174
// stack frames -- these are used for function calls and
175175
// for exceptions
176-
class framet
176+
struct framet
177177
{
178-
public:
179178
// function calls
180179
irep_idt function_identifier;
181180
goto_state_mapt goto_state_map;
182181
symex_targett::sourcet calling_location;
183182

184183
goto_programt::const_targett end_of_function;
185-
exprt return_value;
186-
bool hidden_function;
184+
exprt return_value = nil_exprt();
185+
bool hidden_function = false;
187186

188187
symex_renaming_levelt::current_namest old_level1;
189188

190-
typedef std::set<irep_idt> local_objectst;
191-
local_objectst local_objects;
192-
193-
framet():
194-
return_value(nil_exprt()),
195-
hidden_function(false)
196-
{
197-
}
189+
std::set<irep_idt> local_objects;
198190

199191
// exceptions
200-
typedef std::map<irep_idt, goto_programt::targett> catch_mapt;
201-
catch_mapt catch_map;
192+
std::map<irep_idt, goto_programt::targett> catch_map;
202193

203194
// loop and recursion unwinding
204195
struct loop_infot
205196
{
206-
loop_infot():
207-
count(0),
208-
is_recursion(false)
209-
{
210-
}
211-
212-
unsigned count;
213-
bool is_recursion;
197+
unsigned count = 0;
198+
bool is_recursion = false;
214199
};
215-
typedef std::unordered_map<irep_idt, loop_infot> loop_iterationst;
216-
loop_iterationst loop_iterations;
200+
std::unordered_map<irep_idt, loop_infot> loop_iterations;
217201
};
218202

219203
typedef std::vector<framet> call_stackt;
@@ -249,40 +233,27 @@ class goto_symex_statet final
249233
// threads
250234
unsigned atomic_section_id;
251235
typedef std::pair<unsigned, std::list<guardt> > a_s_r_entryt;
252-
typedef std::unordered_map<ssa_exprt, a_s_r_entryt, irep_hash>
253-
read_in_atomic_sectiont;
254236
typedef std::list<guardt> a_s_w_entryt;
255-
typedef std::unordered_map<ssa_exprt, a_s_w_entryt, irep_hash>
256-
written_in_atomic_sectiont;
257-
read_in_atomic_sectiont read_in_atomic_section;
258-
written_in_atomic_sectiont written_in_atomic_section;
237+
std::unordered_map<ssa_exprt, a_s_r_entryt, irep_hash> read_in_atomic_section;
238+
std::unordered_map<ssa_exprt, a_s_w_entryt, irep_hash>
239+
written_in_atomic_section;
259240

260241
unsigned total_vccs, remaining_vccs;
261242

262-
class threadt
243+
struct threadt
263244
{
264-
public:
265245
goto_programt::const_targett pc;
266246
guardt guard;
267247
call_stackt call_stack;
268248
std::map<irep_idt, unsigned> function_frame;
269-
unsigned atomic_section_id;
270-
271-
threadt():
272-
atomic_section_id(0)
273-
{
274-
}
249+
unsigned atomic_section_id = 0;
275250
};
276251

277-
typedef std::vector<threadt> threadst;
278-
threadst threads;
252+
std::vector<threadt> threads;
279253

280254
bool l2_thread_read_encoding(ssa_exprt &expr, const namespacet &ns);
281255
bool l2_thread_write_encoding(const ssa_exprt &expr, const namespacet &ns);
282256

283-
void populate_dirty_for_function(
284-
const irep_idt &id, const goto_functiont &);
285-
286257
bool record_events;
287258
incremental_dirtyt dirty;
288259

@@ -294,7 +265,6 @@ class goto_symex_statet final
294265
/// \brief This state is saved, with the PC pointing to the next instruction
295266
/// of a GOTO
296267
bool has_saved_next_instruction;
297-
bool saved_target_is_backwards;
298268

299269
private:
300270
/// \brief Dangerous, do not use

src/goto-symex/symex_atomic_section.cpp

+13-21
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,16 @@ void goto_symext::symex_atomic_end(statet &state)
4545
const unsigned atomic_section_id=state.atomic_section_id;
4646
state.atomic_section_id=0;
4747

48-
for(goto_symex_statet::read_in_atomic_sectiont::const_iterator
49-
r_it=state.read_in_atomic_section.begin();
50-
r_it!=state.read_in_atomic_section.end();
51-
++r_it)
48+
for(const auto &pair : state.read_in_atomic_section)
5249
{
53-
ssa_exprt r=r_it->first;
54-
r.set_level_2(r_it->second.first);
50+
ssa_exprt r = pair.first;
51+
r.set_level_2(pair.second.first);
5552

5653
// guard is the disjunction over reads
57-
PRECONDITION(!r_it->second.second.empty());
58-
guardt read_guard(r_it->second.second.front());
59-
for(std::list<guardt>::const_iterator
60-
it=++(r_it->second.second.begin());
61-
it!=r_it->second.second.end();
54+
PRECONDITION(!pair.second.second.empty());
55+
guardt read_guard(pair.second.second.front());
56+
for(std::list<guardt>::const_iterator it = ++(pair.second.second.begin());
57+
it != pair.second.second.end();
6258
++it)
6359
read_guard|=*it;
6460
exprt read_guard_expr=read_guard.as_expr();
@@ -71,20 +67,16 @@ void goto_symext::symex_atomic_end(statet &state)
7167
state.source);
7268
}
7369

74-
for(goto_symex_statet::written_in_atomic_sectiont::const_iterator
75-
w_it=state.written_in_atomic_section.begin();
76-
w_it!=state.written_in_atomic_section.end();
77-
++w_it)
70+
for(const auto &pair : state.written_in_atomic_section)
7871
{
79-
ssa_exprt w=w_it->first;
72+
ssa_exprt w = pair.first;
8073
w.set_level_2(state.level2.current_count(w.get_identifier()));
8174

8275
// guard is the disjunction over writes
83-
PRECONDITION(!w_it->second.empty());
84-
guardt write_guard(w_it->second.front());
85-
for(std::list<guardt>::const_iterator
86-
it=++(w_it->second.begin());
87-
it!=w_it->second.end();
76+
PRECONDITION(!pair.second.empty());
77+
guardt write_guard(pair.second.front());
78+
for(std::list<guardt>::const_iterator it = ++(pair.second.begin());
79+
it != pair.second.end();
8880
++it)
8981
write_guard|=*it;
9082
exprt write_guard_expr=write_guard.as_expr();

src/goto-symex/symex_function_call.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,11 @@ void goto_symext::symex_function_call_code(
298298
frame.hidden_function=goto_function.is_hidden();
299299

300300
const goto_symex_statet::framet &p_frame=state.previous_frame();
301-
for(goto_symex_statet::framet::loop_iterationst::const_iterator
302-
it=p_frame.loop_iterations.begin();
303-
it!=p_frame.loop_iterations.end();
304-
++it)
305-
if(it->second.is_recursion)
306-
frame.loop_iterations.insert(*it);
301+
for(const auto &pair : p_frame.loop_iterations)
302+
{
303+
if(pair.second.is_recursion)
304+
frame.loop_iterations.insert(pair);
305+
}
307306

308307
// increase unwinding counter
309308
frame.loop_iterations[identifier].is_recursion=true;

src/goto-symex/symex_goto.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,13 @@ void goto_symext::symex_goto(statet &state)
184184
path_storaget::patht next_instruction(target, state);
185185
next_instruction.state.saved_target = state_pc;
186186
next_instruction.state.has_saved_next_instruction = true;
187-
next_instruction.state.saved_target_is_backwards = backward;
188187

189188
path_storaget::patht jump_target(target, state);
190189
jump_target.state.saved_target = new_state_pc;
191190
jump_target.state.has_saved_jump_target = true;
192191
// `forward` tells us where the branch we're _currently_ executing is
193192
// pointing to; this needs to be inverted for the branch that we're saving,
194193
// so let its truth value for `backwards` be the same as ours for `forward`.
195-
jump_target.state.saved_target_is_backwards = !backward;
196194

197195
log.debug() << "Saving next instruction '"
198196
<< next_instruction.state.saved_target->source_location << "'"

0 commit comments

Comments
 (0)