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: [PATCH] PR c++/13376


On Sunday 28 December 2003 19:53, Mark Mitchell wrote:
> On Sat, 2003-12-27 at 12:40, Steven Bosscher wrote:
> > Hi,
> >
> > Mainline g++ gives strange names in dumps for passes that use
> > current_function_name (such as gcse):
>
> The caching in cxx_printable_name has bothered me for years.
>
> Just get rid of it.

That does not really solve the problem; current_function_name is still
expected to point to a non-changing string, but lang_decl_name re-uses
its result buffer for each call.  Using xstrdup would cause memleaks
because `struct function' is GC-able but strings are not.

So I would still like to apply the original patch and get rid of
current_function_name.

The attached patch removes the caching in cxx_printabe_name and has
passed the usual testing.  OK to apply both patches?

Gr.
Steven

	* tree.c (cxx_printable_name): Remove.
	* error.c (lang_decl_name): Rename to cxx_printable_name.
	* cp-tree.h (lang_decl_name): Remove prototype.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.944
diff -c -3 -p -r1.944 cp-tree.h
*** cp/cp-tree.h	23 Dec 2003 16:53:47 -0000	1.944
--- cp/cp-tree.h	29 Dec 2003 11:58:29 -0000
*************** extern const char *type_as_string		(tree
*** 3757,3763 ****
  extern const char *decl_as_string		(tree, int);
  extern const char *expr_as_string		(tree, int);
  extern const char *context_as_string            (tree, int);
! extern const char *lang_decl_name		(tree, int);
  extern const char *language_to_string           (enum languages);
  extern void print_instantiation_context         (void);
  
--- 3757,3763 ----
  extern const char *decl_as_string		(tree, int);
  extern const char *expr_as_string		(tree, int);
  extern const char *context_as_string            (tree, int);
! extern const char *cxx_printable_name		(tree, int);
  extern const char *language_to_string           (enum languages);
  extern void print_instantiation_context         (void);
  
*************** extern tree ovl_cons                    
*** 4127,4133 ****
  extern tree build_overload                      (tree, tree);
  extern tree function_arg_chain			(tree);
  extern int promotes_to_aggr_type		(tree, enum tree_code);
- extern const char *cxx_printable_name		(tree, int);
  extern tree build_exception_variant		(tree, tree);
  extern tree bind_template_template_parm		(tree, tree);
  extern tree array_type_nelts_total		(tree);
--- 4127,4132 ----
Index: cp/error.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/error.c,v
retrieving revision 1.241
diff -c -3 -p -r1.241 error.c
*** cp/error.c	21 Dec 2003 21:07:30 -0000	1.241
--- cp/error.c	29 Dec 2003 11:58:33 -0000
*************** context_as_string (tree context, int fla
*** 1926,1935 ****
    return pp_formatted_text (cxx_pp);
  }
  
! /* Generate the three forms of printable names for cxx_printable_name.  */
  
  const char *
! lang_decl_name (tree decl, int v)
  {
    if (v >= 2)
      return decl_as_string (decl, TFF_DECL_SPECIFIERS);
--- 1926,1936 ----
    return pp_formatted_text (cxx_pp);
  }
  
! /* Generate the three forms of printable names for the printable_names
!    langhook.  */
  
  const char *
! cxx_printable_name (tree decl, int v)
  {
    if (v >= 2)
      return decl_as_string (decl, TFF_DECL_SPECIFIERS);
Index: cp/tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/tree.c,v
retrieving revision 1.359
diff -c -3 -p -r1.359 tree.c
*** cp/tree.c	22 Dec 2003 20:42:57 -0000	1.359
--- cp/tree.c	29 Dec 2003 11:58:37 -0000
*************** build_overload (tree decl, tree chain)
*** 934,983 ****
      chain = ovl_cons (chain, NULL_TREE);
    return ovl_cons (decl, chain);
  }
- 
- 
- #define PRINT_RING_SIZE 4
- 
- const char *
- cxx_printable_name (tree decl, int v)
- {
-   static tree decl_ring[PRINT_RING_SIZE];
-   static char *print_ring[PRINT_RING_SIZE];
-   static int ring_counter;
-   int i;
- 
-   /* Only cache functions.  */
-   if (v < 2
-       || TREE_CODE (decl) != FUNCTION_DECL
-       || DECL_LANG_SPECIFIC (decl) == 0)
-     return lang_decl_name (decl, v);
- 
-   /* See if this print name is lying around.  */
-   for (i = 0; i < PRINT_RING_SIZE; i++)
-     if (decl_ring[i] == decl)
-       /* yes, so return it.  */
-       return print_ring[i];
- 
-   if (++ring_counter == PRINT_RING_SIZE)
-     ring_counter = 0;
- 
-   if (current_function_decl != NULL_TREE)
-     {
-       if (decl_ring[ring_counter] == current_function_decl)
- 	ring_counter += 1;
-       if (ring_counter == PRINT_RING_SIZE)
- 	ring_counter = 0;
-       if (decl_ring[ring_counter] == current_function_decl)
- 	abort ();
-     }
- 
-   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;
-   return print_ring[ring_counter];
- }
  
  /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
     listed in RAISES.  */
--- 934,939 ----


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