@@ -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
@@ -278,11 +279,46 @@ class havoc_generate_function_bodiest : public generate_function_bodiest,
278
279
279
280
if (function.type .return_type () != void_typet ())
280
281
{
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
+
281
313
auto return_instruction = add_instruction ();
282
314
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 ());
285
320
}
321
+
286
322
auto end_function_instruction = add_instruction ();
287
323
end_function_instruction->make_end_function ();
288
324
0 commit comments