public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c: Avoid ICE with _BitInt(N) : 0 bitfield [PR113740]
@ 2024-02-05  7:57 Jakub Jelinek
  2024-02-05 13:12 ` Marek Polacek
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2024-02-05  7:57 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches

Hi!

finish_struct already made sure not to call build_bitint_type for
signed _BitInt(2) : 1;
or
signed _BitInt(2) : 0;
bitfields (but instead build a zero precision integral type,
we remove it later), this patch makes sure we do it also for
unsigned _BitInt(1) : 0;
because of the build_bitint_type assertion that precision is
>= (unsigned ? 1 : 2).

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

2024-02-05  Jakub Jelinek  <jakub@redhat.com>

	PR c/113740
	* c-decl.cc (finish_struct): Only use build_bitint_type if
	bit-field has width larger or equal to minimum _BitInt
	precision.

	* gcc.dg/bitint-85.c: New test.

--- gcc/c/c-decl.cc.jj	2024-02-01 09:14:16.474551596 +0100
+++ gcc/c/c-decl.cc	2024-02-03 13:03:35.272479105 +0100
@@ -9555,7 +9555,7 @@ finish_struct (location_t loc, tree t, t
 	  if (width != TYPE_PRECISION (type))
 	    {
 	      if (TREE_CODE (type) == BITINT_TYPE
-		  && (width > 1 || TYPE_UNSIGNED (type)))
+		  && width >= (TYPE_UNSIGNED (type) ? 1 : 2))
 		TREE_TYPE (field)
 		  = build_bitint_type (width, TYPE_UNSIGNED (type));
 	      else
--- gcc/testsuite/gcc.dg/bitint-85.c.jj	2024-02-03 13:05:49.162639344 +0100
+++ gcc/testsuite/gcc.dg/bitint-85.c	2024-02-03 13:05:39.489772259 +0100
@@ -0,0 +1,5 @@
+/* PR c/113740 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23" } */
+
+struct S { unsigned _BitInt(32) : 0; };

	Jakub


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

* Re: [PATCH] c: Avoid ICE with _BitInt(N) : 0 bitfield [PR113740]
  2024-02-05  7:57 [PATCH] c: Avoid ICE with _BitInt(N) : 0 bitfield [PR113740] Jakub Jelinek
@ 2024-02-05 13:12 ` Marek Polacek
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Polacek @ 2024-02-05 13:12 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Joseph S. Myers, gcc-patches

On Mon, Feb 05, 2024 at 08:57:18AM +0100, Jakub Jelinek wrote:
> Hi!
> 
> finish_struct already made sure not to call build_bitint_type for
> signed _BitInt(2) : 1;
> or
> signed _BitInt(2) : 0;
> bitfields (but instead build a zero precision integral type,
> we remove it later), this patch makes sure we do it also for
> unsigned _BitInt(1) : 0;
> because of the build_bitint_type assertion that precision is
> >= (unsigned ? 1 : 2).
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK, thanks.
 
> 2024-02-05  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c/113740
> 	* c-decl.cc (finish_struct): Only use build_bitint_type if
> 	bit-field has width larger or equal to minimum _BitInt
> 	precision.
> 
> 	* gcc.dg/bitint-85.c: New test.
> 
> --- gcc/c/c-decl.cc.jj	2024-02-01 09:14:16.474551596 +0100
> +++ gcc/c/c-decl.cc	2024-02-03 13:03:35.272479105 +0100
> @@ -9555,7 +9555,7 @@ finish_struct (location_t loc, tree t, t
>  	  if (width != TYPE_PRECISION (type))
>  	    {
>  	      if (TREE_CODE (type) == BITINT_TYPE
> -		  && (width > 1 || TYPE_UNSIGNED (type)))
> +		  && width >= (TYPE_UNSIGNED (type) ? 1 : 2))
>  		TREE_TYPE (field)
>  		  = build_bitint_type (width, TYPE_UNSIGNED (type));
>  	      else
> --- gcc/testsuite/gcc.dg/bitint-85.c.jj	2024-02-03 13:05:49.162639344 +0100
> +++ gcc/testsuite/gcc.dg/bitint-85.c	2024-02-03 13:05:39.489772259 +0100
> @@ -0,0 +1,5 @@
> +/* PR c/113740 */
> +/* { dg-do compile { target bitint } } */
> +/* { dg-options "-std=c23" } */
> +
> +struct S { unsigned _BitInt(32) : 0; };
> 
> 	Jakub
> 

Marek


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

end of thread, other threads:[~2024-02-05 13:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-05  7:57 [PATCH] c: Avoid ICE with _BitInt(N) : 0 bitfield [PR113740] Jakub Jelinek
2024-02-05 13:12 ` Marek Polacek

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).