Patchwork convert c-pragma.c:pending_redefine_extname to a VEC

login
register
mail settings
Submitter Nathan Froyd
Date Aug. 7, 2010, 6:37 p.m.
Message ID <20100807183755.GJ17362@codesourcery.com>
Download mbox | patch
Permalink /patch/61188/
State New
Headers show

Comments

Nathan Froyd - Aug. 7, 2010, 6:37 p.m.
As $SUBJECT suggests.  Not much to this one.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

	* c-pragma.c (pending_redefinition): Declare.  Declare a VEC of it.
	(pending_redefine_extname): Change type to a VEC.
	(add_to_renaming_pragma_list): Update for new type of
	pending_redefine_extname.
	(maybe_apply_pending_pragma): Likewise.
Joseph S. Myers - Aug. 8, 2010, 12:37 p.m.
On Sat, 7 Aug 2010, Nathan Froyd wrote:

> As $SUBJECT suggests.  Not much to this one.
> 
> Tested on x86_64-unknown-linux-gnu.  OK to commit?
> 
> -Nathan
> 
> 	* c-pragma.c (pending_redefinition): Declare.  Declare a VEC of it.
> 	(pending_redefine_extname): Change type to a VEC.
> 	(add_to_renaming_pragma_list): Update for new type of
> 	pending_redefine_extname.
> 	(maybe_apply_pending_pragma): Likewise.

OK.

Patch

diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index cea0b26..81e42be 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -424,7 +424,15 @@  maybe_apply_pending_pragma_weaks (void)
       if it appears afterward, we have no way of knowing whether a modified
       DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.)  */
 
-static GTY(()) tree pending_redefine_extname;
+typedef struct GTY(()) pending_redefinition_d {
+  tree oldname;
+  tree newname;
+} pending_redefinition;
+
+DEF_VEC_O(pending_redefinition);
+DEF_VEC_ALLOC_O(pending_redefinition,gc);
+
+static GTY(()) VEC(pending_redefinition,gc) *pending_redefine_extname;
 
 static void handle_pragma_redefine_extname (cpp_reader *);
 
@@ -475,17 +483,23 @@  handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
 void
 add_to_renaming_pragma_list (tree oldname, tree newname)
 {
-  tree previous = purpose_member (oldname, pending_redefine_extname);
-  if (previous)
-    {
-      if (TREE_VALUE (previous) != newname)
-	warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
-		 "conflict with previous #pragma redefine_extname");
-      return;
-    }
+  unsigned ix;
+  pending_redefinition *p;
+
+  for (ix = 0;
+       VEC_iterate (pending_redefinition, pending_redefine_extname, ix, p);
+       ix++)
+    if (oldname == p->oldname)
+      {
+	if (p->newname != newname)
+	  warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
+		   "conflict with previous #pragma redefine_extname");
+	return;
+      }
 
-  pending_redefine_extname
-    = tree_cons (oldname, newname, pending_redefine_extname);
+  p = VEC_safe_push (pending_redefinition, gc, pending_redefine_extname, NULL);
+  p->oldname = oldname;
+  p->newname = newname;
 }
 
 static GTY(()) tree pragma_extern_prefix;
@@ -517,7 +531,8 @@  handle_pragma_extern_prefix (cpp_reader * ARG_UNUSED (dummy))
 tree
 maybe_apply_renaming_pragma (tree decl, tree asmname)
 {
-  tree *p, t;
+  unsigned ix;
+  pending_redefinition *p;
 
   /* The renaming pragmas are only applied to declarations with
      external linkage.  */
@@ -538,26 +553,32 @@  maybe_apply_renaming_pragma (tree decl, tree asmname)
 		   "conflict with previous rename");
 
       /* Take any pending redefine_extname off the list.  */
-      for (p = &pending_redefine_extname; (t = *p); p = &TREE_CHAIN (t))
-	if (DECL_NAME (decl) == TREE_PURPOSE (t))
+      for (ix = 0;
+	   VEC_iterate (pending_redefinition, pending_redefine_extname, ix, p);
+	   ix++)
+	if (DECL_NAME (decl) == p->oldname)
 	  {
 	    /* Only warn if there is a conflict.  */
-	    if (strcmp (IDENTIFIER_POINTER (TREE_VALUE (t)), oldname))
+	    if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
 	      warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
 		       "conflict with previous rename");
 
-	    *p = TREE_CHAIN (t);
+	    VEC_unordered_remove (pending_redefinition,
+				  pending_redefine_extname, ix);
 	    break;
 	  }
       return 0;
     }
 
   /* Find out if we have a pending #pragma redefine_extname.  */
-  for (p = &pending_redefine_extname; (t = *p); p = &TREE_CHAIN (t))
-    if (DECL_NAME (decl) == TREE_PURPOSE (t))
+  for (ix = 0;
+       VEC_iterate (pending_redefinition, pending_redefine_extname, ix, p);
+       ix++)
+    if (DECL_NAME (decl) == p->oldname)
       {
-	tree newname = TREE_VALUE (t);
-	*p = TREE_CHAIN (t);
+	tree newname = p->newname;
+	VEC_unordered_remove (pending_redefinition,
+			      pending_redefine_extname, ix);
 
 	/* If we already have an asmname, #pragma redefine_extname is
 	   ignored (with a warning if it conflicts).  */