Skip to content

Commit 440eb97

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 5335863 commit 440eb97

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
@@ -28,8 +28,15 @@ class goto_statet
2828
/// Distance from entry
2929
unsigned depth = 0;
3030

31+
protected:
3132
symex_level2t level2;
3233

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

@@ -67,6 +74,13 @@ class goto_statet
6774
: guard(true_exprt(), guard_manager)
6875
{
6976
}
77+
78+
void move_from(goto_statet &&other_state)
79+
{
80+
level2 = std::move(other_state.level2);
81+
propagation = std::move(other_state.propagation);
82+
value_set = std::move(other_state.value_set);
83+
}
7084
};
7185

7286
#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
@@ -214,6 +214,12 @@ class goto_symex_statet final : public goto_statet
214214
/// isn't an expression keyed by it.
215215
void increase_generation_if_exists(const irep_idt identifier);
216216

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

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
@@ -330,9 +330,7 @@ void goto_symext::merge_goto(
330330
{
331331
if(state.guard.is_false())
332332
{
333-
state.level2 = std::move(goto_state.level2);
334-
state.propagation = std::move(goto_state.propagation);
335-
state.value_set = std::move(goto_state.value_set);
333+
state.move_from(std::move(goto_state));
336334
}
337335
else
338336
{
@@ -521,17 +519,17 @@ void goto_symext::phi_function(
521519
statet &dest_state)
522520
{
523521
if(
524-
goto_state.level2.current_names.empty() &&
525-
dest_state.level2.current_names.empty())
522+
goto_state.get_level2().current_names.empty() &&
523+
dest_state.get_level2().current_names.empty())
526524
return;
527525

528526
guardt diff_guard = goto_state.guard;
529527
// this gets the diff between the guards
530528
diff_guard -= dest_state.guard;
531529

532530
for_each2(
533-
goto_state.level2.current_names,
534-
dest_state.level2.current_names,
531+
goto_state.get_level2().current_names,
532+
dest_state.get_level2().current_names,
535533
[&](const ssa_exprt &ssa, unsigned goto_count, unsigned dest_count) {
536534
merge_names(
537535
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)