[Bug c/116892] forward declaration of enum followed by packed on the enum type causes an ICE in verify_type

2025-06-03 Thread uecker at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116892

uecker at gcc dot gnu.org changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #13 from uecker at gcc dot gnu.org ---
Fixed

[Bug c/116892] forward declaration of enum followed by packed on the enum type causes an ICE in verify_type

2025-06-03 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116892

--- Comment #12 from GCC Commits  ---
The master branch has been updated by Martin Uecker :

https://gcc.gnu.org/g:bd773888eafe34fb990041462df6d3a3c8a4217d

commit r16-1087-gbd773888eafe34fb990041462df6d3a3c8a4217d
Author: Martin Uecker 
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.

[Bug c/116892] forward declaration of enum followed by packed on the enum type causes an ICE in verify_type

2025-06-03 Thread uecker at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116892

--- Comment #11 from uecker at gcc dot gnu.org ---
(In reply to Richard Earnshaw from comment #10)
> (In reply to uecker from comment #9)
> > (In reply to Richard Earnshaw from comment #8)
> > > Forward declarations of enums in C requires c23, when you can use the size
> > > type specifier.  For earlier versions this isn't valid code.
> > 
> > Is is a GNU extension: 
> > https://gcc.gnu.org/onlinedocs/gcc/Enum-Extensions.html
> 
> 
> GCC has also traditionally supported forward declarations of enum types that
> don’t include an explicit underlying type specification. This results in an
> incomplete type, much like what you get if you write struct foo without
> describing the elements. 
> 
> You cannot allocate variables or storage using the type while it is
> incomplete.  
> 
> However, you can work with pointers to that type.
> 
> 
> So a prototype passing/returning a value is essentially defining the amount
> of storage the parameter would need for passing (to allow for sizing the
> parameter list).  That falls under the unsupported cases in situations like
> #c2.

A prototype with an incomplete type is fine, but you can not call it before it
is completed.  https://godbolt.org/z/4Meznhfdj

[Bug c/116892] forward declaration of enum followed by packed on the enum type causes an ICE in verify_type

2025-06-03 Thread rearnsha at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116892

--- Comment #10 from Richard Earnshaw  ---
(In reply to uecker from comment #9)
> (In reply to Richard Earnshaw from comment #8)
> > Forward declarations of enums in C requires c23, when you can use the size
> > type specifier.  For earlier versions this isn't valid code.
> 
> Is is a GNU extension: 
> https://gcc.gnu.org/onlinedocs/gcc/Enum-Extensions.html


GCC has also traditionally supported forward declarations of enum types that
don’t include an explicit underlying type specification. This results in an
incomplete type, much like what you get if you write struct foo without
describing the elements. 

You cannot allocate variables or storage using the type while it is
incomplete.  

However, you can work with pointers to that type.


So a prototype passing/returning a value is essentially defining the amount of
storage the parameter would need for passing (to allow for sizing the parameter
list).  That falls under the unsupported cases in situations like #c2.

[Bug c/116892] forward declaration of enum followed by packed on the enum type causes an ICE in verify_type

2025-06-03 Thread uecker at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116892

--- Comment #9 from uecker at gcc dot gnu.org ---
(In reply to Richard Earnshaw from comment #8)
> Forward declarations of enums in C requires c23, when you can use the size
> type specifier.  For earlier versions this isn't valid code.

Is is a GNU extension: 
https://gcc.gnu.org/onlinedocs/gcc/Enum-Extensions.html

[Bug c/116892] forward declaration of enum followed by packed on the enum type causes an ICE in verify_type

2025-06-03 Thread rearnsha at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116892

Richard Earnshaw  changed:

   What|Removed |Added

   Keywords|ice-on-valid-code   |ice-on-invalid-code

--- Comment #8 from Richard Earnshaw  ---
Forward declarations of enums in C requires c23, when you can use the size type
specifier.  For earlier versions this isn't valid code.

[Bug c/116892] forward declaration of enum followed by packed on the enum type causes an ICE in verify_type

2025-06-02 Thread uecker at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116892

--- Comment #7 from uecker at gcc dot gnu.org ---

PATCH: https://gcc.gnu.org/pipermail/gcc-patches/2025-June/685350.html

[Bug c/116892] forward declaration of enum followed by packed on the enum type causes an ICE in verify_type

2025-04-14 Thread uecker at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116892

--- Comment #6 from uecker at gcc dot gnu.org ---

Maybe something like that will do?

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 8c420f22976..fb1216fe808 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -10303,6 +10303,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 000..4cfa935eb72
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116892.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+
+
+enum fmt_type;
+
+void foo(const enum fmt_type a);
+
+enum [[gnu::packed]] fmt_type {
+  A
+} const a;
+

[Bug c/116892] forward declaration of enum followed by packed on the enum type causes an ICE in verify_type

2025-04-14 Thread mnowak at startmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116892

--- Comment #5 from Michal Nowak  ---
Something like this happens to me every time I build BIND 9's "main" branch
(https://gitlab.isc.org/isc-projects/bind9.git) with GCC 15 (15.0.1 20250413
from https://copr.fedorainfracloud.org/coprs/jwakely/gcc-latest/) on Fedora 41.

autoreconf -fi
CC=/opt/gcc-latest/bin/gcc CFLAGS="-fno-omit-frame-pointer
-fno-optimize-sibling-calls -O1 -g -Wall -Wextra" ./configure
--enable-developer --enable-dnstap --enable-geoip --with-libidn2
--disable-maintainer-mode --enable-option-checking=fatal --with-cmocka
--with-libxml2 --with-json-c --with-jemalloc --disable-tracing
make -j

In file included from stats.c:28:
./include/dns/stats.h:257:1: error: type variant differs by TYPE_PACKED
  257 | typedef void (*dns_opcodestats_dumper_t)(dns_opcode_t, uint64_t, void
*);
  | ^~~
 
unit-size 
align:16 warn_if_not_align:0 symtab:876718752 alias-set -1
canonical-type 0x7faa34622540 precision:16 min 
max 
pointer_to_this >
asm_written unsigned packed HI size 
unit-size 
align:16 warn_if_not_align:0 symtab:873521472 alias-set -1 canonical-type
0x7faa34622540
attributes > precision:16 min
 max 
values >
value 
VOID ./include/dns/types.h:312:2
align:1 warn_if_not_align:0 context  initial >
chain > value 
chain > value 
chain > value 
chain > value

chain  value  chain >>
chain >
 
unit-size 
align:16 warn_if_not_align:0 symtab:876718752 alias-set -1
canonical-type 0x7faa34622540 precision:16 min 
max 
pointer_to_this >
unsigned HI size  unit-size 
align:16 warn_if_not_align:0 symtab:873521392 alias-set -1 canonical-type
0x7faa34622540
attributes > precision:16 min
 max 
values >
value 
VOID ./include/dns/types.h:312:2
align:1 warn_if_not_align:0 context  initial >
chain > value 
chain > value 
chain > value 
chain > value

chain  value  chain >>
chain >