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]

Re: [C++ PATCH] Fix cxx_printable_name caching


On Mon, Sep 24, 2007 at 10:49:24PM +0200, Richard Guenther wrote:
> On 9/24/07, Jakub Jelinek <jakub@redhat.com> wrote:
> > I have tried to move decl_ring array to file scope instead and
> > mark it with GTY((deletable)), but that didn't work, as the old
> > FUNCTION_DECL in this case is ggc_free'd (during duplicate_decls) rather
> > than normally garbage collected, so there isn't anything that would set
> > it to NULL in between the ggc_free call and next cxx_printable_name.
> > As ggc_free is a promise that such a pointer isn't held anywhere, that is
> > not a GC bug.
> 
> It looks like you should be able to get rid of decl_ring completely?

If we don't care about next_decl_uid wraps, yes.  Though, if next_decl_uid
wraps, we might have bigger problems than that.
So here is a patch that uses solely uids.

2007-09-24  Jakub Jelinek  <jakub@redhat.com>

	* tree.c (cxx_printable_name): Compare FUNCTION_DECL uids
	rather than pointers.

--- gcc/cp/tree.c.jj	2007-09-24 22:18:26.000000000 +0200
+++ gcc/cp/tree.c	2007-09-24 22:59:21.000000000 +0200
@@ -1155,7 +1155,7 @@ build_overload (tree decl, tree chain)
 const char *
 cxx_printable_name (tree decl, int v)
 {
-  static tree decl_ring[PRINT_RING_SIZE];
+  static unsigned int uid_ring[PRINT_RING_SIZE];
   static char *print_ring[PRINT_RING_SIZE];
   static int ring_counter;
   int i;
@@ -1168,7 +1168,7 @@ cxx_printable_name (tree decl, int v)
 
   /* See if this print name is lying around.  */
   for (i = 0; i < PRINT_RING_SIZE; i++)
-    if (decl_ring[i] == decl)
+    if (uid_ring[i] == DECL_UID (decl))
       /* yes, so return it.  */
       return print_ring[i];
 
@@ -1177,18 +1177,18 @@ cxx_printable_name (tree decl, int v)
 
   if (current_function_decl != NULL_TREE)
     {
-      if (decl_ring[ring_counter] == current_function_decl)
+      if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
 	ring_counter += 1;
       if (ring_counter == PRINT_RING_SIZE)
 	ring_counter = 0;
-      gcc_assert (decl_ring[ring_counter] != current_function_decl);
+      gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
     }
 
   if (print_ring[ring_counter])
     free (print_ring[ring_counter]);
 
   print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v));
-  decl_ring[ring_counter] = decl;
+  uid_ring[ring_counter] = DECL_UID (decl);
   return print_ring[ring_counter];
 }
 


	Jakub


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