@@ -16,6 +16,7 @@ Author: Diffblue Ltd.
16
16
17
17
#include < util/arith_tools.h>
18
18
#include < util/format_expr.h>
19
+ #include < util/fresh_symbol.h>
19
20
#include < util/make_unique.h>
20
21
#include < util/string_utils.h>
21
22
@@ -271,11 +272,46 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
271
272
272
273
if (function.type .return_type () != void_typet ())
273
274
{
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
+
274
306
auto return_instruction = add_instruction ();
275
307
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 ());
278
313
}
314
+
279
315
auto end_function_instruction = add_instruction ();
280
316
end_function_instruction->make_end_function ();
281
317
0 commit comments