public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C PATCH]  Fix ICE for composite type for structs with unsigned bitfields [PR113492]
@ 2024-01-20 18:37 Martin Uecker
  2024-01-20 23:36 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Uecker @ 2024-01-20 18:37 UTC (permalink / raw)
  To: gcc-patches; +Cc: Joseph Myers


C23: Fix ICE for composite type for structs with unsigned bitfields [PR113492]
    
This patch fixes a bug when forming a composite type from structs that
contain an unsigned bitfield declared with int while using -funsigned-bitfields.
In such structs the unsigned integer type was not compatible to the
regular unsigned integer type used elsewhere in the C FE.
    
	PR c/113492

gcc/c:
	* c-decl.cc (grokdeclarator): Use c_common_unsigned_type instead of
 	unsigned_type_for to create the unsigned type for bitfields declared
	with int when using -funsigned-bitfields.
    
gcc/testsuite:
	* gcc.dg/pr113492.c: New test.




diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 4029bbc59fe..8d18a3e11f4 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -6947,7 +6947,7 @@ grokdeclarator (const struct c_declarator *declarator,
      "signed".  */
   if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
       && TREE_CODE (type) == INTEGER_TYPE)
-    type = unsigned_type_for (type);
+    type = c_common_unsigned_type (type);
 
   /* Figure out the type qualifiers for the declaration.  There are
      two ways a declaration can become qualified.  One is something
diff --git a/gcc/testsuite/gcc.dg/pr113492.c b/gcc/testsuite/gcc.dg/pr113492.c
new file mode 100644
index 00000000000..56296c51072
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr113492.c
@@ -0,0 +1,43 @@
+/* PR 113492
+ * { dg-do compile }
+ * { dg-options "-std=c23 -funsigned-bitfields" } */
+
+struct foo {
+	int i : 3;
+} i;
+
+void test()
+{
+	struct foo {
+		unsigned i : 3;
+	} u;
+
+	1 ? i : u;
+	1 ? u : i;
+}
+	
+struct bar {
+	unsigned i : 3;
+} u;
+
+void test2()
+{
+	struct bar {
+		int i : 3;
+	} i;
+
+	1 ? i : u;
+	1 ? u : i;
+}
+	
+void test3()
+{
+	typedef int myint;
+	struct bar {
+		myint i : 3;
+	} i;
+
+	1 ? i : u;
+	1 ? u : i;
+}
+


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

* Re: [C PATCH]  Fix ICE for composite type for structs with unsigned bitfields [PR113492]
  2024-01-20 18:37 [C PATCH] Fix ICE for composite type for structs with unsigned bitfields [PR113492] Martin Uecker
@ 2024-01-20 23:36 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2024-01-20 23:36 UTC (permalink / raw)
  To: Martin Uecker; +Cc: gcc-patches

On Sat, 20 Jan 2024, Martin Uecker wrote:

> C23: Fix ICE for composite type for structs with unsigned bitfields [PR113492]
>     
> This patch fixes a bug when forming a composite type from structs that
> contain an unsigned bitfield declared with int while using -funsigned-bitfields.
> In such structs the unsigned integer type was not compatible to the
> regular unsigned integer type used elsewhere in the C FE.
>     
> 	PR c/113492
> 
> gcc/c:
> 	* c-decl.cc (grokdeclarator): Use c_common_unsigned_type instead of
>  	unsigned_type_for to create the unsigned type for bitfields declared
> 	with int when using -funsigned-bitfields.
>     
> gcc/testsuite:
> 	* gcc.dg/pr113492.c: New test.

OK.

-- 
Joseph S. Myers
josmyers@redhat.com


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

end of thread, other threads:[~2024-01-20 23:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-20 18:37 [C PATCH] Fix ICE for composite type for structs with unsigned bitfields [PR113492] Martin Uecker
2024-01-20 23:36 ` Joseph Myers

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