[incremental] Patch: FYI: cgraph and pushdecl fixlets

Tom Tromey tromey@redhat.com
Mon Oct 8 21:45:00 GMT 2007


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

This patch changes the new cgraph_note_duplicate to cope with the
situation where a duplicate is added after a function has been
defined.

It also fixes a buglet in pushdecl where we could update an external
binding with a merged decl but fail to update the file scope binding
-- i.e., pushdecl was apparently relying on decl smashing behavior.
This part of the patch is kind of a hack and pushdecl requires further
study.

Tom

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

	* c-decl.c (pushdecl): Update file scope decl as well.
	* cgraph.c (cgraph_note_duplicate): Swap decl and duplicate when
	function already defined.
	* cgraphbuild.c (record_reference): Don't canonicalize decl.

Index: cgraphbuild.c
===================================================================
--- cgraphbuild.c	(revision 128875)
+++ cgraphbuild.c	(working copy)
@@ -59,7 +59,7 @@
 	     functions reachable unconditionally.  */
 	  tree decl = TREE_OPERAND (*tp, 0);
 	  if (TREE_CODE (decl) == FUNCTION_DECL)
-	    cgraph_mark_needed_node (cgraph_node (cgraph_canonical_decl (decl)));
+	    cgraph_mark_needed_node (cgraph_node (decl));
 	}
       break;
 
Index: cgraph.c
===================================================================
--- cgraph.c	(revision 128875)
+++ cgraph.c	(working copy)
@@ -267,6 +267,24 @@
 	      && TREE_CODE (duplicate) == FUNCTION_DECL);
   gcc_assert (decl != duplicate);
 
+  if (cgraph_hash)
+    {
+      struct cgraph_node key, **cg_slot;
+      key.decl = decl;
+      cg_slot = (struct cgraph_node **) htab_find_slot (cgraph_hash, &key,
+							NO_INSERT);
+      if (cg_slot && *cg_slot)
+	{
+	  /* We already saw a definition of the function, so reverse
+	     the duplication.  */
+	  tree tem;
+	  gcc_assert (DECL_INITIAL (decl));
+	  tem = duplicate;
+	  duplicate = decl;
+	  decl = tem;
+	}
+    }
+
   if (!duplicate_map)
     duplicate_map = pointer_map_create ();
 
Index: c-decl.c
===================================================================
--- c-decl.c	(revision 129042)
+++ c-decl.c	(working copy)
@@ -2297,6 +2297,7 @@
       tree type = TREE_TYPE (x);
       tree visdecl = b->decl;
       tree vistype = TREE_TYPE (visdecl);
+      tree savedecl;
       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
 	  && COMPLETE_TYPE_P (TREE_TYPE (x)))
 	b->inner_comp = false;
@@ -2317,6 +2318,7 @@
 		TREE_TYPE (b_use->decl) = b_use->type; /* FIXME!!! */
 	    }
 	}
+      savedecl = b_use->decl;
       if (duplicate_decls (x, b_use->decl, b_use))
 	{
 	  if (b_use != b)
@@ -2336,6 +2338,10 @@
 						  TYPE_ATTRIBUTES
 						  (b_use->type));
 	      TREE_TYPE (b_use->decl) = thistype; /* FIXME!!! */
+
+	      /* Also update the file scope copy.  */
+	      if (B_IN_FILE_SCOPE (b) && b->decl == savedecl)
+		b->decl = b_use->decl;
 	    }
 	  return b_use->decl;
 	}



More information about the Gcc-patches mailing list