Skip to content

Commit 29ca8a9

Browse files
authored
Merge pull request #6406 from diffblue/symex_function_call
clean up goto_symex function calls
2 parents 268a0d0 + 3d64049 commit 29ca8a9

File tree

4 files changed

+56
-88
lines changed

4 files changed

+56
-88
lines changed

src/goto-symex/goto_symex.h

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -431,29 +431,29 @@ class goto_symext
431431
/// \param get_goto_function: The delegate to retrieve function bodies (see
432432
/// \ref get_goto_functiont)
433433
/// \param state: Symbolic execution state for current instruction
434-
/// \param code: The function call instruction
434+
/// \param instruction: The function call instruction
435435
virtual void symex_function_call(
436436
const get_goto_functiont &get_goto_function,
437437
statet &state,
438-
const code_function_callt &code);
438+
const goto_programt::instructiont &instruction);
439439

440440
/// Symbolically execute a END_FUNCTION instruction.
441441
/// \param state: Symbolic execution state for current instruction
442442
virtual void symex_end_of_function(statet &);
443443

444444
/// Symbolic execution of a call to a function call.
445-
/// For functions starting with \c __CPROVER_fkt
446-
/// \ref goto_symext::symex_fkt
447-
/// For non-special functions see
448-
/// \ref goto_symext::symex_function_call_code
449445
/// \param get_goto_function: The delegate to retrieve function bodies (see
450446
/// \ref get_goto_functiont)
451447
/// \param state: Symbolic execution state for current instruction
452-
/// \param code: The function call instruction
448+
/// \param lhs: nil or the lhs of the function call instruction
449+
/// \param function: the symbol of the function to call
450+
/// \param arguments: the arguments of the function call
453451
virtual void symex_function_call_symbol(
454452
const get_goto_functiont &get_goto_function,
455453
statet &state,
456-
const code_function_callt &code);
454+
const exprt &lhs,
455+
const symbol_exprt &function,
456+
const exprt::operandst &arguments);
457457

458458
/// Symbolic execution of a function call by inlining.
459459
/// Records the call in \p target by appending a function call step and:
@@ -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,
@@ -754,16 +758,7 @@ class goto_symext
754758
/// \param code: right-hand side containing side effect
755759
virtual void
756760
symex_cpp_new(statet &state, const exprt &lhs, const side_effect_exprt &code);
757-
/// Symbolically execute a FUNCTION_CALL instruction for a function whose
758-
/// name starts with CPROVER_FKT_PREFIX
759-
/// \remarks
760-
/// While the name seems to imply that this would be called when symbolic
761-
/// execution doesn't know what to do, it may actually be derived from a
762-
/// German abbreviation for function.
763-
/// This should not be called as these functions should already be removed
764-
/// \param state: Symbolic execution state for current instruction
765-
/// \param code: The function call instruction
766-
virtual void symex_fkt(statet &state, const code_function_callt &code);
761+
767762
/// Symbolically execute an OTHER instruction that does a CPP `printf`
768763
/// \param state: Symbolic execution state for current instruction
769764
/// \param rhs: The cleaned up CPP `printf` instruction

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -534,28 +534,3 @@ void goto_symext::symex_cpp_delete(
534534
bool do_array=code.get(ID_statement)==ID_cpp_delete_array;
535535
#endif
536536
}
537-
538-
void goto_symext::symex_fkt(
539-
statet &,
540-
const code_function_callt &)
541-
{
542-
// TODO: uncomment this line when TG-4667 is done
543-
// UNREACHABLE;
544-
#if 0
545-
exprt new_fc(ID_function, fc.type());
546-
547-
new_fc.reserve_operands(fc.operands().size()-1);
548-
549-
bool first=true;
550-
551-
Forall_operands(it, fc)
552-
if(first)
553-
first=false;
554-
else
555-
new_fc.add_to_operands(std::move(*it));
556-
557-
new_fc.set(ID_identifier, fc.op0().get(ID_identifier));
558-
559-
fc.swap(new_fc);
560-
#endif
561-
}

src/goto-symex/symex_function_call.cpp

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -173,54 +173,58 @@ void goto_symext::parameter_assignments(
173173
void goto_symext::symex_function_call(
174174
const get_goto_functiont &get_goto_function,
175175
statet &state,
176-
const code_function_callt &code)
176+
const goto_programt::instructiont &instruction)
177177
{
178-
const exprt &function=code.function();
178+
const exprt &function = instruction.call_function();
179179

180180
// If at some point symex_function_call can support more
181181
// expression ids(), like ID_Dereference, please expand the
182182
// precondition appropriately.
183183
PRECONDITION(function.id() == ID_symbol);
184-
symex_function_call_symbol(get_goto_function, state, code);
184+
185+
symex_function_call_symbol(
186+
get_goto_function,
187+
state,
188+
instruction.call_lhs(),
189+
to_symbol_expr(instruction.call_function()),
190+
instruction.call_arguments());
185191
}
186192

187193
void goto_symext::symex_function_call_symbol(
188194
const get_goto_functiont &get_goto_function,
189195
statet &state,
190-
const code_function_callt &original_code)
196+
const exprt &lhs,
197+
const symbol_exprt &function,
198+
const exprt::operandst &arguments)
191199
{
192-
code_function_callt code = original_code;
193-
194-
if(code.lhs().is_not_nil())
195-
code.lhs() = clean_expr(std::move(code.lhs()), state, true);
200+
exprt cleaned_lhs;
196201

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

199-
for(auto &argument : code.arguments())
200-
argument = clean_expr(std::move(argument), state, false);
207+
// no need to clean the function, which is a symbol only
201208

202-
target.location(state.guard.as_expr(), state.source);
209+
exprt::operandst cleaned_arguments;
203210

204-
PRECONDITION(code.function().id() == ID_symbol);
211+
for(auto &argument : arguments)
212+
cleaned_arguments.push_back(clean_expr(argument, state, false));
205213

206-
const irep_idt &identifier=
207-
to_symbol_expr(code.function()).get_identifier();
214+
target.location(state.guard.as_expr(), state.source);
208215

209-
if(has_prefix(id2string(identifier), CPROVER_FKT_PREFIX))
210-
{
211-
symex_fkt(state, code);
212-
}
213-
else
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

src/goto-symex/symex_main.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,13 +674,7 @@ void goto_symext::execute_next_instruction(
674674

675675
case FUNCTION_CALL:
676676
if(state.reachable)
677-
{
678-
code_function_callt call(
679-
instruction.call_lhs(),
680-
instruction.call_function(),
681-
instruction.call_arguments());
682-
symex_function_call(get_goto_function, state, call);
683-
}
677+
symex_function_call(get_goto_function, state, instruction);
684678
else
685679
symex_transition(state);
686680
break;

0 commit comments

Comments
 (0)