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]

C++ PATCH to ggc_alloc DECL_LANG_SPECIFIC



We now gcc_alloc DECL_LANG_SPECIFIC, thereby removing some truly
grotesque bits in duplicate_decls where we tried to figure out if one
of the decls was one we just now allocated, and was therefore atop the
appropriate obstack, and then free it.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

1999-09-08  Mark Mitchell  <mark@codesourcery.com>

	* cp-tree.h (lang_decl_flags): Remove permanent_attr.
	Remove next.
	(LANG_DECL_PERMANENT): Remove.
	* decl.c (duplicate_decls): Don't mess about with obstacks trying
	to free memory.
	(lang_mark_tree): Mark DECL_LANG_SPECIFIC.
	* lex.c (free_lang_decl_chain): Remove.
	(build_lang_decl): Don't use obstacks.
	(retrofit_lang_decl): Likewise.
	(copy_lang_decl): Likewise.

Index: cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.290
diff -c -p -r1.290 cp-tree.h
*** cp-tree.h	1999/09/09 01:47:01	1.290
--- cp-tree.h	1999/09/09 03:28:23
*************** struct lang_decl_flags
*** 1474,1493 ****
    unsigned const_memfunc : 1;
    unsigned volatile_memfunc : 1;
    unsigned abstract_virtual : 1;
-   unsigned permanent_attr : 1 ;
- 
    unsigned constructor_for_vbase_attr : 1;
    unsigned mutable_flag : 1;
    unsigned saved_inline : 1;
    unsigned use_template : 2;
    unsigned nonconverting : 1;
    unsigned declared_inline : 1;
    unsigned not_really_extern : 1;
- 
    unsigned needs_final_overrider : 1;
    unsigned bitfield : 1;
    unsigned defined_in_class : 1;
!   unsigned dummy : 5;
  
    tree access;
    tree context;
--- 1474,1492 ----
    unsigned const_memfunc : 1;
    unsigned volatile_memfunc : 1;
    unsigned abstract_virtual : 1;
    unsigned constructor_for_vbase_attr : 1;
+ 
    unsigned mutable_flag : 1;
    unsigned saved_inline : 1;
    unsigned use_template : 2;
    unsigned nonconverting : 1;
    unsigned declared_inline : 1;
    unsigned not_really_extern : 1;
    unsigned needs_final_overrider : 1;
+ 
    unsigned bitfield : 1;
    unsigned defined_in_class : 1;
!   unsigned dummy : 6;
  
    tree access;
    tree context;
*************** struct lang_decl
*** 1515,1523 ****
    {
      tree sorted_fields;
      struct pending_inline *pending_inline_info;
-     /* The lang_decls on the free_lang_decl_chain are chained together
-        through this pointer.  */
-     struct lang_decl *next;
    } u;
  };
  
--- 1514,1519 ----
*************** struct lang_decl
*** 1638,1646 ****
  /* Nonzero for FUNCTION_DECL means that this member function
     must be overridden by derived classes.  */
  #define DECL_NEEDS_FINAL_OVERRIDER_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.needs_final_overrider)
