12
12
#include " c_typecheck_base.h"
13
13
14
14
#include < util/arith_tools.h>
15
+ #include < util/byte_operators.h>
15
16
#include < util/c_types.h>
16
17
#include < util/config.h>
17
18
#include < util/cprover_prefix.h>
@@ -518,13 +519,15 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
518
519
{
519
520
// Already right union component. We can initialize multiple submembers,
520
521
// so do not overwrite this.
522
+ dest = &(to_union_expr (*dest).op ());
521
523
}
522
524
else
523
525
{
524
526
// The first component is not the maximum member, which the (default)
525
527
// zero initializer prepared. Replace this by a component-specific
526
528
// initializer; other bytes have an unspecified value (C Standard
527
- // 6.2.6.1(7)).
529
+ // 6.2.6.1(7)). In practice, objects of static lifetime are fully zero
530
+ // initialized.
528
531
const auto zero =
529
532
zero_initializer (component.type (), value.source_location (), *this );
530
533
if (!zero.has_value ())
@@ -534,12 +537,23 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
534
537
<< to_string (component.type ()) << " '" << eom;
535
538
throw 0 ;
536
539
}
537
- union_exprt union_expr (component.get_name (), *zero, type);
538
- union_expr.add_source_location ()=value.source_location ();
539
- *dest=union_expr;
540
- }
541
540
542
- dest = &(to_union_expr (*dest).op ());
541
+ if (current_symbol.is_static_lifetime )
542
+ {
543
+ byte_update_exprt byte_update{
544
+ byte_update_id (), *dest, from_integer (0 , index_type ()), *zero};
545
+ byte_update.add_source_location () = value.source_location ();
546
+ *dest = std::move (byte_update);
547
+ dest = &(to_byte_update_expr (*dest).op2 ());
548
+ }
549
+ else
550
+ {
551
+ union_exprt union_expr (component.get_name (), *zero, type);
552
+ union_expr.add_source_location () = value.source_location ();
553
+ *dest = std::move (union_expr);
554
+ dest = &(to_union_expr (*dest).op ());
555
+ }
556
+ }
543
557
}
544
558
else
545
559
UNREACHABLE;
0 commit comments