Skip to content

Commit 5bd95a7

Browse files
Merge pull request #4793 from romainbrenguier/clean-up/symex-assign-symbol
Clean_up related to symex_assign_symbol
2 parents 860a438 + 71caf32 commit 5bd95a7

12 files changed

+56
-70
lines changed

src/goto-symex/goto_state.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,17 @@ std::size_t goto_statet::increase_generation(
3131
const ssa_exprt &lhs,
3232
std::function<std::size_t(const irep_idt &)> fresh_l2_name_provider)
3333
{
34-
std::size_t n = fresh_l2_name_provider(l1_identifier);
34+
const std::size_t n = fresh_l2_name_provider(l1_identifier);
3535

36-
const auto r_opt = level2.current_names.find(l1_identifier);
37-
38-
if(!r_opt)
36+
if(const auto r_opt = level2.current_names.find(l1_identifier))
3937
{
40-
level2.current_names.insert(l1_identifier, std::make_pair(lhs, n));
38+
std::pair<ssa_exprt, std::size_t> copy = r_opt->get();
39+
copy.second = n;
40+
level2.current_names.replace(l1_identifier, std::move(copy));
4141
}
4242
else
4343
{
44-
std::pair<ssa_exprt, unsigned> copy = r_opt->get();
45-
copy.second = n;
46-
level2.current_names.replace(l1_identifier, std::move(copy));
44+
level2.current_names.insert(l1_identifier, std::make_pair(lhs, n));
4745
}
4846

4947
return n;

src/goto-symex/goto_symex_state.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ goto_symex_statet::write_is_shared_resultt goto_symex_statet::write_is_shared(
514514
}
515515

516516
/// thread encoding
517+
/// \return true if \p expr is shared between threads
517518
bool goto_symex_statet::l2_thread_write_encoding(
518519
const ssa_exprt &expr,
519520
const namespacet &ns)

src/goto-symex/goto_symex_state.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class goto_symex_statet final : public goto_statet
217217
unsigned remaining_vccs = 0;
218218

219219
/// Allocates a fresh L2 name for the given L1 identifier, and makes it the
220-
// latest generation on this path.
220+
/// latest generation on this path.
221221
std::size_t
222222
increase_generation(const irep_idt l1_identifier, const ssa_exprt &lhs)
223223
{

src/goto-symex/renamed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class renamedt : private underlyingt
5050
};
5151

5252
friend renamedt<ssa_exprt, L0>
53-
symex_level0(ssa_exprt, const namespacet &, unsigned);
53+
symex_level0(ssa_exprt, const namespacet &, std::size_t);
5454
friend struct symex_level1t;
5555
friend struct symex_level2t;
5656
friend class goto_symex_statet;

src/goto-symex/renaming_level.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void get_variables(
3131
}
3232

3333
renamedt<ssa_exprt, L0>
34-
symex_level0(ssa_exprt ssa_expr, const namespacet &ns, unsigned thread_nr)
34+
symex_level0(ssa_exprt ssa_expr, const namespacet &ns, std::size_t thread_nr)
3535
{
3636
// already renamed?
3737
if(!ssa_expr.get_level_0().empty())
@@ -56,21 +56,23 @@ symex_level0(ssa_exprt ssa_expr, const namespacet &ns, unsigned thread_nr)
5656
return renamedt<ssa_exprt, L0>{ssa_expr};
5757
}
5858

59-
void symex_level1t::insert(const renamedt<ssa_exprt, L0> &ssa, unsigned index)
59+
void symex_level1t::insert(
60+
const renamedt<ssa_exprt, L0> &ssa,
61+
std::size_t index)
6062
{
6163
current_names.insert(
6264
ssa.get().get_identifier(), std::make_pair(ssa.get(), index));
6365
}
6466

65-
optionalt<std::pair<ssa_exprt, unsigned>> symex_level1t::insert_or_replace(
67+
optionalt<std::pair<ssa_exprt, std::size_t>> symex_level1t::insert_or_replace(
6668
const renamedt<ssa_exprt, L0> &ssa,
67-
unsigned index)
69+
std::size_t index)
6870
{
6971
const irep_idt &identifier = ssa.get().get_identifier();
7072
const auto old_value = current_names.find(identifier);
7173
if(old_value)
7274
{
73-
std::pair<ssa_exprt, unsigned> result = *old_value;
75+
std::pair<ssa_exprt, std::size_t> result = *old_value;
7476
current_names.replace(identifier, std::make_pair(ssa.get(), index));
7577
return result;
7678
}

src/goto-symex/renaming_level.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Author: Romain Brenguier, [email protected]
2929
/// This is extended by the different symex_level structures which are used
3030
/// during symex to ensure static single assignment (SSA) form.
3131
using symex_renaming_levelt =
32-
sharing_mapt<irep_idt, std::pair<ssa_exprt, unsigned>>;
32+
sharing_mapt<irep_idt, std::pair<ssa_exprt, std::size_t>>;
3333

3434
/// Add the \c ssa_exprt of current_names to vars
3535
DEPRECATED(SINCE(2019, 6, 5, "Unused"))
@@ -44,21 +44,21 @@ void get_variables(
4444
/// a guard, a shared variable or a function. \p ns is queried to decide
4545
/// whether we are in one of these cases.
4646
renamedt<ssa_exprt, L0>
47-
symex_level0(ssa_exprt ssa_expr, const namespacet &ns, unsigned thread_nr);
47+
symex_level0(ssa_exprt ssa_expr, const namespacet &ns, std::size_t thread_nr);
4848

4949
/// Functor to set the level 1 renaming of SSA expressions.
5050
/// Level 1 corresponds to function frames.
5151
/// This is to preserve locality in case of recursion
5252
struct symex_level1t
5353
{
5454
/// Assume \p ssa is not already known
55-
void insert(const renamedt<ssa_exprt, L0> &ssa, unsigned index);
55+
void insert(const renamedt<ssa_exprt, L0> &ssa, std::size_t index);
5656

5757
/// Set the index for \p ssa to index.
5858
/// \return if an index for \p ssa was already know, returns it's previous
5959
/// value.
60-
optionalt<std::pair<ssa_exprt, unsigned>>
61-
insert_or_replace(const renamedt<ssa_exprt, L0> &ssa, unsigned index);
60+
optionalt<std::pair<ssa_exprt, std::size_t>>
61+
insert_or_replace(const renamedt<ssa_exprt, L0> &ssa, std::size_t index);
6262

6363
/// \return true if \p ssa has an associated index
6464
bool has(const renamedt<ssa_exprt, L0> &ssa) const;

src/goto-symex/ssa_step.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ SSA_assignment_stept::SSA_assignment_stept(
221221
exprt _ssa_full_lhs,
222222
exprt _original_full_lhs,
223223
exprt _ssa_rhs,
224-
exprt _cond_expr,
225-
symex_targett::assignment_typet _assignment_type,
226-
bool _hidden)
224+
symex_targett::assignment_typet _assignment_type)
227225
: SSA_stept(source, goto_trace_stept::typet::ASSIGNMENT)
228226
{
229227
guard = std::move(_guard);
@@ -232,6 +230,8 @@ SSA_assignment_stept::SSA_assignment_stept(
232230
original_full_lhs = std::move(_original_full_lhs);
233231
ssa_rhs = std::move(_ssa_rhs);
234232
assignment_type = _assignment_type;
235-
cond_expr = std::move(_cond_expr);
236-
hidden = _hidden;
233+
cond_expr = equal_exprt{ssa_lhs, ssa_rhs};
234+
hidden = assignment_type != symex_targett::assignment_typet::STATE &&
235+
assignment_type !=
236+
symex_targett::assignment_typet::VISIBLE_ACTUAL_PARAMETER;
237237
}

src/goto-symex/ssa_step.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ class SSA_assignment_stept : public SSA_stept
205205
exprt ssa_full_lhs,
206206
exprt original_full_lhs,
207207
exprt ssa_rhs,
208-
exprt cond_expr,
209-
symex_targett::assignment_typet assignment_type,
210-
bool hidden);
208+
symex_targett::assignment_typet assignment_type);
211209
};
212210

213211
#endif // CPROVER_GOTO_SYMEX_SSA_STEP_H

src/goto-symex/symex_assign.cpp

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ void goto_symext::symex_assign_from_struct(
395395
const exprt::operandst &guard,
396396
assignment_typet assignment_type)
397397
{
398-
const struct_typet &type = to_struct_type(ns.follow(lhs.type()));
399-
const struct_union_typet::componentst &components = type.components();
398+
const auto &components = to_struct_type(ns.follow(lhs.type())).components();
400399
PRECONDITION(rhs.operands().size() == components.size());
401400

402401
for(std::size_t i = 0; i < components.size(); ++i)
@@ -435,16 +434,15 @@ void goto_symext::symex_assign_symbol(
435434
return;
436435
}
437436

438-
exprt l2_rhs = [&]() {
439-
exprt guarded_rhs = rhs;
440-
// put assignment guard into the rhs
441-
if(!guard.empty())
442-
{
443-
guarded_rhs =
444-
if_exprt{conjunction(guard), std::move(guarded_rhs), lhs, rhs.type()};
445-
}
446-
return state.rename(std::move(guarded_rhs), ns).get();
447-
}();
437+
exprt l2_rhs =
438+
state
439+
.rename(
440+
// put assignment guard into the rhs
441+
guard.empty()
442+
? rhs
443+
: static_cast<exprt>(if_exprt{conjunction(guard), rhs, lhs}),
444+
ns)
445+
.get();
448446

449447
// Note the following two calls are specifically required for
450448
// field-sensitivity. For example, with-expressions, which may have just been
@@ -457,7 +455,6 @@ void goto_symext::symex_assign_symbol(
457455

458456
do_simplify(assignment.rhs);
459457

460-
const ssa_exprt &l1_lhs = assignment.lhs;
461458
const ssa_exprt l2_lhs = state
462459
.assignment(
463460
assignment.lhs,
@@ -468,15 +465,12 @@ void goto_symext::symex_assign_symbol(
468465
symex_config.allow_pointer_unsoundness)
469466
.get();
470467

471-
exprt ssa_full_lhs = add_to_lhs(full_lhs, l2_lhs);
472468
state.record_events.push(false);
473-
const exprt l2_full_lhs = state.rename(std::move(ssa_full_lhs), ns).get();
469+
const exprt l2_full_lhs =
470+
state.rename(add_to_lhs(full_lhs, l2_lhs), ns).get();
474471
state.record_events.pop();
475472

476-
// do the assignment
477-
const symbolt &symbol = ns.lookup(l2_lhs.get_object_name());
478-
479-
if(symbol.is_auxiliary)
473+
if(ns.lookup(l2_lhs.get_object_name()).is_auxiliary)
480474
assignment_type=symex_targett::assignment_typet::HIDDEN;
481475

482476
log.conditional_output(
@@ -486,19 +480,16 @@ void goto_symext::symex_assign_symbol(
486480
<< messaget::eom;
487481
});
488482

489-
const exprt assignment_guard =
490-
make_and(state.guard.as_expr(), conjunction(guard));
491-
492-
const exprt original_lhs = get_original_name(l2_full_lhs);
493483
target.assignment(
494-
assignment_guard,
484+
make_and(state.guard.as_expr(), conjunction(guard)),
495485
l2_lhs,
496486
l2_full_lhs,
497-
original_lhs,
487+
get_original_name(l2_full_lhs),
498488
assignment.rhs,
499489
state.source,
500490
assignment_type);
501491

492+
const ssa_exprt &l1_lhs = assignment.lhs;
502493
if(field_sensitivityt::is_divisible(l1_lhs))
503494
{
504495
// Split composite symbol lhs into its components

src/goto-symex/symex_target_equation.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,13 @@ void symex_target_equationt::assignment(
114114
{
115115
PRECONDITION(ssa_lhs.is_not_nil());
116116

117-
SSA_steps.emplace_back(SSA_assignment_stept{
118-
source,
119-
guard,
120-
ssa_lhs,
121-
ssa_full_lhs,
122-
original_full_lhs,
123-
ssa_rhs,
124-
equal_exprt(ssa_lhs, ssa_rhs),
125-
assignment_type,
126-
assignment_type != assignment_typet::STATE &&
127-
assignment_type != assignment_typet::VISIBLE_ACTUAL_PARAMETER});
117+
SSA_steps.emplace_back(SSA_assignment_stept{source,
118+
guard,
119+
ssa_lhs,
120+
ssa_full_lhs,
121+
original_full_lhs,
122+
ssa_rhs,
123+
assignment_type});
128124

129125
merge_ireps(SSA_steps.back());
130126
}

src/util/ssa_expr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,19 @@ const irep_idt ssa_exprt::get_l1_object_identifier() const
178178
#endif
179179
}
180180

181-
void ssa_exprt::set_level_0(unsigned i)
181+
void ssa_exprt::set_level_0(std::size_t i)
182182
{
183183
set(ID_L0, i);
184184
::update_identifier(*this);
185185
}
186186

187-
void ssa_exprt::set_level_1(unsigned i)
187+
void ssa_exprt::set_level_1(std::size_t i)
188188
{
189189
set(ID_L1, i);
190190
::update_identifier(*this);
191191
}
192192

193-
void ssa_exprt::set_level_2(unsigned i)
193+
void ssa_exprt::set_level_2(std::size_t i)
194194
{
195195
set(ID_L2, i);
196196
::update_identifier(*this);

src/util/ssa_expr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ class ssa_exprt:public symbol_exprt
5252
return o.get_identifier();
5353
}
5454

55-
void set_level_0(unsigned i);
55+
void set_level_0(std::size_t i);
5656

57-
void set_level_1(unsigned i);
57+
void set_level_1(std::size_t i);
5858

59-
void set_level_2(unsigned i);
59+
void set_level_2(std::size_t i);
6060

6161
void remove_level_2();
6262

0 commit comments

Comments
 (0)