https://gcc.gnu.org/g:b2c8d3064764f1f4bfd41d8791d06f2206b42780
commit r16-1036-gb2c8d3064764f1f4bfd41d8791d06f2206b42780 Author: Martin Uecker <uec...@tugraz.at> Date: Thu May 29 17:17:12 2025 +0200 c: fix ICE related to tagged types with attributes in diagnostics [PR120380] get_aka_type will create a new type for diagnostics, but for tagged types attributes will then be ignored with a warning. This can lead to reentering warning code which leads to an ICE. Fix this by ignoring the attributes for tagged types. PR c/120380 gcc/c/ChangeLog: * c-objc-common.cc (get_aka_type): Ignore attributes for tagged types. gcc/testsuite/ChangeLog: * gcc.dg/pr120380.c: New test. Diff: --- gcc/c/c-objc-common.cc | 5 +++++ gcc/testsuite/gcc.dg/pr120380.c | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/gcc/c/c-objc-common.cc b/gcc/c/c-objc-common.cc index 2016eaebf17c..d574bc771289 100644 --- a/gcc/c/c-objc-common.cc +++ b/gcc/c/c-objc-common.cc @@ -216,6 +216,11 @@ get_aka_type (tree type) return canonical ? canonical : type; } } + /* For tagged types ignore attributes because they will otherwise + be ignored later causing a warning inside diagnostics which leads + to an ICE. */ + if (RECORD_OR_UNION_TYPE_P (type) || TREE_CODE (type) == ENUMERAL_TYPE) + return build_qualified_type (result, TYPE_QUALS (type)); return build_type_attribute_qual_variant (result, TYPE_ATTRIBUTES (type), TYPE_QUALS (type)); } diff --git a/gcc/testsuite/gcc.dg/pr120380.c b/gcc/testsuite/gcc.dg/pr120380.c new file mode 100644 index 000000000000..10577a196c77 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr120380.c @@ -0,0 +1,24 @@ +/* PR c/120380 */ +/* { dg-do compile } */ + +struct pair_t { + char c; + int i; +}; +typedef struct foo_ { /* { dg-error "no member" } */ + struct foo_ { /* { dg-error "nested redefinition" } */ + /* { dg-error "no member" "" { target *-*-* } .-1 } */ + struct foo_ { /* { dg-error "nested redefinition" } */ + int value; + } + } /* { dg-error "does not declare anything" } */ + /* { dg-error "no semicolon" "" { target *-*-* } .-1 } */ +} __attribute__((packed)) foo; /* { dg-error "does not declare anything" } */ + /* { dg-error "no semicolon" "" { target *-*-* } .-1 } */ +struct pair_t p = {0, 1}; +foo *addr = (foo *)&p.i; +int main() { + addr->value = 0; /* { dg-error "has no member" } */ + return 0; +} +