- 
- /* Nonzero if allocated on permanent_obstack.  */
- #define LANG_DECL_PERMANENT(LANGDECL) ((LANGDECL)->decl_flags.permanent_attr)
  
  /* The _TYPE context in which this _DECL appears.  This field holds the
     class where a virtual function instance is actually defined, and the
--- 1634,1639 ----
Index: decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.435
diff -c -p -r1.435 decl.c
*** decl.c	1999/09/09 01:47:01	1.435
--- decl.c	1999/09/09 03:28:32
*************** int
*** 3037,3043 ****
  duplicate_decls (newdecl, olddecl)
       tree newdecl, olddecl;
  {
-   extern struct obstack permanent_obstack;
    unsigned olddecl_uid = DECL_UID (olddecl);
    int olddecl_friend = 0, types_match = 0;
    int new_defines_function = 0;
--- 3037,3042 ----
*************** duplicate_decls (newdecl, olddecl)
*** 3625,3632 ****
    if (TREE_CODE (newdecl) == FUNCTION_DECL)
      {
        int function_size;
-       struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
-       struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
  
        function_size = sizeof (struct tree_decl);
  
--- 3624,3629 ----
*************** duplicate_decls (newdecl, olddecl)
*** 3634,3644 ****
  	     (char *) olddecl + sizeof (struct tree_common),
  	     function_size - sizeof (struct tree_common));
  
-       /* Can we safely free the storage used by newdecl?  */
- 
- #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
- 		  & ~ obstack_alignment_mask (&permanent_obstack))
- 
        if (DECL_TEMPLATE_INSTANTIATION (newdecl))
  	{
  	  /* If newdecl is a template instantiation, it is possible that
--- 3631,3636 ----
*************** duplicate_decls (newdecl, olddecl)
*** 3670,3707 ****
  	    if (TREE_VALUE (decls) == newdecl)
  	      TREE_VALUE (decls) = olddecl;
  	}
- 
-       if (((char *)newdecl + ROUND (function_size) == (char *)nl
- 	   && ((char *)newdecl + ROUND (function_size)
- 	       + ROUND (sizeof (struct lang_decl))
- 	       == obstack_next_free (&permanent_obstack)))
- 	  || ((char *)newdecl + ROUND (function_size)
- 	      == obstack_next_free (&permanent_obstack)))
- 	{
- 	  DECL_MAIN_VARIANT (newdecl) = olddecl;
- 	  DECL_LANG_SPECIFIC (olddecl) = ol;
- 	  bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
- 
- 	  obstack_free (&permanent_obstack, newdecl);
- 	}
-       else if (LANG_DECL_PERMANENT (ol) && ol != nl)
- 	{
- 	  if (DECL_MAIN_VARIANT (olddecl) == olddecl)
- 	    {
- 	      struct lang_decl *free_lang_decl = ol;
- 
- 	      /* Save these lang_decls that would otherwise be lost.  */
- 	      if (DECL_LANG_SPECIFIC (olddecl) == ol)
- 		abort ();
- 
- 	      free_lang_decl->u.next = free_lang_decl_chain;
- 	      free_lang_decl_chain = free_lang_decl;
- 	    }
- 	  else
- 	    {
- 	      /* Storage leak.  */;
- 	    }
- 	}
      }
    else
      {
--- 3662,3667 ----
*************** lang_mark_tree (t)
*** 14580,14585 ****
--- 14540,14546 ----
  
        if (ld)
  	{
+ 	  ggc_mark (ld);
  	  ggc_mark_tree (ld->decl_flags.access);
  	  ggc_mark_tree (ld->decl_flags.context);
  	  if (TREE_CODE (t) != NAMESPACE_DECL)
Index: lex.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/lex.c,v
retrieving revision 1.143
diff -c -p -r1.143 lex.c
*** lex.c	1999/09/07 16:07:22	1.143
--- lex.c	1999/09/09 03:28:35
*************** extern int tree_node_counts[];
*** 4748,4757 ****
  extern int tree_node_sizes[];
  #endif
  
- /* Place to save freed lang_decls which were allocated on the
-    permanent_obstack.  */
- struct lang_decl *free_lang_decl_chain;
- 
  tree
  build_lang_decl (code, name, type)
       enum tree_code code;
--- 4748,4753 ----
*************** build_lang_decl (code, name, type)
*** 4760,4776 ****
  {
    tree t;
  
-   /* When we're building statement trees, declarations need to live
-      forever.  */
-   if (building_stmt_tree ())
-     push_permanent_obstack ();
- 
    t = build_decl (code, name, type);
    retrofit_lang_decl (t);
  
-   if (building_stmt_tree ())
-     pop_obstacks ();
- 
    return t;
  }
  
--- 4756,4764 ----
*************** void
*** 4781,4787 ****
  retrofit_lang_decl (t)
       tree t;
  {
-   struct obstack *obstack = current_obstack;
    struct lang_decl *ld;
    size_t size;
  
--- 4769,4774 ----
*************** retrofit_lang_decl (t)
*** 4789,4815 ****
      size = sizeof (struct lang_decl);
    else
      size = sizeof (struct lang_decl_flags);
- 
-   if (! TREE_PERMANENT (t))
-     obstack = saveable_obstack;
-   else
-     /* Could be that saveable is permanent and current is not.  */
-     obstack = &permanent_obstack;
- 
-   if (CAN_HAVE_FULL_LANG_DECL_P (t) && free_lang_decl_chain 
-       && obstack == &permanent_obstack)
-     {
-       ld = free_lang_decl_chain;
-       free_lang_decl_chain = free_lang_decl_chain->u.next;
-     }
-   else
-     ld = (struct lang_decl *) obstack_alloc (obstack, size);
  
    memset (ld, 0, size);
  
    DECL_LANG_SPECIFIC (t) = ld;
-   LANG_DECL_PERMANENT (ld) = obstack == &permanent_obstack;
-   my_friendly_assert (LANG_DECL_PERMANENT (ld) == TREE_PERMANENT  (t), 234);
    if (current_lang_name == lang_name_cplusplus)
      DECL_LANGUAGE (t) = lang_cplusplus;
    else if (current_lang_name == lang_name_c)
--- 4776,4786 ----
      size = sizeof (struct lang_decl);
    else
      size = sizeof (struct lang_decl_flags);
  
+   ld = (struct lang_decl *) ggc_alloc (size);
    memset (ld, 0, size);
  
    DECL_LANG_SPECIFIC (t) = ld;
    if (current_lang_name == lang_name_cplusplus)
      DECL_LANGUAGE (t) = lang_cplusplus;
    else if (current_lang_name == lang_name_c)
*************** copy_lang_decl (node)
*** 4832,4838 ****
       tree node;
  {
    int size;
!   int *pi;
  
    if (! DECL_LANG_SPECIFIC (node))
      return;
--- 4803,4809 ----
       tree node;
  {
    int size;
!   struct lang_decl *ld;
  
    if (! DECL_LANG_SPECIFIC (node))
      return;
*************** copy_lang_decl (node)
*** 4841,4849 ****
      size = sizeof (struct lang_decl_flags);
    else
      size = sizeof (struct lang_decl);
!   pi = (int *)obstack_alloc (&permanent_obstack, size);
!   bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)pi, size);
!   DECL_LANG_SPECIFIC (node) = (struct lang_decl *)pi;
  }
  
  tree
--- 4812,4820 ----
      size = sizeof (struct lang_decl_flags);
    else
      size = sizeof (struct lang_decl);
!   ld = (struct lang_decl *) ggc_alloc (size);
!   bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)ld, size);
!   DECL_LANG_SPECIFIC (node) = ld;
  }
  
  tree


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