Skip to content

Commit 82a1bd3

Browse files
author
Daniel Kroening
authored
Merge pull request #2819 from diffblue/trace-with-arguments2
goto_trace now contains the arguments of function calls
2 parents 8646fdd + bf717d3 commit 82a1bd3

File tree

8 files changed

+85
-12
lines changed

8 files changed

+85
-12
lines changed

regression/cbmc/trace_show_function_calls/test.desc

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ main.c
33
--trace --trace-show-function-calls
44
^EXIT=10$
55
^SIGNAL=0$
6-
Function call: function_to_call \(depth 2\)
6+
Function call: function_to_call\(-2147483647\) \(depth 2\)
77
Function return: function_to_call \(depth 1\)
8-
Function call: function_to_call \(depth 2\)
8+
Function call: function_to_call\(-2\) \(depth 2\)
99
^VERIFICATION FAILED$
1010
--
1111
^warning: ignoring

src/goto-programs/goto_trace.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,34 @@ void show_goto_trace(
444444
case goto_trace_stept::typet::FUNCTION_CALL:
445445
function_depth++;
446446
if(options.show_function_calls)
447-
out << "\n#### Function call: " << step.function_identifier
448-
<< " (depth " << function_depth << ") ####\n";
447+
{
448+
out << "\n#### Function call: " << step.function_identifier;
449+
out << '(';
450+
451+
bool first = true;
452+
for(auto &arg : step.function_arguments)
453+
{
454+
if(first)
455+
first = false;
456+
else
457+
out << ", ";
458+
459+
out << from_expr(ns, step.function_identifier, arg);
460+
}
461+
462+
out << ") (depth " << function_depth << ") ####\n";
463+
}
449464
break;
465+
450466
case goto_trace_stept::typet::FUNCTION_RETURN:
451467
function_depth--;
452468
if(options.show_function_calls)
469+
{
453470
out << "\n#### Function return: " << step.function_identifier
454471
<< " (depth " << function_depth << ") ####\n";
472+
}
455473
break;
474+
456475
case goto_trace_stept::typet::SPAWN:
457476
case goto_trace_stept::typet::MEMORY_BARRIER:
458477
case goto_trace_stept::typet::ATOMIC_BEGIN:

src/goto-programs/goto_trace.h

+3
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ class goto_trace_stept
122122
// for function call/return
123123
irep_idt function_identifier;
124124

125+
// for function call
126+
std::vector<exprt> function_arguments;
127+
125128
/*! \brief outputs the trace step in ASCII to a given stream
126129
*/
127130
void output(

src/goto-symex/build_goto_trace.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,17 @@ void build_goto_trace(
304304
{
305305
goto_trace_step.lhs_object.make_nil();
306306
}
307+
307308
goto_trace_step.type = SSA_step.type;
308309
goto_trace_step.hidden = SSA_step.hidden;
309310
goto_trace_step.format_string = SSA_step.format_string;
310311
goto_trace_step.io_id = SSA_step.io_id;
311312
goto_trace_step.formatted = SSA_step.formatted;
312313
goto_trace_step.function_identifier = SSA_step.function_identifier;
314+
goto_trace_step.function_arguments = SSA_step.converted_function_arguments;
315+
316+
for(auto &arg : goto_trace_step.function_arguments)
317+
arg = prop_conv.get(arg);
313318

314319
// update internal field for specific variables in the counterexample
315320
update_internal_field(SSA_step, goto_trace_step, ns);

src/goto-symex/symex_function_call.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,14 @@ void goto_symext::symex_function_call_code(
254254
return;
255255
}
256256

257+
// read the arguments -- before the locality renaming
258+
exprt::operandst arguments = call.arguments();
259+
for(auto &a : arguments)
260+
state.rename(a, ns);
261+
257262
// record the call
258-
target.function_call(state.guard.as_expr(), identifier, state.source);
263+
target.function_call(
264+
state.guard.as_expr(), identifier, arguments, state.source);
259265

260266
if(!goto_function.body_available())
261267
{
@@ -276,11 +282,6 @@ void goto_symext::symex_function_call_code(
276282
return;
277283
}
278284

279-
// read the arguments -- before the locality renaming
280-
exprt::operandst arguments=call.arguments();
281-
for(auto &a : arguments)
282-
state.rename(a, ns);
283-
284285
// produce a new frame
285286
PRECONDITION(!state.call_stack().empty());
286287
goto_symex_statet::framet &frame=state.new_frame();

src/goto-symex/symex_target.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ class symex_targett
105105
virtual void function_call(
106106
const exprt &guard,
107107
const irep_idt &function_identifier,
108-
const sourcet &source)=0;
108+
const std::vector<exprt> &ssa_function_arguments,
109+
const sourcet &source) = 0;
109110

110111
// record return from a function
111112
virtual void function_return(

src/goto-symex/symex_target_equation.cpp

+39-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ void symex_target_equationt::location(
210210
void symex_target_equationt::function_call(
211211
const exprt &guard,
212212
const irep_idt &function_identifier,
213+
const std::vector<exprt> &ssa_function_arguments,
213214
const sourcet &source)
214215
{
215216
SSA_steps.push_back(SSA_stept());
@@ -219,6 +220,7 @@ void symex_target_equationt::function_call(
219220
SSA_step.type = goto_trace_stept::typet::FUNCTION_CALL;
220221
SSA_step.source = source;
221222
SSA_step.function_identifier = function_identifier;
223+
SSA_step.ssa_function_arguments = ssa_function_arguments;
222224

223225
merge_ireps(SSA_step);
224226
}
@@ -383,6 +385,7 @@ void symex_target_equationt::convert(
383385
convert_assumptions(prop_conv);
384386
convert_assertions(prop_conv);
385387
convert_goto_instructions(prop_conv);
388+
convert_function_calls(prop_conv);
386389
convert_io(prop_conv);
387390
convert_constraints(prop_conv);
388391
}
@@ -658,6 +661,39 @@ void symex_target_equationt::convert_assertions(
658661
prop_conv.set_to_true(disjunction(disjuncts));
659662
}
660663

664+
/// converts function calls
665+
/// \par parameters: decision procedure
666+
/// \return -
667+
void symex_target_equationt::convert_function_calls(
668+
decision_proceduret &dec_proc)
669+
{
670+
std::size_t argument_count=0;
671+
672+
for(auto &step : SSA_steps)
673+
if(!step.ignore)
674+
{
675+
step.converted_function_arguments.reserve(step.ssa_function_arguments.size());
676+
677+
for(const auto &arg : step.ssa_function_arguments)
678+
{
679+
if(arg.is_constant() ||
680+
arg.id()==ID_string_constant)
681+
step.converted_function_arguments.push_back(arg);
682+
else
683+
{
684+
const irep_idt identifier="symex::args::"+std::to_string(argument_count++);
685+
symbol_exprt symbol(identifier, arg.type());
686+
687+
equal_exprt eq(arg, symbol);
688+
merge_irep(eq);
689+
690+
dec_proc.set_to(eq, true);
691+
step.converted_function_arguments.push_back(symbol);
692+
}
693+
}
694+
}
695+
}
696+
661697
/// converts I/O
662698
/// \par parameters: decision procedure
663699
/// \return -
@@ -690,7 +726,6 @@ void symex_target_equationt::convert_io(
690726
}
691727
}
692728

693-
694729
void symex_target_equationt::merge_ireps(SSA_stept &SSA_step)
695730
{
696731
merge_irep(SSA_step.guard);
@@ -705,6 +740,9 @@ void symex_target_equationt::merge_ireps(SSA_stept &SSA_step)
705740
for(auto &step : SSA_step.io_args)
706741
merge_irep(step);
707742

743+
for(auto &arg : SSA_step.ssa_function_arguments)
744+
merge_irep(arg);
745+
708746
// converted_io_args is merged in convert_io
709747
}
710748

src/goto-symex/symex_target_equation.h

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class symex_target_equationt:public symex_targett
7575
virtual void function_call(
7676
const exprt &guard,
7777
const irep_idt &function_identifier,
78+
const std::vector<exprt> &ssa_function_arguments,
7879
const sourcet &source);
7980

8081
// record return from a function
@@ -163,6 +164,7 @@ class symex_target_equationt:public symex_targett
163164
void convert_constraints(decision_proceduret &decision_procedure) const;
164165
void convert_goto_instructions(prop_convt &prop_conv);
165166
void convert_guards(prop_convt &prop_conv);
167+
void convert_function_calls(decision_proceduret &decision_procedure);
166168
void convert_io(decision_proceduret &decision_procedure);
167169

168170
exprt make_expression() const;
@@ -232,6 +234,10 @@ class symex_target_equationt:public symex_targett
232234
// for function call/return
233235
irep_idt function_identifier;
234236

237+
// for function calls
238+
std::vector<exprt> ssa_function_arguments,
239+
converted_function_arguments;
240+
235241
// for SHARED_READ/SHARED_WRITE and ATOMIC_BEGIN/ATOMIC_END
236242
unsigned atomic_section_id=0;
237243

0 commit comments

Comments
 (0)