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