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: apply decl attributes to copied decl


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

When copying a decl, we must apply its attributes using
decl_attributes, so that on-the-side data structures in tree.c refer
to the correct node.  Without this, initpri1.c failed, because the
canonical decl did not have the correct constructor priority.

Also, I checked and these data structures in tree.c are all weak maps,
so no explicit cleanup is needed on the server.  Nice :)

This also fixes a declaration-in-the-code oversight.

Tom

ChangeLog:
2008-02-15  Tom Tromey  <tromey@redhat.com>

	* c-decl.c (get_smashed_type): Don't mix declaration with code.
	(duplicate_decls): Apply attributes to new decl.

Index: c-decl.c
===================================================================
--- c-decl.c	(revision 132311)
+++ c-decl.c	(working copy)
@@ -2088,8 +2088,6 @@
 	{
 	  /* Modify a copy of OLDDECL and install that in the
 	     bindings.  */
-	  /* FIXME: we shouldn't need a copy -- we should just modify
-	     NEWDECL.  */
 	  tree copy = copy_node (olddecl);
 	  merge_decls (newdecl, copy, newtype,
 		       C_SMASHED_TYPE_VARIANT (oldtype));
@@ -2097,6 +2095,18 @@
 	  /* 	  gcc_assert (binding->decl == olddecl); */
 	  C_FIRST_DEFINITION_P (copy) = C_FIRST_DEFINITION_P (newdecl);
 	  binding->decl = copy;
+
+	  /* Need to call decl_attributes on the new decl, to ensure
+	     that on-the-side data structures know about the new
+	     tree.  */
+	  if (DECL_ATTRIBUTES (copy))
+	    {
+	      tree attrs = DECL_ATTRIBUTES (copy);
+	      DECL_ATTRIBUTES (copy) = NULL_TREE;
+	      attrs = decl_attributes (&copy, attrs, 0);
+	      gcc_assert (! attrs);
+	    }
+
 	  c_parser_bind_callback (DECL_NAME (copy), copy);
 	  c_parser_note_smash (olddecl, copy);
 	}
@@ -8184,10 +8194,10 @@
 
 	case ARRAY_TYPE:
 	  {
-	    tree index = NULL_TREE;
+	    tree elts, index = NULL_TREE;
 	    if (TYPE_DOMAIN (type))
 	      index = get_smashed_type (map, TYPE_DOMAIN (type));
-	    tree elts = get_smashed_type (map, TREE_TYPE (type));
+	    elts = get_smashed_type (map, TREE_TYPE (type));
 	    if (index != TYPE_DOMAIN (type) || elts != TREE_TYPE (type))
 	      type = build_array_type (elts, index);
 	  }


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