[gcc r16-1087] c: fix ICE with enum completed with packed attribute after forward decl [PR116892]
Martin Uecker
uecker@gcc.gnu.org
Tue Jun 3 16:42:06 GMT 2025
https://gcc.gnu.org/g:bd773888eafe34fb990041462df6d3a3c8a4217d
commit r16-1087-gbd773888eafe34fb990041462df6d3a3c8a4217d
Author: Martin Uecker <uecker@tugraz.at>
Date: Sun Jun 1 22:30:42 2025 +0200
c: fix ICE with enum completed with packed attribute after forward decl [PR116892]
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.
Diff:
---
gcc/c/c-decl.cc | 1 +
gcc/testsuite/gcc.dg/pr116892.c | 11 +++++++++++
2 files changed, 12 insertions(+)
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 1008bcaebdc9..2b0bd663ba91 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -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
index 000000000000..7eb431b9573f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116892.c
@@ -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;
+
More information about the Gcc-cvs
mailing list