Skip to content

Commit f91b1eb

Browse files
Make the result of rename be a renamedt
This makes explicit the fact that the expression has been renamed.
1 parent 58f0771 commit f91b1eb

11 files changed

+85
-72
lines changed

src/goto-instrument/accelerate/scratch_program.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ bool scratch_programt::check_sat(bool do_slice)
6969

7070
exprt scratch_programt::eval(const exprt &e)
7171
{
72-
return checker->get(symex_state->rename<L2>(e, ns));
72+
return checker->get(symex_state->rename<L2>(e, ns).expr);
7373
}
7474

7575
void scratch_programt::append(goto_programt::instructionst &new_instructions)

src/goto-symex/goto_symex_state.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ void goto_symex_statet::set_l2_indices(
262262
ssa_expr.set_level_2(level2.current_count(ssa_expr.get_identifier()));
263263
}
264264

265-
ssa_exprt
265+
renamedt<ssa_exprt, L0>
266266
goto_symex_statet::rename_level0_ssa(ssa_exprt ssa, const namespacet &ns)
267267
{
268268
set_l0_indices(ssa, ns);
269269
rename<L0>(ssa.type(), ssa.get_identifier(), ns);
270270
ssa.update_type();
271-
return ssa;
271+
return renamedt<ssa_exprt, L0>{ssa};
272272
}
273273

274274
ssa_exprt
@@ -281,7 +281,8 @@ goto_symex_statet::rename_level1_ssa(ssa_exprt ssa, const namespacet &ns)
281281
}
282282

283283
template <levelt level>
284-
exprt goto_symex_statet::rename(exprt expr, const namespacet &ns)
284+
template <levelt level>
285+
renamedt<exprt, level> goto_symex_statet::rename(exprt expr, const namespacet &ns)
285286
{
286287
// rename all the symbols with their last known value
287288

@@ -346,7 +347,7 @@ exprt goto_symex_statet::rename(exprt expr, const namespacet &ns)
346347

347348
// do this recursively
348349
Forall_operands(it, expr)
349-
*it = rename<level>(std::move(*it), ns);
350+
*it = rename<level>(std::move(*it), ns).expr;
350351

351352
const exprt &c_expr = as_const(expr);
352353
INVARIANT(
@@ -358,7 +359,7 @@ exprt goto_symex_statet::rename(exprt expr, const namespacet &ns)
358359
"Type of renamed expr should be the same as operands for with_exprt and "
359360
"if_exprt");
360361
}
361-
return expr;
362+
return level2t<exprt>{expr};
362363
}
363364

364365
/// thread encoding

src/goto-symex/goto_symex_state.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,11 @@ class goto_symex_statet final : public goto_statet
176176
///
177177
/// A full explanation of SSA (which is why we do this renaming) is in
178178
/// the SSA section of background-concepts.md.
179-
template <levelt>
180-
exprt rename(exprt expr, const namespacet &ns);
179+
template <levelt level>
180+
renamedt<exprt, level> rename(exprt expr, const namespacet &ns);
181181

182-
ssa_exprt rename_level0_ssa(ssa_exprt ssa, const namespacet &ns);
182+
renamedt<ssa_exprt, L0> rename_level0_ssa(
183+
ssa_exprt ssa, const namespacet &ns);
183184

184185
ssa_exprt rename_level1_ssa(ssa_exprt ssa, const namespacet &ns);
185186

src/goto-symex/renaming_level.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ struct symex_level0t : public symex_renaming_levelt
7676
~symex_level0t() override = default;
7777
};
7878

79+
/// Wrapper for expressions that have been renamed at level2
80+
template <typename underlyingt>
81+
struct level2t
82+
{
83+
static_assert(
84+
std::is_base_of<exprt, underlyingt>::value,
85+
"underlyingt should inherit from exprt");
86+
underlyingt expr;
87+
};
88+
7989
/// Functor to set the level 1 renaming of SSA expressions.
8090
/// Level 1 corresponds to function frames.
8191
/// This is to preserve locality in case of recursion

src/goto-symex/symex_assign.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ void goto_symext::symex_assign_symbol(
212212
tmp_ssa_rhs.swap(ssa_rhs);
213213
}
214214

215-
exprt l2_rhs = state.rename<L2>(std::move(ssa_rhs), ns);
216-
do_simplify(l2_rhs);
215+
level2t<exprt> l2_rhs = state.rename<L2>(std::move(ssa_rhs), ns);
216+
do_simplify(l2_rhs.expr);
217217

