From bd773888eafe34fb990041462df6d3a3c8a4217d Mon Sep 17 00:00:00 2001 From: Martin Uecker Date: Sun, 1 Jun 2025 22:30:42 +0200 Subject: [PATCH] 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. --- gcc/c/c-decl.cc | 1 + gcc/testsuite/gcc.dg/pr116892.c | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr116892.c diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 1008bcaebdc..2b0bd663ba9 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 00000000000..7eb431b9573 --- /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; + -- 2.47.2