[C] Fix ICE with -g and -std=c23 related to incomplete types [PR114361]
Checks
Commit Message
I did not copy TYPE_CANONICAL to incomplete variants
when they are completed.
Bootstrapped and regession tested on x86_64
Fix ICE with -g and -std=c23 related to incomplete types [PR114361]
We did not copy TYPE_CANONICAL to the incomplete variants when
completing a structure.
PR c/114361
gcc/c/
* c-decl.c (finish_struct): Set TYPE_CANONICAL when completing
strucute types.
gcc/testsuite/
* gcc.dg/pr114361.c: New test.
* gcc.dg/c23-tag-incomplete-1.c: New test.
* gcc.dg/c23-tag-incomplete-2.c: New test.
---
gcc/c/c-decl.cc | 1 +
gcc/testsuite/gcc.dg/c23-tag-incomplete-1.c | 14 ++++++++++++++
gcc/testsuite/gcc.dg/c23-tag-incomplete-2.c | 13 +++++++++++++
gcc/testsuite/gcc.dg/pr114361.c | 11 +++++++++++
4 files changed, 39 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/c23-tag-incomplete-1.c
create mode 100644 gcc/testsuite/gcc.dg/c23-tag-incomplete-2.c
create mode 100644 gcc/testsuite/gcc.dg/pr114361.c
Comments
On Tue, 2 Apr 2024, Martin Uecker wrote:
> Fix ICE with -g and -std=c23 related to incomplete types [PR114361]
>
> We did not copy TYPE_CANONICAL to the incomplete variants when
> completing a structure.
>
> PR c/114361
>
> gcc/c/
> * c-decl.c (finish_struct): Set TYPE_CANONICAL when completing
> strucute types.
>
> gcc/testsuite/
> * gcc.dg/pr114361.c: New test.
> * gcc.dg/c23-tag-incomplete-1.c: New test.
> * gcc.dg/c23-tag-incomplete-2.c: New test.
OK.
@@ -9722,6 +9722,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
C_TYPE_VARIABLE_SIZE (x) = C_TYPE_VARIABLE_SIZE (t);
C_TYPE_VARIABLY_MODIFIED (x) = C_TYPE_VARIABLY_MODIFIED (t);
C_TYPE_INCOMPLETE_VARS (x) = NULL_TREE;
+ TYPE_CANONICAL (x) = TYPE_CANONICAL (t);
}
/* Update type location to the one of the definition, instead of e.g.
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-do compile }
+ * { dg-options "-std=c23 -g" } */
+
+struct a;
+typedef struct a b;
+
+void g() {
+ struct a { b* x; };
+}
+
+struct a { b* x; };
+
+
+
new file mode 100644
@@ -0,0 +1,13 @@
+/* { dg-do compile }
+ * { dg-options "-std=c23 -g" } */
+
+struct a;
+typedef struct a b;
+
+void f() {
+ extern struct a { b* x; } t;
+}
+
+extern struct a { b* x; } t;
+
+
new file mode 100644
@@ -0,0 +1,11 @@
+/* PR c/114361 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu23 -g" } */
+
+void f()
+{
+ typedef struct foo bar;
+ typedef __typeof( ({ (struct foo { bar *x; }){ }; }) ) wuz;
+ struct foo { wuz *x; };
+}
+