This fixes an error recovery issue.
Bootstrapped and regression tested for x86_64. 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..b7b9c74bdf7 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 qualifiers here because the 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..7f50936d80f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr120380.c @@ -0,0 +1,24 @@ +/* PR c/120380 */ +/* { dg-do compile } */ + +struct pair_t { + char c; + __int128_t i; +} __attribute__((packed)); +typedef struct unaligned_int128_t_ { /* { dg-error "no members" } */ + struct unaligned_int128_t_ { /* { dg-error "nested redefinition" } */ + /* { dg-error "no members" "" { target *-*-* } .-1 } */ + struct unaligned_int128_t_ { /* { dg-error "nested redefinition" } */ + __int128_t value; + } + } /* { dg-error "does not declare anything" } */ + /* { dg-error "no semicolon" "" { target *-*-* } .-1 } */ +} __attribute__((packed, may_alias)) unaligned_int128_t; /* { dg-error "does not declare anything" } */ + /* { dg-error "no semicolon" "" { target *-*-* } .-1 } */ +struct pair_t p = {0, 1}; +unaligned_int128_t *addr = (unaligned_int128_t *)&p.i; +int main() { + addr->value = 0; /* { dg-error "has no member" } */ + return 0; +} +