c++: Fix up value initialization of structs with zero width bitfields [PR102019]
authorJakub Jelinek <jakub@redhat.com>
Wed, 25 Aug 2021 20:35:21 +0000 (22:35 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 25 Aug 2021 20:35:57 +0000 (22:35 +0200)
The removal of remove_zero_width_bit_fields, in addition to triggering
some ABI issues that need solving anyway (ABI incompatibility between
C and C++) also resulted in UB inside of gcc, we now call build_zero_init
which calls build_int_cst on an integral type with TYPE_PRECISION of 0.

Fixed by ignoring the zero width bitfields.  I understand
build_value_init_noctor wants to initialize to 0 even unnamed bitfields
(of non-zero width), at least until we have some CONSTRUCTOR flag that says
that even all the padding bits should be cleared.

2021-08-25  Jakub Jelinek  <jakub@redhat.com>

PR c++/102019
* init.c (build_value_init_noctor): Ignore unnamed zero-width
bitfields.

gcc/cp/init.c

index 229c84e..1426f9a 100644 (file)
@@ -427,6 +427,11 @@ build_value_init_noctor (tree type, tsubst_flags_t complain)
                      == NULL_TREE))
                continue;
 
+             /* Ignore unnamed zero-width bitfields.  */
+             if (DECL_UNNAMED_BIT_FIELD (field)
+                 && integer_zerop (DECL_SIZE (field)))
+               continue;
+
              /* We could skip vfields and fields of types with
                 user-defined constructors, but I think that won't improve
                 performance at all; it should be simpler in general just