Hi!

We ICE on the following testcase, because the C FE abuses TYPE_VFIELD
for its FE stuff, but may leak it to the middle-end.
We clear it for TYPE_MAIN_VARIANT (and only use it for that), but
for the other variants it could be non-NULL, because build_variant_type*
would just copy that field over.

Fixed by clearing it on all the variant types.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-01-29  Jakub Jelinek  <ja...@redhat.com>

        PR debug/69518
        * c-decl.c (finish_struct): Clear C_TYPE_INCOMPLETE_VARS in
        all type variants, not just TYPE_MAIN_VARIANT.

        * gcc.dg/torture/pr69518.c: New test.

--- gcc/c/c-decl.c.jj   2016-01-27 20:32:17.000000000 +0100
+++ gcc/c/c-decl.c      2016-01-29 13:54:52.776583200 +0100
@@ -7842,6 +7842,14 @@ finish_struct (location_t loc, tree t, t
       }
   }
 
+  /* Note: C_TYPE_INCOMPLETE_VARS overloads TYPE_VFIELD which is used
+     in dwarf2out via rest_of_decl_compilation below and means
+     something totally different.  Since we will be clearing
+     C_TYPE_INCOMPLETE_VARS shortly after we iterate through them,
+     clear it ahead of time and avoid problems in dwarf2out.  Ideally,
+     C_TYPE_INCOMPLETE_VARS should use some language specific
+     node.  */
+  tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
   for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
     {
       TYPE_FIELDS (x) = TYPE_FIELDS (t);
@@ -7849,6 +7857,7 @@ finish_struct (location_t loc, tree t, t
       C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
       C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
       C_TYPE_VARIABLE_SIZE (x) = C_TYPE_VARIABLE_SIZE (t);
+      C_TYPE_INCOMPLETE_VARS (x) = NULL_TREE;
     }
 
   /* If this was supposed to be a transparent union, but we can't
@@ -7862,17 +7871,7 @@ finish_struct (location_t loc, tree t, t
     }
 
   /* If this structure or union completes the type of any previous
-     variable declaration, lay it out and output its rtl.
-
-     Note: C_TYPE_INCOMPLETE_VARS overloads TYPE_VFIELD which is used
-     in dwarf2out via rest_of_decl_compilation below and means
-     something totally different.  Since we will be clearing
-     C_TYPE_INCOMPLETE_VARS shortly after we iterate through them,
-     clear it ahead of time and avoid problems in dwarf2out.  Ideally,
-     C_TYPE_INCOMPLETE_VARS should use some language specific
-     node.  */
-  tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
-  C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0;
+     variable declaration, lay it out and output its rtl.  */
   for (x = incomplete_vars; x; x = TREE_CHAIN (x))
     {
       tree decl = TREE_VALUE (x);
--- gcc/testsuite/gcc.dg/torture/pr69518.c.jj   2016-01-29 13:52:22.547656581 
+0100
+++ gcc/testsuite/gcc.dg/torture/pr69518.c      2016-01-29 13:52:03.000000000 
+0100
@@ -0,0 +1,11 @@
+/* PR debug/69518 */
+/* { dg-do compile } */
+/* { dg-options "-g" } */
+
+struct A a;
+typedef struct A B;
+struct A {}
+foo (B x)
+{
+  __builtin_abort ();
+}

        Jakub

Reply via email to