Skip to content

Commit 8811606

Browse files
authored
Merge pull request #4595 from romainbrenguier/clean-up/field-sensitivity
field_sensitivityt::apply does not take a reference
2 parents 07c5e1d + a786eb3 commit 8811606

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

src/goto-symex/field_sensitivity.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,37 @@ Author: Michael Tautschnig
1818

1919
// #define ENABLE_ARRAY_FIELD_SENSITIVITY
2020

21-
void field_sensitivityt::apply(
21+
exprt field_sensitivityt::apply(
2222
const namespacet &ns,
2323
goto_symex_statet &state,
24-
exprt &expr,
24+
exprt expr,
2525
bool write) const
2626
{
2727
if(!run_apply)
28-
return;
28+
return expr;
2929

3030
if(expr.id() != ID_address_of)
3131
{
3232
Forall_operands(it, expr)
33-
apply(ns, state, *it, write);
33+
*it = apply(ns, state, std::move(*it), write);
3434
}
3535

3636
if(expr.id() == ID_symbol && expr.get_bool(ID_C_SSA_symbol) && !write)
3737
{
38-
expr = get_fields(ns, state, to_ssa_expr(expr));
38+
return get_fields(ns, state, to_ssa_expr(expr));
3939
}
4040
else if(
4141
!write && expr.id() == ID_member &&
4242
to_member_expr(expr).struct_op().id() == ID_struct)
4343
{
44-
simplify(expr, ns);
44+
return simplify_expr(std::move(expr), ns);
4545
}
4646
#ifdef ENABLE_ARRAY_FIELD_SENSITIVITY
4747
else if(
4848
!write && expr.id() == ID_index &&
4949
to_index_expr(expr).array().id() == ID_array)
5050
{
51-
simplify(expr, ns);
51+
return simplify_expr(std::move(expr), ns);
5252
}
5353
#endif // ENABLE_ARRAY_FIELD_SENSITIVITY
5454
else if(expr.id() == ID_member)
@@ -73,9 +73,9 @@ void field_sensitivityt::apply(
7373
member.struct_op() = tmp.get_original_expr();
7474
tmp.set_expression(member);
7575
if(was_l2)
76-
expr = state.rename(tmp, ns).get();
76+
return state.rename(std::move(tmp), ns).get();
7777
else
78-
expr.swap(tmp);
78+
return std::move(tmp);
7979
}
8080
}
8181
#ifdef ENABLE_ARRAY_FIELD_SENSITIVITY
@@ -102,12 +102,13 @@ void field_sensitivityt::apply(
102102
index.array() = tmp.get_original_expr();
103103
tmp.set_expression(index);
104104
if(was_l2)
105-
expr = state.rename(tmp, ns).get();
105+
return state.rename(std::move(tmp), ns).get();
106106
else
107-
expr.swap(tmp);
107+
return std::move(tmp);
108108
}
109109
}
110110
#endif // ENABLE_ARRAY_FIELD_SENSITIVITY
111+
return expr;
111112
}
112113

113114
exprt field_sensitivityt::get_fields(
@@ -187,8 +188,7 @@ void field_sensitivityt::field_assignments(
187188
symex_targett &target,
188189
bool allow_pointer_unsoundness)
189190
{
190-
exprt lhs_fs = lhs;
191-
apply(ns, state, lhs_fs, false);
191+
const exprt lhs_fs = apply(ns, state, lhs, false);
192192

193193
bool run_apply_bak = run_apply;
194194
run_apply = false;

src/goto-symex/field_sensitivity.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ class field_sensitivityt
4545
/// existing member or index expressions into symbols are performed.
4646
/// \param ns: a namespace to resolve type symbols/tag types
4747
/// \param [in,out] state: symbolic execution state
48-
/// \param [in,out] expr: an expression to be (recursively) transformed - this
49-
/// parameter is both input and output.
48+
/// \param expr: an expression to be (recursively) transformed.
5049
/// \param write: set to true if the expression is to be used as an lvalue.
51-
void
52-
apply(const namespacet &ns, goto_symex_statet &state, exprt &expr, bool write)
50+
/// \return the transformed expression
51+
exprt
52+
apply(const namespacet &ns, goto_symex_statet &state, exprt expr, bool write)
5353
const;
5454

5555
/// Compute an expression representing the individual components of a

src/goto-symex/goto_symex_state.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ goto_symex_statet::rename(exprt expr, const namespacet &ns)
337337
"if_exprt");
338338

339339
if(level == L2)
340-
field_sensitivity.apply(ns, *this, expr, false);
340+
expr = field_sensitivity.apply(ns, *this, std::move(expr), false);
341341

342342
return renamedt<exprt, level>{std::move(expr)};
343343
}

src/goto-symex/symex_assign.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ static void rewrite_with_to_field_symbols(
271271
with_expr.new_value().type());
272272
}
273273

274-
state.field_sensitivity.apply(ns, state, field_sensitive_lhs, true);
274+
field_sensitive_lhs = state.field_sensitivity.apply(
275+
ns, state, std::move(field_sensitive_lhs), true);
275276

276277
if(field_sensitive_lhs.id() != ID_symbol)
277278
break;
@@ -392,8 +393,8 @@ void goto_symext::symex_assign_from_struct(
392393
for(std::size_t i = 0; i < components.size(); ++i)
393394
{
394395
const auto &comp = components[i];
395-
exprt lhs_field = member_exprt(lhs, comp.get_name(), comp.type());
396-
state.field_sensitivity.apply(ns, state, lhs_field, true);
396+
const exprt lhs_field = state.field_sensitivity.apply(
397+
ns, state, member_exprt{lhs, comp.get_name(), comp.type()}, true);
397398
INVARIANT(
398399
lhs_field.id() == ID_symbol,
399400
"member of symbol should be susceptible to field-sensitivity");

src/goto-symex/symex_dereference.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void goto_symext::dereference_rec(exprt &expr, statet &state, bool write)
244244

245245
// ...and may have introduced a member-of-symbol construct with a
246246
// corresponding SSA symbol:
247-
state.field_sensitivity.apply(ns, state, expr, write);
247+
expr = state.field_sensitivity.apply(ns, state, std::move(expr), write);
248248
}
249249
else if(
250250
expr.id() == ID_index && to_index_expr(expr).array().id() == ID_member &&
@@ -359,8 +359,8 @@ void goto_symext::dereference(exprt &expr, statet &state, bool write)
359359
// from different frames. Would be enough to rename
360360
// symbols whose address is taken.
361361
PRECONDITION(!state.call_stack().empty());
362-
exprt l1_expr = state.rename<L1>(expr, ns).get();
363-
state.field_sensitivity.apply(ns, state, l1_expr, write);
362+
exprt l1_expr = state.field_sensitivity.apply(
363+
ns, state, state.rename<L1>(expr, ns).get(), write);
364364

365365
// start the recursion!
366366
dereference_rec(l1_expr, state, write);
@@ -394,5 +394,5 @@ void goto_symext::dereference(exprt &expr, statet &state, bool write)
394394
"simplify re-introduced dereferencing");
395395
}
396396

397-
state.field_sensitivity.apply(ns, state, expr, write);
397+
expr = state.field_sensitivity.apply(ns, state, std::move(expr), write);
398398
}

0 commit comments

Comments
 (0)