Skip to content

Commit 3d64049

Browse files
committed
renaming + signature of symex_function_call_code
This both renames the method symex_function_call_code and changes its signature, to better reflect the ordering of steps when executing function calls.
1 parent 5d1900c commit 3d64049

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

src/goto-symex/goto_symex.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,15 @@ class goto_symext
464464
/// \param get_goto_function: The delegate to retrieve function bodies (see
465465
/// \ref get_goto_functiont)
466466
/// \param state: Symbolic execution state for current instruction
467-
/// \param call: The function call instruction
468-
virtual void symex_function_call_code(
467+
/// \param cleaned_lhs: nil or the lhs of the function call, cleaned
468+
/// \param function: the symbol of the function to call
469+
/// \param cleaned_arguments: the arguments of the function call, cleaned
470+
virtual void symex_function_call_post_clean(
469471
const get_goto_functiont &get_goto_function,
470472
statet &state,
471-
const code_function_callt &call);
473+
const exprt &cleaned_lhs,
474+
const symbol_exprt &function,
475+
const exprt::operandst &cleaned_arguments);
472476

473477
virtual bool get_unwind_recursion(
474478
const irep_idt &identifier,

src/goto-symex/symex_function_call.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -197,30 +197,34 @@ void goto_symext::symex_function_call_symbol(
197197
const symbol_exprt &function,
198198
const exprt::operandst &arguments)
199199
{
200-
code_function_callt code(lhs, function, arguments);
200+
exprt cleaned_lhs;
201201

202-
if(code.lhs().is_not_nil())
203-
code.lhs() = clean_expr(std::move(code.lhs()), state, true);
202+
if(lhs.is_nil())
203+
cleaned_lhs = lhs;
204+
else
205+
cleaned_lhs = clean_expr(lhs, state, true);
204206

205-
code.function() = clean_expr(std::move(code.function()), state, false);
207+
// no need to clean the function, which is a symbol only
206208

207-
for(auto &argument : code.arguments())
208-
argument = clean_expr(std::move(argument), state, false);
209+
exprt::operandst cleaned_arguments;
209210

210-
target.location(state.guard.as_expr(), state.source);
211+
for(auto &argument : arguments)
212+
cleaned_arguments.push_back(clean_expr(argument, state, false));
211213

212-
PRECONDITION(code.function().id() == ID_symbol);
214+
target.location(state.guard.as_expr(), state.source);
213215

214-
symex_function_call_code(get_goto_function, state, code);
216+
symex_function_call_post_clean(
217+
get_goto_function, state, cleaned_lhs, function, cleaned_arguments);
215218
}
216219

217-
void goto_symext::symex_function_call_code(
220+
void goto_symext::symex_function_call_post_clean(
218221
const get_goto_functiont &get_goto_function,
219222
statet &state,
220-
const code_function_callt &call)
223+
const exprt &cleaned_lhs,
224+
const symbol_exprt &function,
225+
const exprt::operandst &cleaned_arguments)
221226
{
222-
const irep_idt &identifier=
223-
to_symbol_expr(call.function()).get_identifier();
227+
const irep_idt &identifier = function.get_identifier();
224228

225229
const goto_functionst::goto_functiont &goto_function =
226230
get_goto_function(identifier);
@@ -258,10 +262,10 @@ void goto_symext::symex_function_call_code(
258262
}
259263

260264
// read the arguments -- before the locality renaming
261-
const exprt::operandst &arguments = call.arguments();
262265
const std::vector<renamedt<exprt, L2>> renamed_arguments =
263-
make_range(arguments).map(
264-
[&](const exprt &a) { return state.rename(a, ns); });
266+
make_range(cleaned_arguments).map([&](const exprt &a) {
267+
return state.rename(a, ns);
268+
});
265269

266270
// we hide the call if the caller and callee are both hidden
267271
const bool hidden =
@@ -279,18 +283,18 @@ void goto_symext::symex_function_call_code(
279283
target.function_return(
280284
state.guard.as_expr(), identifier, state.source, hidden);
281285

282-
if(call.lhs().is_not_nil())
286+
if(cleaned_lhs.is_not_nil())
283287
{
284-
const auto rhs =
285-
side_effect_expr_nondett(call.lhs().type(), call.source_location());
286-
symex_assign(state, call.lhs(), rhs);
288+
const auto rhs = side_effect_expr_nondett(
289+
cleaned_lhs.type(), state.source.pc->source_location());
290+
symex_assign(state, cleaned_lhs, rhs);
287291
}
288292

289293
if(symex_config.havoc_undefined_functions)
290294
{
291295
// assign non det to function arguments if pointers
292296
// are not const
293-
for(const auto &arg : call.arguments())
297+
for(const auto &arg : cleaned_arguments)
294298
{
295299
if(
296300
arg.type().id() == ID_pointer &&
@@ -325,10 +329,10 @@ void goto_symext::symex_function_call_code(
325329
locality(identifier, state, path_storage, goto_function, ns);
326330

327331
// assign actuals to formal parameters
328-
parameter_assignments(identifier, goto_function, state, arguments);
332+
parameter_assignments(identifier, goto_function, state, cleaned_arguments);
329333

330334
frame.end_of_function=--goto_function.body.instructions.end();
331-
frame.return_value=call.lhs();
335+
frame.return_value = cleaned_lhs;
332336
frame.function_identifier=identifier;
333337
frame.hidden_function = goto_function.is_hidden();
334338

0 commit comments

Comments
 (0)