public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Fix up value initialization of structs with zero width bitfields [PR102019]
@ 2021-08-23 20:16 Jakub Jelinek
  2021-08-25 20:26 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2021-08-23 20:16 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

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.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

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

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

--- gcc/cp/init.c.jj	2021-07-29 13:24:42.698012879 +0200
+++ gcc/cp/init.c	2021-08-23 14:43:08.791947395 +0200
@@ -427,6 +427,11 @@ build_value_init_noctor (tree type, tsub
 		      == 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

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: Fix up value initialization of structs with zero width bitfields [PR102019]
  2021-08-23 20:16 [PATCH] c++: Fix up value initialization of structs with zero width bitfields [PR102019] Jakub Jelinek
@ 2021-08-25 20:26 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2021-08-25 20:26 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On 8/23/21 4:16 PM, Jakub Jelinek wrote:
> Hi!
> 
> 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.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

OK.

> 2021-08-23  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/102019
> 	* init.c (build_value_init_noctor): Ignore unnamed zero-width
> 	bitfields.
> 
> --- gcc/cp/init.c.jj	2021-07-29 13:24:42.698012879 +0200
> +++ gcc/cp/init.c	2021-08-23 14:43:08.791947395 +0200
> @@ -427,6 +427,11 @@ build_value_init_noctor (tree type, tsub
>   		      == 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
> 
> 	Jakub
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-25 20:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23 20:16 [PATCH] c++: Fix up value initialization of structs with zero width bitfields [PR102019] Jakub Jelinek
2021-08-25 20:26 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).