@@ -514,22 +514,22 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
514
514
515
515
const union_typet::componentt &component = components[index ];
516
516
517
- DATA_INVARIANT (
518
- dest->id () == ID_union, " union should be zero initialized" );
519
-
520
- if (dest->get (ID_component_name) == component.get_name ())
517
+ if (
518
+ dest->id () == ID_union &&
519
+ to_union_expr (*dest).get_component_name () == component.get_name ())
521
520
{
522
521
// Already right union component. We can initialize multiple submembers,
523
522
// so do not overwrite this.
524
523
dest = &(to_union_expr (*dest).op ());
525
524
}
526
- else
525
+ else if (dest-> id () == ID_union)
527
526
{
528
- // The first component is not the maximum member, which the (default)
529
- // zero initializer prepared. Replace this by a component-specific
530
- // initializer; other bytes have an unspecified value (C Standard
531
- // 6.2.6.1(7)). In practice, objects of static lifetime are fully zero
532
- // initialized.
527
+ // The designated initializer does not initialize the maximum member,
528
+ // which the (default) zero initializer prepared. Replace this by a
529
+ // component-specific initializer; other bytes have an unspecified value
530
+ // (C Standard 6.2.6.1(7)). In practice, objects of static lifetime are
531
+ // fully zero initialized, so we just byte-update on top of the existing
532
+ // zero initializer.
533
533
const auto zero =
534
534
zero_initializer (component.type (), value.source_location (), *this );
535
535
if (!zero.has_value ())
@@ -556,6 +556,15 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
556
556
dest = &(to_union_expr (*dest).op ());
557
557
}
558
558
}
559
+ else if (
560
+ dest->id () == ID_byte_update_big_endian ||
561
+ dest->id () == ID_byte_update_little_endian)
562
+ {
563
+ // handle the byte update introduced by an earlier initializer (if
564
+ // current_symbol.is_static_lifetime)
565
+ byte_update_exprt &byte_update = to_byte_update_expr (*dest);
566
+ dest = &byte_update.op2 ();
567
+ }
559
568
}
560
569
else
561
570
UNREACHABLE;
0 commit comments