@@ -52,48 +52,55 @@ static std::optional<codet> static_lifetime_init(
5252 if (symbol.type .id () == ID_code || symbol.type .id () == ID_empty)
5353 return {};
5454
55- if (symbol.type .id () == ID_array && to_array_type (symbol.type ).size ().is_nil ())
55+ // Get a writable reference to the symbol in case we need to update it
56+ symbolt *symbol_ptr = &symbol_table.get_writeable_ref (identifier);
57+
58+ if (
59+ symbol_ptr->type .id () == ID_array &&
60+ to_array_type (symbol_ptr->type ).size ().is_nil ())
5661 {
5762 // C standard 6.9.2, paragraph 5
5863 // adjust the type to an array of size 1
59- symbolt &writable_symbol = symbol_table.get_writeable_ref (identifier);
60- writable_symbol.type = symbol.type ;
61- writable_symbol.type .set (ID_size, from_integer (1 , size_type ()));
64+ symbol_ptr->type .set (ID_size, from_integer (1 , size_type ()));
6265 }
6366
6467 if (
65- (symbol. type .id () == ID_struct_tag &&
66- ns.follow_tag (to_struct_tag_type (symbol. type )).is_incomplete ()) ||
67- (symbol. type .id () == ID_union_tag &&
68- ns.follow_tag (to_union_tag_type (symbol. type )).is_incomplete ()))
68+ (symbol_ptr-> type .id () == ID_struct_tag &&
69+ ns.follow_tag (to_struct_tag_type (symbol_ptr-> type )).is_incomplete ()) ||
70+ (symbol_ptr-> type .id () == ID_union_tag &&
71+ ns.follow_tag (to_union_tag_type (symbol_ptr-> type )).is_incomplete ()))
6972 {
7073 return {}; // do not initialize
7174 }
7275
7376 exprt rhs;
7477
75- if ((symbol.value .is_nil () && symbol.is_extern ) ||
76- symbol.value .id () == ID_nondet)
78+ if (
79+ (symbol_ptr->value .is_nil () && symbol_ptr->is_extern ) ||
80+ symbol_ptr->value .id () == ID_nondet)
7781 {
78- if (symbol. value .get_bool (ID_C_no_nondet_initialization))
82+ if (symbol_ptr-> value .get_bool (ID_C_no_nondet_initialization))
7983 return {};
8084
8185 // Nondet initialise if not linked, or if explicitly requested.
8286 // Compilers would usually complain about the unlinked symbol case.
83- const auto nondet = nondet_initializer (symbol.type , symbol.location , ns);
87+ const auto nondet =
88+ nondet_initializer (symbol_ptr->type , symbol_ptr->location , ns);
8489 CHECK_RETURN (nondet.has_value ());
8590 rhs = *nondet;
8691 }
87- else if (symbol. value .is_nil ())
92+ else if (symbol_ptr-> value .is_nil ())
8893 {
89- const auto zero = zero_initializer (symbol.type , symbol.location , ns);
94+ const auto zero =
95+ zero_initializer (symbol_ptr->type , symbol_ptr->location , ns);
9096 CHECK_RETURN (zero.has_value ());
9197 rhs = *zero;
9298 }
9399 else
94- rhs = symbol. value ;
100+ rhs = symbol_ptr-> value ;
95101
96- return code_frontend_assignt{symbol.symbol_expr (), rhs, symbol.location };
102+ return code_frontend_assignt{
103+ symbol_ptr->symbol_expr (), rhs, symbol_ptr->location };
97104}
98105
99106void static_lifetime_init (
0 commit comments