Skip to content

Commit b09cd64

Browse files
smowtonJohnDumbell
authored andcommitted
Symex: protect level2
We really should protect the level 2 name map to prevent "allocating" a new generation by just making one up in the local name map, cf. applying for one properly using increase_generation.
1 parent 1e94a4a commit b09cd64

File tree

7 files changed

+34
-15
lines changed

7 files changed

+34
-15
lines changed

src/goto-symex/auto_objects.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ void goto_symext::trigger_auto_object(const exprt &expr, statet &state)
9191
if(has_prefix(id2string(symbol.base_name), "auto_object"))
9292
{
9393
// done already?
94-
if(state.level2.current_names.find(ssa_expr.get_identifier())==
95-
state.level2.current_names.end())
94+
if(
95+
state.get_level2().current_names.find(ssa_expr.get_identifier()) ==
96+
state.get_level2().current_names.end())
9697
{
9798
initialize_auto_object(expr, state);
9899
}

src/goto-symex/goto_state.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ class goto_statet
2929
/// Distance from entry
3030
unsigned depth = 0;
3131

32+
protected:
3233
symex_level2t level2;
3334

35+
public:
36+
const symex_level2t &get_level2() const
37+
{
38+
return level2;
39+
}
40+
3441
/// Uses level 1 names, and is used to do dereferencing
3542
value_sett value_set;
3643

@@ -72,6 +79,13 @@ class goto_statet
7279
: guard(true_exprt(), guard_manager), source(_source)
7380
{
7481
}
82+
83+
void move_from(goto_statet &&other_state)
84+
{
85+
level2 = std::move(other_state.level2);
86+
propagation = std::move(other_state.propagation);
87+
value_set = std::move(other_state.value_set);
88+
}
7589
};
7690

7791
#endif // CPROVER_GOTO_SYMEX_GOTO_STATE_H

src/goto-symex/goto_symex_state.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ class goto_symex_statet final : public goto_statet
212212
/// isn't an expression keyed by it.
213213
void increase_generation_if_exists(const irep_idt identifier);
214214

215+
/// Drops an L1 name from the local L2 map
216+
void drop_l1_name(symex_renaming_levelt::current_namest::const_iterator it)
217+
{
218+
level2.current_names.erase(it);
219+
}
220+
215221
private:
216222
std::function<std::size_t(const irep_idt &)> fresh_l2_name_provider;
217223

src/goto-symex/symex_atomic_section.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void goto_symext::symex_atomic_end(statet &state)
7070
for(const auto &pair : state.written_in_atomic_section)
7171
{
7272
ssa_exprt w = pair.first;
73-
w.set_level_2(state.level2.current_count(w.get_identifier()));
73+
w.set_level_2(state.get_level2().current_count(w.get_identifier()));
7474

7575
// guard is the disjunction over writes
7676
PRECONDITION(!pair.second.empty());

src/goto-symex/symex_function_call.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ static void pop_frame(goto_symext::statet &state)
349349
state.level1.restore_from(frame.old_level1);
350350

351351
// clear function-locals from L2 renaming
352-
for(auto c_it = state.level2.current_names.begin();
353-
c_it != state.level2.current_names.end();) // no ++c_it
352+
for(auto c_it = state.get_level2().current_names.begin();
353+
c_it != state.get_level2().current_names.end();) // no ++c_it
354354
{
355355
const irep_idt l1_o_id=c_it->second.first.get_l1_object_identifier();
356356
// could use iteration over local_objects as l1_o_id is prefix
@@ -364,7 +364,7 @@ static void pop_frame(goto_symext::statet &state)
364364
}
365365
auto cur = c_it;
366366
++c_it;
367-
state.level2.current_names.erase(cur);
367+
state.drop_l1_name(cur);
368368
}
369369
}
370370

src/goto-symex/symex_goto.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,7 @@ void goto_symext::merge_goto(goto_statet &&goto_state, statet &state)
325325
{
326326
if(state.guard.is_false())
327327
{
328-
state.level2 = std::move(goto_state.level2);
329-
state.propagation = std::move(goto_state.propagation);
330-
state.value_set = std::move(goto_state.value_set);
328+
state.move_from(std::move(goto_state));
331329
}
332330
else
333331
{
@@ -516,17 +514,17 @@ void goto_symext::phi_function(
516514
statet &dest_state)
517515
{
518516
if(
519-
goto_state.level2.current_names.empty() &&
520-
dest_state.level2.current_names.empty())
517+
goto_state.get_level2().current_names.empty() &&
518+
dest_state.get_level2().current_names.empty())
521519
return;
522520

523521
guardt diff_guard = goto_state.guard;
524522
// this gets the diff between the guards
525523
diff_guard -= dest_state.guard;
526524

527525
for_each2(
528-
goto_state.level2.current_names,
529-
dest_state.level2.current_names,
526+
goto_state.get_level2().current_names,
527+
dest_state.get_level2().current_names,
530528
[&](const ssa_exprt &ssa, unsigned goto_count, unsigned dest_count) {
531529
merge_names(
532530
goto_state,

src/goto-symex/symex_start_thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ void goto_symext::symex_start_thread(statet &state)
5252
// create a copy of the local variables for the new thread
5353
framet &frame = state.call_stack().top();
5454

55-
for(auto c_it = state.level2.current_names.begin();
56-
c_it != state.level2.current_names.end();
55+
for(auto c_it = state.get_level2().current_names.begin();
56+
c_it != state.get_level2().current_names.end();
5757
++c_it)
5858
{
5959
const irep_idt l1_o_id=c_it->second.first.get_l1_object_identifier();

0 commit comments

Comments
 (0)