Skip to content

Commit 8fec047

Browse files
clean_expr returns exprt and takes argument by copy
This makes the information flow clearer, avoid errors where a subtype of exprt could be passed as argument and its id mutated to something inconsistent with this subtype, and avoids having to make explicit copies in the places where the function is called.
1 parent d9a5113 commit 8fec047

8 files changed

+29
-46
lines changed

src/goto-symex/goto_symex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class goto_symext
305305
/// \param expr: The expression to clean up
306306
/// \param state
307307
/// \param write
308-
void clean_expr(exprt &expr, statet &state, bool write);
308+
exprt clean_expr(exprt expr, statet &state, bool write);
309309

310310
void trigger_auto_object(const exprt &, statet &);
311311
void initialize_auto_object(const exprt &, statet &);

src/goto-symex/symex_assign.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ Author: Daniel Kroening, [email protected]
2727

2828
void goto_symext::symex_assign(statet &state, const code_assignt &code)
2929
{
30-
exprt lhs=code.lhs();
31-
exprt rhs=code.rhs();
30+
exprt lhs = clean_expr(code.lhs(), state, true);
31+
exprt rhs = clean_expr(code.rhs(), state, false);
3232

3333
DATA_INVARIANT(
3434
lhs.type() == rhs.type(), "assignments must be type consistent");
3535

36-
clean_expr(lhs, state, true);
37-
clean_expr(rhs, state, false);
3836

3937
if(rhs.id()==ID_side_effect)
4038
{

src/goto-symex/symex_builtin_functions.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void goto_symext::symex_va_start(
290290
state.symbol_table);
291291
va_array.value = array;
292292

293-
clean_expr(array, state, false);
293+
array = clean_expr(std::move(array), state, false);
294294
array = state.rename(std::move(array), ns).get();
295295
do_simplify(array);
296296
symex_assign(state, code_assignt{va_array.symbol_expr(), std::move(array)});
@@ -446,8 +446,8 @@ void goto_symext::symex_cpp_new(
446446

447447
if(do_array)
448448
{
449-
exprt size_arg = static_cast<const exprt &>(code.find(ID_size));
450-
clean_expr(size_arg, state, false);
449+
exprt size_arg =
450+
clean_expr(static_cast<const exprt &>(code.find(ID_size)), state, false);
451451
symbol.type = array_typet(pointer_type.subtype(), size_arg);
452452
}
453453
else

src/goto-symex/symex_clean_expr.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ replace_nondet(exprt &expr, symex_nondet_generatort &build_symex_nondet)
173173

174174
void goto_symext::lift_let(statet &state, const let_exprt &let_expr)
175175
{
176-
exprt let_value = let_expr.value();
177-
clean_expr(let_value, state, false);
176+
exprt let_value = clean_expr(let_expr.value(), state, false);
178177
let_value = state.rename(std::move(let_value), ns).get();
179178
do_simplify(let_value);
180179

@@ -213,8 +212,8 @@ void goto_symext::lift_lets(statet &state, exprt &rhs)
213212
}
214213
}
215214

216-
void goto_symext::clean_expr(
217-
exprt &expr,
215+
exprt goto_symext::clean_expr(
216+
exprt expr,
218217
statet &state,
219218
const bool write)
220219
{
@@ -227,4 +226,5 @@ void goto_symext::clean_expr(
227226
// lhs
228227
if(write)
229228
adjust_byte_extract_rec(expr, ns);
229+
return expr;
230230
}

src/goto-symex/symex_function_call.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ void goto_symext::parameter_assignments(
134134
assignment_type =
135135
symex_targett::assignment_typet::VISIBLE_ACTUAL_PARAMETER;
136136

137-
clean_expr(lhs, state, true);
138-
clean_expr(rhs, state, false);
137+
lhs = to_symbol_expr(clean_expr(std::move(lhs), state, true));
138+
rhs = clean_expr(std::move(rhs), state, false);
139139

140140
exprt::operandst lhs_conditions;
141141
symex_assign_rec(
@@ -193,12 +193,12 @@ void goto_symext::symex_function_call_symbol(
193193
code_function_callt code = original_code;
194194

195195
if(code.lhs().is_not_nil())
196-
clean_expr(code.lhs(), state, true);
196+
code.lhs() = clean_expr(std::move(code.lhs()), state, true);
197197

198-
clean_expr(code.function(), state, false);
198+
code.function() = clean_expr(std::move(code.function()), state, false);
199199

200200
Forall_expr(it, code.arguments())
201-
clean_expr(*it, state, false);
201+
*it = clean_expr(std::move(*it), state, false);
202202

203203
target.location(state.guard.as_expr(), state.source);
204204

src/goto-symex/symex_goto.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ void goto_symext::symex_goto(statet &state)
6969
{
7070
const goto_programt::instructiont &instruction=*state.source.pc;
7171

72-
exprt new_guard = instruction.get_condition();
73-
clean_expr(new_guard, state, false);
72+
exprt new_guard = clean_expr(instruction.get_condition(), state, false);
7473

7574
renamedt<exprt, L2> renamed_guard = state.rename(std::move(new_guard), ns);
7675
if(symex_config.simplify_opt)

src/goto-symex/symex_main.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ void goto_symext::symex_assert(
8787
const goto_programt::instructiont &instruction,
8888
statet &state)
8989
{
90-
exprt condition = instruction.get_condition();
91-
clean_expr(condition, state, false);
90+
exprt condition = clean_expr(instruction.get_condition(), state, false);
9291

9392
// First, push negations in and perhaps convert existential quantifiers into
9493
// universals:
@@ -131,9 +130,7 @@ void goto_symext::vcc(
131130

132131
void goto_symext::symex_assume(statet &state, const exprt &cond)
133132
{
134-
exprt simplified_cond=cond;
135-
136-
clean_expr(simplified_cond, state, false);
133+
exprt simplified_cond = clean_expr(cond, state, false);
137134
simplified_cond = state.rename(std::move(simplified_cond), ns).get();
138135
do_simplify(simplified_cond);
139136

src/goto-symex/symex_other.cpp

+11-22
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,22 @@ void goto_symext::symex_other(
8989
else if(statement==ID_cpp_delete ||
9090
statement=="cpp_delete[]")
9191
{
92-
codet clean_code=code;
93-
clean_expr(clean_code, state, false);
92+
const codet clean_code = to_code(clean_expr(code, state, false));
9493
symex_cpp_delete(state, clean_code);
9594
}
9695
else if(statement==ID_printf)
9796
{
98-
codet clean_code=code;
99-
clean_expr(clean_code, state, false);
97+
const codet clean_code = to_code(clean_expr(code, state, false));
10098
symex_printf(state, clean_code);
10199
}
102100
else if(statement==ID_input)
103101
{
104-
codet clean_code(code);
105-
clean_expr(clean_code, state, false);
102+
const codet clean_code = to_code(clean_expr(code, state, false));
106103
symex_input(state, clean_code);
107104
}
108105
else if(statement==ID_output)
109106
{
110-
codet clean_code(code);
111-
clean_expr(clean_code, state, false);
107+
const codet clean_code = to_code(clean_expr(code, state, false));
112108
symex_output(state, clean_code);
113109
}
114110
else if(statement==ID_decl)
@@ -138,10 +134,8 @@ void goto_symext::symex_other(
138134
"expected array_copy/array_replace statement to have two operands");
139135

140136
// we need to add dereferencing for both operands
141-
exprt dest_array(code.op0());
142-
clean_expr(dest_array, state, false);
143-
exprt src_array(code.op1());
144-
clean_expr(src_array, state, false);
137+
exprt dest_array = clean_expr(code.op0(), state, false);
138+
exprt src_array = clean_expr(code.op1(), state, false);
145139

146140
// obtain the actual arrays
147141
process_array_expr(state, dest_array);
@@ -190,15 +184,13 @@ void goto_symext::symex_other(
190184
"expected array_set statement to have two operands");
191185

192186
// we need to add dereferencing for the first operand
193-
exprt array_expr(code.op0());
194-
clean_expr(array_expr, state, false);
187+
exprt array_expr = clean_expr(code.op0(), state, false);
195188

196189
// obtain the actual array(s)
197190
process_array_expr(state, array_expr);
198191

199192
// prepare to build the array_of
200-
exprt value = code.op1();
201-
clean_expr(value, state, false);
193+
exprt value = clean_expr(code.op1(), state, false);
202194

203195
// we might have a memset-style update of a non-array type - convert to a
204196
// byte array
@@ -237,10 +229,8 @@ void goto_symext::symex_other(
237229
"expected array_equal statement to have three operands");
238230

239231
// we need to add dereferencing for the first two
240-
exprt array1(code.op0());
241-
clean_expr(array1, state, false);
242-
exprt array2(code.op1());
243-
clean_expr(array2, state, false);
232+
exprt array1 = clean_expr(code.op0(), state, false);
233+
exprt array2 = clean_expr(code.op1(), state, false);
244234

245235
// obtain the actual arrays
246236
process_array_expr(state, array1);
@@ -270,8 +260,7 @@ void goto_symext::symex_other(
270260
code.operands().size() == 1,
271261
"expected havoc_object statement to have one operand");
272262

273-
exprt object(code.op0());
274-
clean_expr(object, state, false);
263+
exprt object = clean_expr(code.op0(), state, false);
275264

276265
process_array_expr(state, object);
277266
havoc_rec(state, guardt(true_exprt(), guard_manager), object);

0 commit comments

Comments
 (0)