diff mbox series

c: Fix ICE for redeclaration of structs with different alignment [PR114727]

Message ID d05a7c35c992449d15b026d913d7f8efcd62ef0f.camel@tugraz.at
State New
Headers show
Series c: Fix ICE for redeclaration of structs with different alignment [PR114727] | expand

Commit Message

Martin Uecker June 29, 2024, 3:04 p.m. UTC
This fixes an ICE when redeclaring a struct and having
an aligned attribute in one version in C23.


Bootstrapped and regression tested on x86_64.



    c: Fix ICE for redeclaration of structs with different alignment [PR114727]
    
    For redeclarations of struct in C23, if one has an alignment attribute
    that makes the alignment different, we later get an ICE in verify_types.
    This patches disallows such redeclarations by declaring such types to
    be different.
    
            PR c/114727
    
    gcc/c/
            * c-typeck.cc (tagged_types_tu_compatible): Add test.
    
    gcc/testsuite/
            * gcc.dg/pr114727.c: New test.

Comments

Joseph Myers July 9, 2024, 5:31 p.m. UTC | #1
On Sat, 29 Jun 2024, Martin Uecker wrote:

> This fixes an ICE when redeclaring a struct and having
> an aligned attribute in one version in C23.
> 
> 
> Bootstrapped and regression tested on x86_64.
> 
> 
> 
>     c: Fix ICE for redeclaration of structs with different alignment [PR114727]
>     
>     For redeclarations of struct in C23, if one has an alignment attribute
>     that makes the alignment different, we later get an ICE in verify_types.
>     This patches disallows such redeclarations by declaring such types to
>     be different.
>     
>             PR c/114727
>     
>     gcc/c/
>             * c-typeck.cc (tagged_types_tu_compatible): Add test.
>     
>     gcc/testsuite/
>             * gcc.dg/pr114727.c: New test.

OK.
diff mbox series

Patch

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index e486ac04f9c..455dc374b48 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -1603,6 +1603,9 @@  tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
 	  != TYPE_REVERSE_STORAGE_ORDER (t2)))
     return false;
 
+  if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
+    data->different_types_p = true;
+
   /* For types already being looked at in some active
      invocation of this function, assume compatibility.
      The cache is built as a linked list on the stack
diff --git a/gcc/testsuite/gcc.dg/pr114727.c b/gcc/testsuite/gcc.dg/pr114727.c
new file mode 100644
index 00000000000..12949590ce0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114727.c
@@ -0,0 +1,6 @@ 
+/* { dg-do compile }
+ * { dg-options "-std=c23 -g" } */
+
+#define Y [[gnu::aligned(128)]]
+extern struct Y foo { int x; } x;
+struct foo { int x; };		/* { dg-error "redefinition" } */