Skip to content

Commit 6199641

Browse files
committed
Generate function bodies with nondet return values
1 parent e66793d commit 6199641

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

@@ -268,11 +269,46 @@ class havoc_generate_function_bodiest : public generate_function_bodiest,
268269

269270
if(function.type.return_type() != void_typet())
270271
{
272+
typet type(function.type.return_type());
273+
type.remove(ID_C_constant);
274+
275+
symbolt &aux_symbol = get_fresh_aux_symbol(
276+
type,
277+
id2string(function_name),
278+
"return_value",
279+
function_symbol.location,
280+
ID_C,
281+
symbol_table);
282+
283+
aux_symbol.is_static_lifetime = false;
284+
285+
auto decl_instruction = add_instruction();
286+
decl_instruction->make_decl();
287+
decl_instruction->code = code_declt(aux_symbol.symbol_expr());
288+
289+
goto_programt dest;
290+
291+
havoc_expr_rec(
292+
aux_symbol.symbol_expr(),
293+
0,
294+
function_symbol.location,
295+
symbol_table,
296+
dest);
297+
298+
function.body.destructive_append(dest);
299+
300+
exprt return_expr = typecast_exprt::conditional_cast(
301+
aux_symbol.symbol_expr(), function.type.return_type());
302+
271303
auto return_instruction = add_instruction();
272304
return_instruction->make_return();
273-
return_instruction->code = code_returnt(side_effect_expr_nondett(
274-
function.type.return_type(), function_symbol.location));
305+
return_instruction->code = code_returnt(return_expr);
306+
307+
auto dead_instruction = add_instruction();
308+
dead_instruction->make_dead();
309+
dead_instruction->code = code_deadt(aux_symbol.symbol_expr());
275310
}
311+
276312
auto end_function_instruction = add_instruction();
277313
end_function_instruction->make_end_function();
278314

0 commit comments

Comments
 (0)