Skip to content

Commit 58b5de0

Browse files
Merge pull request #4080 from romainbrenguier/doc/symex-function-call
Clean-up and document symex_function_call [DOC-150]
2 parents da97188 + 7dc47a4 commit 58b5de0

File tree

3 files changed

+35
-45
lines changed

3 files changed

+35
-45
lines changed

src/goto-symex/goto_symex.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,27 +275,37 @@ class goto_symext
275275

276276
virtual void loop_bound_exceeded(statet &, const exprt &guard);
277277

278-
// function calls
279-
280-
void pop_frame(statet &);
281-
void return_assignment(statet &);
282-
283278
virtual void no_body(const irep_idt &)
284279
{
285280
}
286281

282+
/// Symbolic execution of a function call.
283+
/// Only functions that are symbols are supported, see
284+
/// \ref goto_symext::symex_function_call_symbol
287285
virtual void symex_function_call(
288286
const get_goto_functiont &,
289287
statet &,
290288
const code_function_callt &);
291289

292290
virtual void symex_end_of_function(statet &);
293291

292+
/// Symbolic execution of a call to a function call.
293+
/// For functions \c CBMC_trace and functions starting with \c __CPROVER_fkt
294+
/// see \ref goto_symext::symex_trace and
295+
/// \ref goto_symext::symex_fkt
296+
/// For non-special functions see
297+
/// \ref goto_symext::symex_function_call_code
294298
virtual void symex_function_call_symbol(
295299
const get_goto_functiont &,
296300
statet &,
297301
const code_function_callt &);
298302

303+
/// Symbolic execution of a function call by inlining.
304+
/// Records the call in \p target by appending a function call step and:
305+
/// - if the body is available create a new frame, assigns the parameters,
306+
/// and proceed to executing the code of the function.
307+
/// - otherwise assign a nondetministic value to the left-hand-side of the
308+
/// call when there is one
299309
virtual void symex_function_call_code(
300310
const get_goto_functiont &,
301311
statet &,
@@ -306,17 +316,18 @@ class goto_symext
306316
unsigned thread_nr,
307317
unsigned unwind);
308318

319+
/// Iterates over \p arguments and assigns them to the parameters, which are
320+
/// symbols whose name and type are deduced from the type of \p goto_function.
321+
/// \param function_identifier: name of the function
322+
/// \param goto_function: function whose parameters we want to assign
323+
/// \param [out] state: state of the goto program
324+
/// \param arguments: arguments that are passed to the function
309325
void parameter_assignments(
310326
const irep_idt &function_identifier,
311327
const goto_functionst::goto_functiont &,
312328
statet &,
313329
const exprt::operandst &arguments);
314330

315-
void locality(
316-
const irep_idt &function_identifier,
317-
statet &,
318-
const goto_functionst::goto_functiont &);
319-
320331
// exceptions
321332
void symex_throw(statet &);
322333
void symex_catch(statet &);

src/goto-symex/symex_function_call.cpp

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Author: Daniel Kroening, [email protected]
1818
#include <util/exception_utils.h>
1919
#include <util/invariant.h>
2020

21+
static void locality(
22+
const irep_idt &function_identifier,
23+
goto_symext::statet &state,
24+
const goto_functionst::goto_functiont &goto_function,
25+
const namespacet &ns);
26+
2127
bool goto_symext::get_unwind_recursion(const irep_idt &, unsigned, unsigned)
2228
{
2329
return false;
@@ -220,7 +226,6 @@ void goto_symext::symex_function_call_symbol(
220226
symex_function_call_code(get_goto_function, state, code);
221227
}
222228

223-
/// do function call by inlining
224229
void goto_symext::symex_function_call_code(
225230
const get_goto_functiont &get_goto_function,
226231
statet &state,
@@ -300,7 +305,7 @@ void goto_symext::symex_function_call_code(
300305
framet &frame = state.new_frame();
301306

302307
// preserve locality of local variables
303-
locality(identifier, state, goto_function);
308+
locality(identifier, state, goto_function, ns);
304309

305310
// assign actuals to formal parameters
306311
parameter_assignments(identifier, goto_function, state, arguments);
@@ -327,7 +332,7 @@ void goto_symext::symex_function_call_code(
327332
}
328333

329334
/// pop one call frame
330-
void goto_symext::pop_frame(statet &state)
335+
static void pop_frame(goto_symext::statet &state)
331336
{
332337
PRECONDITION(!state.call_stack().empty());
333338

@@ -378,10 +383,11 @@ void goto_symext::symex_end_of_function(statet &state)
378383

379384
/// preserves locality of local variables of a given function by applying L1
380385
/// renaming to the local identifiers
381-
void goto_symext::locality(
386+
static void locality(
382387
const irep_idt &function_identifier,
383-
statet &state,
384-
const goto_functionst::goto_functiont &goto_function)
388+
goto_symext::statet &state,
389+
const goto_functionst::goto_functiont &goto_function,
390+
const namespacet &ns)
385391
{
386392
unsigned &frame_nr=
387393
state.threads[state.source.thread_nr].function_frame[function_identifier];
@@ -441,28 +447,3 @@ void goto_symext::locality(
441447
}
442448
}
443449

444-
void goto_symext::return_assignment(statet &state)
445-
{
446-
framet &frame = state.top();
447-
448-
const goto_programt::instructiont &instruction=*state.source.pc;
449-
PRECONDITION(instruction.is_return());
450-
const code_returnt &code = instruction.get_return();
451-
452-
target.location(state.guard.as_expr(), state.source);
453-
454-
PRECONDITION(code.operands().size() == 1 || frame.return_value.is_nil());
455-
456-
exprt value = code.return_value();
457-
458-
if(frame.return_value.is_not_nil())
459-
{
460-
code_assignt assignment(frame.return_value, value);
461-
462-
INVARIANT(
463-
base_type_eq(assignment.lhs().type(), assignment.rhs().type(), ns),
464-
"goto_symext::return_assignment type mismatch");
465-
466-
symex_assign(state, assignment);
467-
}
468-
}

src/goto-symex/symex_main.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,8 @@ void goto_symext::symex_step(
441441
break;
442442

443443
case RETURN:
444-
if(!state.guard.is_false())
445-
return_assignment(state);
446-
447-
symex_transition(state);
444+
// This case should have been removed by return-value removal
445+
UNREACHABLE;
448446
break;
449447

450448
case ASSIGN:

0 commit comments

Comments
 (0)