I had accidentally swapped dg-warning and dg-error in the test for the last version. I will commit this one if it passes checks.
Martin 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 --git a/gcc/c/c-objc-common.cc b/gcc/c/c-objc-common.cc index 2016eaebf17..d574bc77128 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 00000000000..9e3f616dbbb --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr120380.c @@ -0,0 +1,23 @@ +/* PR c/120380 */ +/* { dg-do compile } */ + +struct pair_t { + char c; + int i; +}; +typedef struct foo_ { + struct foo_ { /* { dg-error "nested redefinition" } */ + 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; +} +