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]

[incremental] Patch: FYI: handle re-builds


I'm checking this in on the incremental compiler branch.

This patch fixes a couple miscellaneous bugs and also makes it
possible for re-builds to work.  That is, "make; make clean; make"
works fine with the server now.  (Well, "fine" -- we still emit an
incorrect warning when re-building.)

There were a few problems with this previously:

* When re-binding we were not passing function definitions to
  cgraph_finalize_function.  Oops.

* Decls for builtins were chained via their TREE_CHAIN, which was
  overwritten when popping a scope.

* We were smashing decls that were put into the external scope.

* We need to re-register a smashed decl when re-binding.

I'm not happy with the details of this patch -- more for the cleanup
list.

Tom

ChangeLog:
2007-10-04  Tom Tromey  <tromey@redhat.com>

	* c-decl.c (bind): Note a smash when needed.
	(c_decl_re_bind): Pass function definitions to
	cgraph_finalize_function.
	(c_builtin_function): Don't use decl's TREE_CHAIN for
	visible_builtins linked list.
	(push_file_scope): Update.
	(duplicate_decls): Also avoid smashing objects in external scope.
	(start_function): Don't call c_parser_note_smash.
	* toplev.c (start_as): Fix argv argument to pex_run.

Index: toplev.c
===================================================================
--- toplev.c	(revision 128925)
+++ toplev.c	(working copy)
@@ -2205,7 +2205,7 @@
 	 redeclared in a number of files.  Yay.  */
       asm_out_file = pex_input_pipe (px, 0);
 
-      errstr = pex_run (px, PEX_LAST | PEX_SEARCH, as_argv[0], as_argv + 1,
+      errstr = pex_run (px, PEX_LAST | PEX_SEARCH, as_argv[0], as_argv,
 			NULL, NULL, &pxerr);
       if (errstr)
 	{
Index: c-decl.c
===================================================================
--- c-decl.c	(revision 128875)
+++ c-decl.c	(working copy)
@@ -516,6 +516,10 @@
   while (*here && (*here)->depth > scope->depth)
     here = &(*here)->shadowed;
 
+  if (!notify_ok && *here && (*here)->depth == scope->depth
+      && B_IN_FILE_SCOPE (scope)) /* FIXME: zenity crash w/o this here... */
+    c_parser_note_smash ((*here)->decl, decl);
+
   b->shadowed = *here;
   *here = b;
 }
@@ -540,8 +544,14 @@
 	  /*notify_ok=*/false);
 
   TREE_ASM_WRITTEN (decl) = 0;
-  if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
+  if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
     {
+      /* Function has already been genericized, so just tell cgraph
+	 about it.  */
+      cgraph_finalize_function (decl, false);
+    }
+  else if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
+    {
       /* FIXME: moral equivalent of decl smashing here.  */
       if (DECL_INITIAL (decl) == NULL_TREE
 	  || DECL_INITIAL (decl) == error_mark_node)
@@ -942,7 +952,7 @@
 void
 push_file_scope (void)
 {
-  tree decl;
+  tree iter;
 
   if (file_scope)
     return;
@@ -952,9 +962,15 @@
 
   start_fname_decls ();
 
-  for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl))
-    bind (DECL_NAME (decl), decl, file_scope,
-	  /*invisible=*/false, /*nested=*/true, /*notify_ok=*/true);
+  /* FIXME: some overlap between visible_builtins and all_c_built_ins.
+     Also, visible_builtins should probably be a set rather than using
+     tree_cons.  */
+  for (iter = visible_builtins; iter; iter = TREE_CHAIN (iter))
+    {
+      tree decl = TREE_VALUE (iter);
+      bind (DECL_NAME (decl), decl, file_scope,
+	    /*invisible=*/false, /*nested=*/true, /*notify_ok=*/true);
+    }
 }
 
 void
@@ -2085,7 +2101,12 @@
 
   if (need_merge)
     {
-      if (B_IN_FILE_SCOPE (binding) && !object_in_current_hunk_p (olddecl))
+      /* Objects in any non-local scope have to be duplicated here,
+	 since we do not want to smash any generally visible (and
+	 reusable) decl.  FIXME: should make just one duplicate for
+	 both scopes.  */
+      if ((B_IN_FILE_SCOPE (binding) || B_IN_EXTERNAL_SCOPE (binding))
+	  && !object_in_current_hunk_p (olddecl))
 	{
 	  /* Modify a copy of OLDDECL and install that in the
 	     bindings.  */
@@ -2096,6 +2117,7 @@
 	  /* FIXME: this triggers building libgcc.  */
 /* 	  gcc_assert (binding->decl == olddecl); */
 	  binding->decl = copy;
+	  c_parser_bind_callback (DECL_NAME (copy), copy);
 	  c_parser_note_smash (olddecl, copy);
 	}
       else
@@ -3076,8 +3098,9 @@
       slot = htab_find_slot (all_c_built_ins, decl, INSERT);
       *slot = decl;
 
-      TREE_CHAIN (decl) = visible_builtins;
-      visible_builtins = decl;
+      /* We use tree_cons here rather than the decl's TREE_CHAIN as
+	 the latter is re-used when popping scopes.  */
+      visible_builtins = tree_cons (NULL_TREE, decl, visible_builtins);
     }
 
   return decl;
@@ -6497,10 +6520,7 @@
   /* Record the decl so that the function name is defined.
      If we already have a decl for this name, note that we smashed it.  */
 
-  old_decl = pushdecl (decl1);
-  if (decl1 != old_decl)
-    c_parser_note_smash (old_decl, decl1);
-  current_function_decl = decl1;
+  current_function_decl = pushdecl (decl1);
 
   push_scope ();
   declare_parm_level ();


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