@@ -230,6 +230,15 @@ void recursive_initializationt::initialize(
230
230
{depth, address_of_exprt{lhs}}});
231
231
}
232
232
233
+ code_blockt build_null_pointer (const symbol_exprt &result_symbol)
234
+ {
235
+ const typet &type_to_construct = result_symbol.type ().subtype ();
236
+ const null_pointer_exprt nullptr_expr{to_pointer_type (type_to_construct)};
237
+ const code_assignt assign_null{dereference_exprt{result_symbol},
238
+ nullptr_expr};
239
+ return code_blockt{{assign_null, code_returnt{}}};
240
+ }
241
+
233
242
code_blockt recursive_initializationt::build_constructor_body (
234
243
const exprt &depth_symbol,
235
244
const symbol_exprt &result_symbol,
@@ -249,6 +258,11 @@ code_blockt recursive_initializationt::build_constructor_body(
249
258
{
250
259
return build_function_pointer_constructor (result_symbol, is_nullable);
251
260
}
261
+ if (type.subtype ().id () == ID_empty)
262
+ {
263
+ // always initalize void* pointers as NULL
264
+ return build_null_pointer (result_symbol);
265
+ }
252
266
if (lhs_name.has_value ())
253
267
{
254
268
if (should_be_treated_as_cstring (*lhs_name) && type == char_type ())
@@ -620,15 +634,7 @@ code_blockt recursive_initializationt::build_pointer_constructor(
620
634
PRECONDITION (result.type ().id () == ID_pointer);
621
635
const typet &type = result.type ().subtype ();
622
636
PRECONDITION (type.id () == ID_pointer);
623
-
624
- null_pointer_exprt nullptr_expr{pointer_type (type.subtype ())};
625
- const code_assignt assign_null{dereference_exprt{result}, nullptr_expr};
626
-
627
- // always initalize void* pointers as NULL
628
- if (type.subtype ().id () == ID_empty)
629
- {
630
- return code_blockt{{assign_null, code_returnt{}}};
631
- }
637
+ PRECONDITION (type.subtype ().id () != ID_empty);
632
638
633
639
code_blockt body{};
634
640
// build:
@@ -663,6 +669,8 @@ code_blockt recursive_initializationt::build_pointer_constructor(
663
669
should_not_recurse.push_back (has_seen_expr);
664
670
}
665
671
672
+ null_pointer_exprt nullptr_expr{pointer_type (type.subtype ())};
673
+ const code_assignt assign_null{dereference_exprt{result}, nullptr_expr};
666
674
code_blockt null_and_return{{assign_null, code_returnt{}}};
667
675
body.add (code_ifthenelset{conjunction (should_not_recurse), null_and_return});
668
676
@@ -792,15 +800,7 @@ code_blockt recursive_initializationt::build_dynamic_array_constructor(
792
800
const typet &pointer_type = result.type ().subtype ();
793
801
PRECONDITION (pointer_type.id () == ID_pointer);
794
802
const typet &element_type = pointer_type.subtype ();
795
-
796
- null_pointer_exprt nullptr_expr{::pointer_type (element_type)};
797
- const code_assignt assign_null{dereference_exprt{result}, nullptr_expr};
798
-
799
- // always initalize void* pointers as NULL
800
- if (element_type.id () == ID_empty)
801
- {
802
- return code_blockt{{assign_null, code_returnt{}}};
803
- }
803
+ PRECONDITION (element_type.id () != ID_empty);
804
804
805
805
// builds:
806
806
// void type_constructor_ptr_T(int depth, T** result, int* size)
0 commit comments