@@ -530,27 +530,36 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
530
530
// initializer; other bytes have an unspecified value (C Standard
531
531
// 6.2.6.1(7)). In practice, objects of static lifetime are fully zero
532
532
// initialized.
533
- const auto zero =
534
- zero_initializer (component.type (), value.source_location (), *this );
535
- if (!zero.has_value ())
536
- {
537
- error ().source_location = value.source_location ();
538
- error () << " cannot zero-initialize union component of type '"
539
- << to_string (component.type ()) << " '" << eom;
540
- throw 0 ;
541
- }
542
-
543
533
if (current_symbol.is_static_lifetime )
544
534
{
545
- byte_update_exprt byte_update{
546
- byte_update_id (), *dest, from_integer (0 , index_type ()), *zero};
547
- byte_update.add_source_location () = value.source_location ();
548
- *dest = std::move (byte_update);
549
- dest = &(to_byte_update_expr (*dest).op2 ());
535
+ const auto zero =
536
+ zero_initializer (component.type (), value.source_location (), *this );
537
+ if (!zero.has_value ())
538
+ {
539
+ error ().source_location = value.source_location ();
540
+ error () << " cannot zero-initialize union component of type '"
541
+ << to_string (component.type ()) << " '" << eom;
542
+ throw 0 ;
543
+ }
544
+
545
+ union_exprt union_expr (component.get_name (), *zero, type);
546
+ union_expr.add_source_location () = value.source_location ();
547
+ *dest = std::move (union_expr);
548
+ dest = &(to_union_expr (*dest).op ());
550
549
}
551
550
else
552
551
{
553
- union_exprt union_expr (component.get_name (), *zero, type);
552
+ const auto nondet = nondet_initializer (
553
+ component.type (), value.source_location (), *this );
554
+ if (!nondet.has_value ())
555
+ {
556
+ error ().source_location = value.source_location ();
557
+ error () << " cannot nondet-initialize union component of type '"
558
+ << to_string (component.type ()) << " '" << eom;
559
+ throw 0 ;
560
+ }
561
+
562
+ union_exprt union_expr (component.get_name (), *nondet, type);
554
563
union_expr.add_source_location () = value.source_location ();
555
564
*dest = std::move (union_expr);
556
565
dest = &(to_union_expr (*dest).op ());
0 commit comments