]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: fix ICE with enum completed with packed attribute after forward decl [PR116892]
authorMartin Uecker <uecker@tugraz.at>
Sun, 1 Jun 2025 20:30:42 +0000 (22:30 +0200)
committerMartin Uecker <uecker@gcc.gnu.org>
Tue, 3 Jun 2025 16:41:46 +0000 (18:41 +0200)
After forward declaration of an enum and when completing it with the
attribute packed, we need to propagate TYPE_PACKED to all main variants.

PR c/116892

gcc/c/ChangeLog:
* c-decl.cc (finish_enum): Propagate TYPE_PACKED.

gcc/testsuite/ChangeLog:
* gcc.dg/pr116892.c: New test.

gcc/c/c-decl.cc
gcc/testsuite/gcc.dg/pr116892.c [new file with mode: 0644]

index 1008bcaebdc9f4cfb0e7b4895fa46ea9222934b7..2b0bd663ba911b7883bbb0a5ef4e3bfe15e8f98b 100644 (file)
@@ -10293,6 +10293,7 @@ finish_enum (tree enumtype, tree values, tree attributes)
       TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
       TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
       ENUM_UNDERLYING_TYPE (tem) = ENUM_UNDERLYING_TYPE (enumtype);
+      TYPE_PACKED (tem) = TYPE_PACKED (enumtype);
     }
 
   /* Finish debugging output for this type.  */
diff --git a/gcc/testsuite/gcc.dg/pr116892.c b/gcc/testsuite/gcc.dg/pr116892.c
new file mode 100644 (file)
index 0000000..7eb431b
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-g -std=gnu23" } */
+
+enum fmt_type;
+
+void foo(const enum fmt_type a);
+
+enum [[gnu::packed]] fmt_type {
+  A
+} const a;
+