Skip to content

Commit 6ebefbb

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

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,20 @@ 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(is_shared && l2_lhs.get().type().id() == ID_pointer && !allow_pointer_unsoundness)
204205
throw unsupported_operation_exceptiont(
205206
"pointer handling for concurrency is unsound");
206207

@@ -216,7 +217,7 @@ void goto_symex_statet::assignment(
216217
exprt l1_rhs(rhs);
217218
get_l1_name(l1_rhs);
218219

219-
ssa_exprt l1_lhs(lhs);
220+
ssa_exprt l1_lhs{l2_lhs.get()};
220221
l1_lhs.remove_level_2();
221222

222223
if(run_validation_checks)
@@ -249,13 +250,11 @@ renamedt<ssa_exprt, L1> goto_symex_statet::set_l1_indices(
249250
return level1(level0(std::move(ssa_expr), ns, source.thread_nr));
250251
}
251252

252-
ssa_exprt goto_symex_statet::set_l2_indices(
253+
renamedt<ssa_exprt, L2> goto_symex_statet::set_l2_indices(
253254
ssa_exprt ssa_expr,
254255
const namespacet &ns)
255256
{
256-
renamedt<ssa_exprt, L2> l2 =
257-
level2(level1(level0(std::move(ssa_expr), ns, source.thread_nr)));
258-
return l2.get();
257+
return level2(level1(level0(std::move(ssa_expr), ns, source.thread_nr)));
259258
}
260259

261260
template <levelt level>
@@ -330,7 +329,11 @@ exprt goto_symex_statet::rename(exprt expr, const namespacet &ns)
330329
if(p_it != propagation.end())
331330
expr=p_it->second; // already L2
332331
else
333-
ssa = set_l2_indices(ssa, ns);
332+
{
333+
const renamedt<ssa_exprt, L2> l2_ssa =
334+
set_l2_indices(std::move(ssa), ns);
335+
ssa = l2_ssa.get();
336+
}
334337
}
335338
}
336339
}
@@ -444,8 +447,7 @@ bool goto_symex_statet::l2_thread_read_encoding(
444447
if(!no_write.op().is_false())
445448
cond |= guardt{no_write.op()};
446449

447-
if_exprt tmp(cond.as_expr(), ssa_l1, ssa_l1);
448-
tmp.true_case() = set_l2_indices(to_ssa_expr(tmp.true_case()), ns);
450+
const renamedt<ssa_exprt, L2> l2_true_case = set_l2_indices(ssa_l1, ns);
449451

450452
if(a_s_read.second.empty())
451453
{
@@ -455,8 +457,9 @@ bool goto_symex_statet::l2_thread_read_encoding(
455457
symex_renaming_levelt::increase_counter(level2_it);
456458
a_s_read.first=level2.current_count(l1_identifier);
457459
}
460+
const renamedt<ssa_exprt, L2> l2_false_case = set_l2_indices(ssa_l1, ns);
458461

459-
to_ssa_expr(tmp.false_case()).set_level_2(a_s_read.first);
462+
if_exprt tmp{cond.as_expr(), l2_true_case.get(), l2_false_case.get()};
460463

461464
if(cond.is_false())
462465
{
@@ -478,7 +481,9 @@ bool goto_symex_statet::l2_thread_read_encoding(
478481
source,
479482
symex_targett::assignment_typet::PHI);
480483

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

483488
a_s_read.second.push_back(guard);
484489
if(!no_write.op().is_false())
@@ -494,13 +499,16 @@ bool goto_symex_statet::l2_thread_read_encoding(
494499
// No event and no fresh index, but avoid constant propagation
495500
if(!record_events)
496501
{
497-
expr = set_l2_indices(ssa_l1, ns);
502+
const renamedt<ssa_exprt, L2> ssa_l2 =
503+
set_l2_indices(std::move(ssa_l1), ns);
504+
expr = ssa_l2.get();
498505
return true;
499506
}
500507

501508
// produce a fresh L2 name
502509
symex_renaming_levelt::increase_counter(level2_it);
503-
expr = set_l2_indices(ssa_l1, ns);
510+
const renamedt<ssa_exprt, L2> ssa_l2 = set_l2_indices(std::move(ssa_l1), ns);
511+
expr = ssa_l2.get();
504512

505513
// and record that
506514
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)