Am Donnerstag, dem 29.05.2025 um 20:57 +0000 schrieb Joseph Myers:
> On Thu, 29 May 2025, Martin Uecker wrote:
> 
> >     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.
> 
> > +  /* For tagged types ignore qualifiers here because the will
> > +     otherwise be ignored later causing a warning inside diagnostics
> > +     which leads to an ICE.  */
> 
> Do you mean ignore attributes (as in the proposed commit message) or 
> qualifiers (as in the comment)?  Also, "the will" -> "they will" (I 
> think).

Fixed. I also changed and simplified the testcase because it failedĀ 

https://patchwork.sourceware.org/project/gcc/patch/c7197ef34c26a352097e9e0b876e1bed29fbd036.ca...@tugraz.at/

as __int128_t is not defined. I do not understand why there is a difference,
but int is enough anyway.


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..17ff083ad83
--- /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-warning "does not declare 
anything" } */
+                                       /* { dg-warning "no semicolon" "" { 
target *-*-* } .-1 } */
+} __attribute__((packed)) foo;         /* { dg-warning "does not declare 
anything" } */
+                                       /* { dg-warning "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;
+}
+

Reply via email to