Skip to content

Commit 20c4bc1

Browse files
committed
Generate function bodies with nondet return values
Extends the generate function bodies feature to create nondet return values for functions, using the c nondet symbol factory.
1 parent 18cb59a commit 20c4bc1

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

@@ -271,11 +272,46 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
271272

272273
if(function.type.return_type() != void_typet())
273274
{
275+
typet type(function.type.return_type());
276+
type.remove(ID_C_constant);
277+
278+
symbolt &aux_symbol = get_fresh_aux_symbol(
279+
type,
280+
id2string(function_name),
281+
"return_value",
282+
function_symbol.location,
283+
ID_C,
284+
symbol_table);
285+
286+
aux_symbol.is_static_lifetime = false;
287+
288+
auto decl_instruction = add_instruction();
289+
decl_instruction->make_decl();
290+
decl_instruction->code = code_declt(aux_symbol.symbol_expr());
291+
292+
goto_programt dest;
293+
294+
havoc_expr_rec(
295+
aux_symbol.symbol_expr(),
296+
0,
297+
function_symbol.location,
298+
symbol_table,
299+
dest);
300+
301+
function.body.destructive_append(dest);
302+
303+
exprt return_expr = typecast_exprt::conditional_cast(
304+
aux_symbol.symbol_expr(), function.type.return_type());
305+
274306
auto return_instruction = add_instruction();
275307
return_instruction->make_return();
276-
return_instruction->code = code_returnt(side_effect_expr_nondett(
277-
function.type.return_type(), function_symbol.location));
308+
return_instruction->code = code_returnt(return_expr);
309+
310+
auto dead_instruction = add_instruction();
311+
dead_instruction->make_dead();
312+
dead_instruction->code = code_deadt(aux_symbol.symbol_expr());
278313
}
314+
279315
auto end_function_instruction = add_instruction();
280316
end_function_instruction->make_end_function();
281317

0 commit comments

Comments
 (0)