This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix C global decl handling regression in 4.0.2 from 4.0.1


Hi!

PR23190 introduced a regression which shows up e.g. on Linux kernel.
Unlike wrapup_global_declarations in toplev.c, c_write_global_declarations_1
doesn't cycle through decls again when any declarations have been output.
So if some global decl is only referenced by another one that comes later
in the global list, it is not rest_of_decl_compilation'ed.
The testcase only fails on 4.0.2, as HEAD doesn't seem to queue the decls
up and emits them immediately, but still the patch IMHO makes sense there.

Ok for 4.0/HEAD if bootstrap succeeds?

2005-09-29  Jakub Jelinek  <jakub@redhat.com>

	* c-decl.c (c_write_global_declarations_1): If any
	wrapup_global_declaration_2 call returned true, restart the loop.

	* gcc.c-torture/execute/20050929-1.c: New test.

--- gcc/c-decl.c.jj	2005-09-28 21:12:06.000000000 +0200
+++ gcc/c-decl.c	2005-09-29 10:01:41.000000000 +0200
@@ -7527,6 +7527,7 @@ static void
 c_write_global_declarations_1 (tree globals)
 {
   tree decl;
+  bool reconsider;
 
   /* Process the decls in the order they were written.  */
   for (decl = globals; decl; decl = TREE_CHAIN (decl))
@@ -7545,9 +7546,18 @@ c_write_global_declarations_1 (tree glob
 	}
 
       wrapup_global_declaration_1 (decl);
-      wrapup_global_declaration_2 (decl);
-      check_global_declaration_1 (decl);
     }
+
+  do
+    {
+      reconsider = false;
+      for (decl = globals; decl; decl = TREE_CHAIN (decl))
+	reconsider |= wrapup_global_declaration_2 (decl);
+    }
+  while (reconsider);
+
+  for (decl = globals; decl; decl = TREE_CHAIN (decl))
+    check_global_declaration_1 (decl);
 }
 
 /* A subroutine of c_write_global_declarations Emit debug information for each
--- gcc/testsuite/gcc.c-torture/execute/20050929-1.c.jj	2005-09-29 10:18:38.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/execute/20050929-1.c	2005-09-29 10:07:06.000000000 +0200
@@ -0,0 +1,20 @@
+/* PR middle-end/24109 */
+
+extern void abort (void);
+
+struct A { int i; int j; };
+struct B { struct A *a; struct A *b; };
+struct C { struct B *c; struct A *d; };
+struct C e = { &(struct B) { &(struct A) { 1, 2 }, &(struct A) { 3, 4 } }, &(struct A) { 5, 6 } };
+
+int
+main (void)
+{
+  if (e.c->a->i != 1 || e.c->a->j != 2)
+    abort ();
+  if (e.c->b->i != 3 || e.c->b->j != 4)
+    abort ();
+  if (e.d->i != 5 || e.d->j != 6)
+    abort ();
+  return 0;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]