218218
ssa_exprt ssa_lhs=lhs;
219219
state.assignment(
220220
ssa_lhs,
221-
l2_rhs,
221+
l2_rhs.expr,
222222
ns,
223223
symex_config.simplify_opt,
224224
symex_config.constant_propagation,
@@ -254,9 +254,9 @@ void goto_symext::symex_assign_symbol(
254254
target.assignment(
255255
tmp_guard.as_expr(),
256256
ssa_lhs,
257-
l2_full_lhs,
257+
l2_full_lhs.expr,
258258
add_to_lhs(full_lhs, ssa_lhs.get_original_expr()),
259-
l2_rhs,
259+
l2_rhs.expr,
260260
state.source,
261261
assignment_type);
262262
}
@@ -407,20 +407,20 @@ void goto_symext::symex_assign_if(
407407

408408
guardt old_guard=guard;
409409

410-
exprt renamed_guard = state.rename<L2>(lhs.cond(), ns);
411-
do_simplify(renamed_guard);
410+
level2t<exprt> renamed_guard = state.rename<L2>(lhs.cond(), ns);
411+
do_simplify(renamed_guard.expr);
412412

413-
if(!renamed_guard.is_false())
413+
if(!renamed_guard.expr.is_false())
414414
{
415-
guard.add(renamed_guard);
415+
guard.add(renamed_guard.expr);
416416
symex_assign_rec(
417417
state, lhs.true_case(), full_lhs, rhs, guard, assignment_type);
418418
guard = std::move(old_guard);
419419
}
420420

421-
if(!renamed_guard.is_true())
421+
if(!renamed_guard.expr.is_true())
422422
{
423-
guard.add(not_exprt(renamed_guard));
423+
guard.add(not_exprt(renamed_guard.expr));
424424
symex_assign_rec(
425425
state, lhs.false_case(), full_lhs, rhs, guard, assignment_type);
426426
guard = std::move(old_guard);

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ void goto_symext::symex_allocate(
7676

7777
// special treatment for sizeof(T)*x
7878
{
79-
const auto tmp_type = c_sizeof_type_rec(tmp_size);
79+
const auto tmp_type = c_sizeof_type_rec(tmp_size.expr);
8080

8181
if(tmp_type.has_value())
8282
{
8383
// Did the size get multiplied?
8484
auto elem_size = pointer_offset_size(*tmp_type, ns);
85-
const auto alloc_size = numeric_cast<mp_integer>(tmp_size);
85+
const auto alloc_size = numeric_cast<mp_integer>(tmp_size.expr);
8686

8787
if(!elem_size.has_value() || *elem_size==0)
8888
{
@@ -99,7 +99,7 @@ void goto_symext::symex_allocate(
9999
PRECONDITION(*c_sizeof_type_rec(tmp_size.op0()) == *tmp_type);
100100
}
101101
else
102-
PRECONDITION(*c_sizeof_type_rec(tmp_size.op1()) == *tmp_type);
102+
PRECONDITION(*c_sizeof_type_rec(tmp_size.expr.op1()) == *tmp_type);
103103

104104
object_type = array_typet(*tmp_type, s);
105105
}
@@ -112,15 +112,15 @@ void goto_symext::symex_allocate(
112112
mp_integer elements = *alloc_size / (*elem_size);
113113

114114
if(elements * (*elem_size) == *alloc_size)
115-
object_type =
116-
array_typet(*tmp_type, from_integer(elements, tmp_size.type()));
115+
object_type = array_typet(
116+
*tmp_type, from_integer(elements, tmp_size.expr.type()));
117117
}
118118
}
119119
}
120120
}
121121

122122
if(!object_type.has_value())
123-
object_type=array_typet(unsigned_char_type(), tmp_size);
123+
object_type = array_typet(unsigned_char_type(), tmp_size.expr);
124124

125125
// we introduce a fresh symbol for the size
126126
// to prevent any issues of the size getting ever changed
@@ -136,7 +136,7 @@ void goto_symext::symex_allocate(
136136
size_symbol.base_name=
137137
"dynamic_object_size"+std::to_string(dynamic_counter);
138138
size_symbol.name="symex_dynamic::"+id2string(size_symbol.base_name);
139-
size_symbol.type=tmp_size.type();
139+
size_symbol.type = tmp_size.expr.type();
140140
size_symbol.mode = mode;
141141
size_symbol.type.set(ID_C_constant, true);
142142
size_symbol.value = array_size;
@@ -164,12 +164,12 @@ void goto_symext::symex_allocate(
164164

165165
// to allow constant propagation
166166
exprt zero_init = state.rename<L2>(code.op1(), ns);
167-
simplify(zero_init, ns);
167+
simplify(zero_init.expr, ns);
168168

169169
INVARIANT(
170170
zero_init.is_constant(), "allocate expects constant as second argument");
171171

172-
if(!zero_init.is_zero() && !zero_init.is_false())
172+
if(!zero_init.expr.is_zero() && !zero_init.expr.is_false())
173173
{
174174
const auto zero_value =
175175
zero_initializer(*object_type, code.source_location(), ns);
@@ -312,7 +312,7 @@ void goto_symext::symex_printf(
312312
exprt tmp_rhs = state.rename<L2>(rhs, ns);
313313
do_simplify(tmp_rhs);
314314

315-
const exprt::operandst &operands = tmp_rhs.operands();
315+
const exprt::operandst &operands = tmp_rhs.expr.operands();
316316
std::list<exprt> args;
317317

318318
for(std::size_t i=1; i<operands.size(); i++)
@@ -367,7 +367,7 @@ void goto_symext::symex_output(
367367
args.back() = std::move(l2_arg);
368368
}
369369

370-
const irep_idt output_id=get_string_argument(id_arg, ns);
370+
const irep_idt output_id = get_string_argument(id_arg.expr, ns);
371371

372372
target.output(state.guard.as_expr(), state.source, output_id, args);
373373
}

src/goto-symex/symex_decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)
8585

8686
target.decl(
8787
state.guard.as_expr(),
88-
ssa,
88+
l2_expr.expr,
8989
state.source,
9090
hidden?
9191
symex_targett::assignment_typet::HIDDEN:
@@ -94,7 +94,7 @@ void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)
9494
if(state.dirty(ssa.get_object_name()) && state.atomic_section_id == 0)
9595
target.shared_write(
9696
state.guard.as_expr(),
97-
ssa,
97+
l2_expr.expr,
9898
state.atomic_section_id,
9999
state.source);
100100
}

src/goto-symex/symex_function_call.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void goto_symext::symex_function_call_code(
261261
// read the arguments -- before the locality renaming
262262
exprt::operandst arguments = call.arguments();
263263
for(auto &a : arguments)
264-
a = state.rename<L2>(std::move(a), ns);
264+
a = state.rename<L2>(std::move(a), ns).expr;
265265

266266
// we hide the call if the caller and callee are both hidden
267267
const bool hidden = state.top().hidden_function && goto_function.is_hidden();
@@ -395,40 +395,40 @@ static void locality(
395395
it++)
396396
{
397397
// get L0 name
398-
ssa_exprt ssa =
399-
state.rename_level0_ssa(ssa_exprt(ns.lookup(*it).symbol_expr()), ns);
400-
const irep_idt l0_name=ssa.get_identifier();
398+
renamedt<ssa_exprt, L0> l0_ssa =
399+
state.rename_level0(ns.lookup(*it).symbol_expr(), ns);
400+
const irep_idt l0_name = l0_ssa.expr.get_identifier();
401401

402402
// save old L1 name for popping the frame
403403
auto c_it = state.level1.current_names.find(l0_name);
404404

405405
if(c_it != state.level1.current_names.end())
406406
{
407407
frame.old_level1.emplace(l0_name, c_it->second);
408-
c_it->second = std::make_pair(ssa, frame_nr);
408+
c_it->second = std::make_pair(l0_ssa.expr, frame_nr);
409409
}
410410
else
411411
{
412412
c_it = state.level1.current_names
413-
.emplace(l0_name, std::make_pair(ssa, frame_nr))
413+
.emplace(l0_name, std::make_pair(l0_ssa.expr, frame_nr))
414414
.first;
415415
}
416416

417417
// do L1 renaming -- these need not be unique, as
418418
// identifiers may be shared among functions
419419
// (e.g., due to inlining or other code restructuring)
420420

421-
ssa_exprt ssa_l1 = state.rename_level1_ssa(std::move(ssa), ns);
421+
ssa_exprt ssa_l1 = state.rename_level1_ssa(std::move(ssa.expr), ns);
422422

423-
irep_idt l1_name = ssa_l1.get_identifier();
423+
irep_idt l1_name = ssa_l1.expr.get_identifier();
424424
unsigned offset=0;
425425

426426
while(state.l1_history.find(l1_name)!=state.l1_history.end())
427427
{
428428
symex_renaming_levelt::increase_counter(c_it);
429429
++offset;
430-
ssa_l1.set_level_1(frame_nr + offset);
431-
l1_name = ssa_l1.get_identifier();
430+
ssa_l1.expr.set_level_1(frame_nr + offset);
431+
l1_name = ssa_l1.expr.get_identifier();
432432
}
433433

434434
// now unique -- store

0 commit comments

Comments
 (0)