Skip to content

Commit f13a946

Browse files
Make set_l2_indices return a renamedt
This captures the information of which renaming the expression has been through.
1 parent ed654f9 commit f13a946

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,22 @@ void goto_symex_statet::assignment(
188188
const auto level2_it =
189189
level2.current_names.emplace(l1_identifier, std::make_pair(lhs, 0)).first;
190190
symex_renaming_levelt::increase_counter(level2_it);
191-
lhs = set_l2_indices(lhs, ns);
191+
const renamedt<ssa_exprt, L2> l2_lhs = set_l2_indices(std::move(lhs), ns);
192+
lhs = l2_lhs.get();
192193

193194
// in case we happen to be multi-threaded, record the memory access
194-
bool is_shared=l2_thread_write_encoding(lhs, ns);
195+
bool is_shared = l2_thread_write_encoding(l2_lhs.get(), ns);
195196

196197
if(run_validation_checks)
197198
{
198-
DATA_INVARIANT(!check_renaming(lhs), "lhs renaming failed on l2");
199+
DATA_INVARIANT(!check_renaming(l2_lhs.get()), "lhs renaming failed on l2");
199200
DATA_INVARIANT(!check_renaming(rhs), "rhs renaming failed on l2");
200201
}
201202

202203
// see #305 on GitHub for a simple example and possible discussion
203-
if(is_shared && lhs.type().id() == ID_pointer && !allow_pointer_unsoundness)
204+
if(
205+
is_shared && l2_lhs.get().type().id() == ID_pointer &&
206+
!allow_pointer_unsoundness)
204207
throw unsupported_operation_exceptiont(
205208
"pointer handling for concurrency is unsound");
206209

@@ -216,7 +219,7 @@ void goto_symex_statet::assignment(
216219
exprt l1_rhs(rhs);
217220
get_l1_name(l1_rhs);
218221

219-
ssa_exprt l1_lhs(lhs);
222+
ssa_exprt l1_lhs{l2_lhs.get()};
220223
l1_lhs.remove_level_2();
221224

222225
if(run_validation_checks)
@@ -247,12 +250,10 @@ goto_symex_statet::set_l1_indices(ssa_exprt ssa_expr, const namespacet &ns)
247250
return level1(level0(std::move(ssa_expr), ns, source.thread_nr));
248251
}
249252

250-
ssa_exprt
253+
renamedt<ssa_exprt, L2>
251254
goto_symex_statet::set_l2_indices(ssa_exprt ssa_expr, const namespacet &ns)
252255
{
253-
renamedt<ssa_exprt, L2> l2 =
254-
level2(level1(level0(std::move(ssa_expr), ns, source.thread_nr)));
255-
return l2.get();
256+
return level2(level1(level0(std::move(ssa_expr), ns, source.thread_nr)));
256257
}
257258

258259
template <levelt level>
@@ -327,7 +328,11 @@ exprt goto_symex_statet::rename(exprt expr, const namespacet &ns)
327328
if(p_it != propagation.end())
328329
expr=p_it->second; // already L2
329330
else
330-
ssa = set_l2_indices(ssa, ns);
331+
{
332+
const renamedt<ssa_exprt, L2> l2_ssa =
333+
set_l2_indices(std::move(ssa), ns);
334+
ssa = l2_ssa.get();
335+
}
331336
}
332337
}
333338
}
@@ -441,8 +446,7 @@ bool goto_symex_statet::l2_thread_read_encoding(
441446
if(!no_write.op().is_false())
442447
cond |= guardt{no_write.op()};
443448

444-
if_exprt tmp(cond.as_expr(), ssa_l1, ssa_l1);
445-
tmp.true_case() = set_l2_indices(to_ssa_expr(tmp.true_case()), ns);
449+
const renamedt<ssa_exprt, L2> l2_true_case = set_l2_indices(ssa_l1, ns);
446450

447451
if(a_s_read.second.empty())
448452
{
@@ -452,8 +456,9 @@ bool goto_symex_statet::l2_thread_read_encoding(
452456
symex_renaming_levelt::increase_counter(level2_it);
453457
a_s_read.first=level2.current_count(l1_identifier);
454458
}
459+
const renamedt<ssa_exprt, L2> l2_false_case = set_l2_indices(ssa_l1, ns);
455460

456-
to_ssa_expr(tmp.false_case()).set_level_2(a_s_read.first);
461+
if_exprt tmp{cond.as_expr(), l2_true_case.get(), l2_false_case.get()};
457462

458463
if(cond.is_false())
459464
{
@@ -475,7 +480,9 @@ bool goto_symex_statet::l2_thread_read_encoding(
475480
source,
476481
symex_targett::assignment_typet::PHI);
477482

478-
expr = set_l2_indices(ssa_l1, ns);
483+
const renamedt<ssa_exprt, L2> ssa_l2 =
484+
set_l2_indices(std::move(ssa_l1), ns);
485+
expr = ssa_l2.get();
479486

480487
a_s_read.second.push_back(guard);
481488
if(!no_write.op().is_false())
@@ -491,13 +498,16 @@ bool goto_symex_statet::l2_thread_read_encoding(
491498
// No event and no fresh index, but avoid constant propagation
492499
if(!record_events)
493500
{
494-
expr = set_l2_indices(ssa_l1, ns);
501+
const renamedt<ssa_exprt, L2> ssa_l2 =
502+
set_l2_indices(std::move(ssa_l1), ns);
503+
expr = ssa_l2.get();
495504
return true;
496505
}
497506

498507
// produce a fresh L2 name
499508
symex_renaming_levelt::increase_counter(level2_it);
500-
expr = set_l2_indices(ssa_l1, ns);
509+
const renamedt<ssa_exprt, L2> ssa_l2 = set_l2_indices(std::move(ssa_l1), ns);
510+
expr = ssa_l2.get();
501511

502512
// and record that
503513
INVARIANT_STRUCTURED(

src/goto-symex/goto_symex_state.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class goto_symex_statet final : public goto_statet
120120
renamedt<ssa_exprt, L1> set_l1_indices(ssa_exprt expr, const namespacet &ns);
121121

122122
/// Update level 0, 1 and 2 values.
123-
ssa_exprt set_l2_indices(ssa_exprt expr, const namespacet &ns);
123+
renamedt<ssa_exprt, L2> set_l2_indices(ssa_exprt expr, const namespacet &ns);
124124

125125
// this maps L1 names to (L2) types
126126
typedef std::unordered_map<irep_idt, typet> l1_typest;

0 commit comments

Comments
 (0)