Skip to content

Commit a1007a4

Browse files
committed
Generate function bodies with nondet return values
1 parent c3076a7 commit a1007a4

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/goto-instrument/generate_function_bodies.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Diffblue Ltd.
1616

1717
#include <util/arith_tools.h>
1818
#include <util/format_expr.h>
19+
#include <util/fresh_symbol.h>
1920
#include <util/make_unique.h>
2021
#include <util/string_utils.h>
2122

@@ -278,11 +279,46 @@ class havoc_generate_function_bodiest : public generate_function_bodiest,
278279

279280
if(function.type.return_type() != void_typet())
280281
{
282+
typet type(function.type.return_type());
283+
type.remove(ID_C_constant);
284+
285+
symbolt &aux_symbol = get_fresh_aux_symbol(
286+
type,
287+
id2string(function_name),
288+
"return_value",
289+
function_symbol.location,
290+
ID_C,
291+
symbol_table);
292+
293+
aux_symbol.is_static_lifetime = false;
294+
295+
auto decl_instruction = add_instruction();
296+
decl_instruction->make_decl();
297+
decl_instruction->code = code_declt(aux_symbol.symbol_expr());
298+
299+
goto_programt dest;
300+
301+
havoc_expr_rec(
302+
aux_symbol.symbol_expr(),
303+
0,
304+
function_symbol.location,
305+
symbol_table,
306+
dest);
307+
308+
function.body.destructive_append(dest);
309+
310+
exprt return_expr = typecast_exprt::conditional_cast(
311+
aux_symbol.symbol_expr(), function.type.return_type());
312+
281313
auto return_instruction = add_instruction();
282314
return_instruction->make_return();
283-
return_instruction->code = code_returnt(side_effect_expr_nondett(
284-
function.type.return_type(), function_symbol.location));
315+
return_instruction->code = code_returnt(return_expr);
316+
317+
auto dead_instruction = add_instruction();
318+
dead_instruction->make_dead();
319+
dead_instruction->code = code_deadt(aux_symbol.symbol_expr());
285320
}
321+
286322
auto end_function_instruction = add_instruction();
287323
end_function_instruction->make_end_function();
288324

0 commit comments

Comments
 (0)