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]

Re: gc problem with nested functions


> No, I don't want to try that either.  But I think there is a simpler
> solution, which is to have a separate obstack for memory allocated in
> immed_double_const.  I'll try to come up with a patch for this quickly.
> This should be a temporary fix, until we enable GC for all frontends.

Here's a patch that changes varasm.c so that all constants get allocated on
a different, permanent obstack.  This means we are leaking a bit of memory.
An alternative would be to have per-function obstacks for constants, but I'm
not entirely sure whether this would cause problems for static variables
declared inside a function (i.e. if we allocate constants for their
initializers, do we need to keep these constants around past the compilation
of the enclosing function?).

All in all I'm not convinved that this is indeed a better solution than your
fix.  (Note however that your change only changed immed_double_const, but the
same problem exists in immed_real_const_1).

Tested on i686-linux, but that's not very meaningful, as the bug isn't
reproducible with check-gcc on that target.

Bernd

	* varasm.c (constants_obstack): New.
	(init_varasm_once): Initialize it.
	(immed_double_const): Allocate constants on this obstack.
	(immed_real_const_1): Likewise.

Index: varasm.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/varasm.c,v
retrieving revision 1.79
diff -u -p -r1.79 varasm.c
--- varasm.c	1999/09/09 18:55:37	1.79
+++ varasm.c	1999/09/13 15:17:45
@@ -83,6 +83,11 @@ extern struct obstack *current_obstack;
 extern struct obstack *saveable_obstack;
 extern struct obstack *rtl_obstack;
 extern struct obstack permanent_obstack;
+
+/* All constants allocated in immed_double_const and immed_real_const_1 go on
+   this obstack.  */
+static struct obstack constants_obstack;
+
 #define obstack_chunk_alloc xmalloc
 
 struct addr_const;
@@ -2080,13 +2085,9 @@ immed_double_const (i0, i1, mode)
   /* No; make a new one and add it to the chain.
 
      We may be called by an optimizer which may be discarding any memory
-     allocated during its processing (such as combine and loop).  However,
-     we will be leaving this constant on the chain, so we cannot tolerate
-     freed memory.  So switch to saveable_obstack for this allocation
-     and then switch back if we were in current_obstack.  */
-
-  push_obstacks_nochange ();
-  rtl_in_saveable_obstack ();
+     allocated during its processing (such as combine and loop), so we
+     allocate all memory on our private constants_obstack.  */
+  push_obstacks (&constants_obstack, &constants_obstack);
   r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1);
   pop_obstacks ();
 
@@ -2152,12 +2153,9 @@ immed_real_const_1 (d, mode)
   /* No; make a new one and add it to the chain.
 
      We may be called by an optimizer which may be discarding any memory
-     allocated during its processing (such as combine and loop).  However,
-     we will be leaving this constant on the chain, so we cannot tolerate
-     freed memory.  So switch to saveable_obstack for this allocation
-     and then switch back if we were in current_obstack.  */
-  push_obstacks_nochange ();
-  rtl_in_saveable_obstack ();
+     allocated during its processing (such as combine and loop), so we
+     allocate all memory on our private constants_obstack.  */
+  push_obstacks (&constants_obstack, &constants_obstack);
   r = rtx_alloc (CONST_DOUBLE);
   pop_obstacks ();
   PUT_MODE (r, mode);
@@ -4562,6 +4561,8 @@ make_decl_one_only (decl)
 void
 init_varasm_once ()
 {
+  gcc_obstack_init (&constants_obstack);
+
   ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof(const_hash_table[0]),
 		mark_const_hash_entry);
   ggc_add_string_root (&in_named_name, 1);


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