This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix collected c++ gc regressions
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 8 Sep 2003 09:04:58 -0700
- Subject: fix collected c++ gc regressions
Fixes
-FAIL: g++.dg/debug/debug2.C (test for excess errors)
-FAIL: g++.old-deja/g++.jason/template37.C (test for excess errors)
-FAIL: g++.old-deja/g++.mike/p1989.C (test for excess errors)
-FAIL: g++.old-deja/g++.pt/explicit74.C (test for excess errors)
-FAIL: g++.old-deja/g++.pt/ttp34.C (test for excess errors)
There's one more segmentation fault in the logs,
FAIL: g++.dg/init/new6.C (test for excess errors)
which I have not yet investigated, but with 20 hour gcac build
times this has taken long enough already. At least this is
monotonic change in the right direction.
r~
gc/
* c-decl.c (c_expand_body_1): Push and pop function context here.
* tree-optimize.c (tree_rest_of_compilation): ... not here. Take
nested argument instead of computing nesting ourselves.
gcc/cp/
* decl.c (finish_function): Clear current_function_decl.
* decl2.c (mark_used): Don't push/pop gc context.
* optimize.c (optimize_function): Likewise.
* tree.c (cp_cannot_inline_tree_fn): Likewise.
* pt.c (instantiate_decl): Inc/dec function_depth instead.
* semantics.c (expand_body): Update for tree_rest_of_compilation
nested argument.
Index: gcc/c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.443
diff -u -p -r1.443 c-decl.c
--- gcc/c-decl.c 6 Sep 2003 13:33:53 -0000 1.443
+++ gcc/c-decl.c 8 Sep 2003 15:47:39 -0000
@@ -6181,9 +6181,16 @@ c_expand_body_1 (tree fndecl, int nested
/* Make sure that we will evaluate variable-sized types involved
in our function's type. */
expand_pending_sizes (DECL_LANG_SPECIFIC (fndecl)->pending_sizes);
+
+ /* Squirrel away our current state. */
+ push_function_context ();
}
- tree_rest_of_compilation (fndecl);
+ tree_rest_of_compilation (fndecl, nested_p);
+
+ if (nested_p)
+ /* Return to the enclosing function. */
+ pop_function_context ();
if (DECL_STATIC_CONSTRUCTOR (fndecl))
{
Index: gcc/toplev.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.h,v
retrieving revision 1.113
diff -u -p -r1.113 toplev.h
--- gcc/toplev.h 29 Aug 2003 23:21:11 -0000 1.113
+++ gcc/toplev.h 8 Sep 2003 15:47:39 -0000
@@ -66,7 +66,7 @@ extern void inform (const char *, ...) A
extern void rest_of_decl_compilation (tree, const char *, int, int);
extern void rest_of_type_compilation (tree, int);
extern void rest_of_compilation (tree);
-extern void tree_rest_of_compilation (tree);
+extern void tree_rest_of_compilation (tree, bool);
extern void announce_function (tree);
Index: gcc/tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 2.1
diff -u -p -r2.1 tree-optimize.c
--- gcc/tree-optimize.c 29 Aug 2003 23:21:11 -0000 2.1
+++ gcc/tree-optimize.c 8 Sep 2003 15:47:39 -0000
@@ -93,21 +93,13 @@ clear_decl_rtl (tree *tp, int *walk_subt
compilation for FNDECL. */
void
-tree_rest_of_compilation (tree fndecl)
+tree_rest_of_compilation (tree fndecl, bool nested_p)
{
- static int nesting = -1;
-
timevar_push (TV_EXPAND);
- ++nesting;
-
if (flag_unit_at_a_time && !cgraph_global_info_ready)
abort ();
- if (nesting > 0)
- /* Squirrel away our current state. */
- push_function_context ();
-
/* Initialize the RTL code for the function. */
current_function_decl = fndecl;
input_location = DECL_SOURCE_LOCATION (fndecl);
@@ -162,7 +154,7 @@ tree_rest_of_compilation (tree fndecl)
/* If this is a nested function, protect the local variables in the stack
above us from being collected while we're compiling this function. */
- if (nesting > 0)
+ if (nested_p)
ggc_push_context ();
/* There's no need to defer outputting this function any more; we
@@ -173,7 +165,7 @@ tree_rest_of_compilation (tree fndecl)
rest_of_compilation (fndecl);
/* Undo the GC context switch. */
- if (nesting > 0)
+ if (nested_p)
ggc_pop_context ();
/* If requested, warn about function definitions where the function will
@@ -227,7 +219,7 @@ tree_rest_of_compilation (tree fndecl)
clear_decl_rtl,
fndecl);
- if (DECL_SAVED_INSNS (fndecl) == 0 && ! nesting && ! flag_inline_trees)
+ if (DECL_SAVED_INSNS (fndecl) == 0 && !nested_p && !flag_inline_trees)
{
/* Stop pointing to the local nodes about to be freed.
But DECL_INITIAL must remain nonzero so we know this
@@ -239,12 +231,6 @@ tree_rest_of_compilation (tree fndecl)
DECL_ARGUMENTS (fndecl) = 0;
}
-
- if (nesting > 0)
- /* Return to the enclosing function. */
- pop_function_context ();
-
- --nesting;
timevar_pop (TV_EXPAND);
}
Index: gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1124
diff -u -p -r1.1124 decl.c
--- gcc/cp/decl.c 7 Sep 2003 18:52:52 -0000 1.1124
+++ gcc/cp/decl.c 8 Sep 2003 15:47:50 -0000
@@ -14104,6 +14104,7 @@ finish_function (int flags)
/* We're leaving the context of this function, so zap cfun. It's still in
DECL_SAVED_INSNS, and we'll restore it in tree_rest_of_compilation. */
cfun = NULL;
+ current_function_decl = NULL;
/* If this is an in-class inline definition, we may have to pop the
bindings for the template parameters that we added in
Index: gcc/cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.668
diff -u -p -r1.668 decl2.c
--- gcc/cp/decl2.c 7 Sep 2003 11:15:46 -0000 1.668
+++ gcc/cp/decl2.c 8 Sep 2003 15:47:54 -0000
@@ -4232,10 +4232,7 @@ mark_used (tree decl)
information. */
|| cp_function_chain->can_throw);
- /* Our caller is likely to have lots of data on the stack. */
- ggc_push_context ();
instantiate_decl (decl, defer);
- ggc_pop_context ();
}
}
Index: gcc/cp/optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/optimize.c,v
retrieving revision 1.96
diff -u -p -r1.96 optimize.c
--- gcc/cp/optimize.c 3 Sep 2003 21:38:26 -0000 1.96
+++ gcc/cp/optimize.c 8 Sep 2003 15:47:54 -0000
@@ -56,31 +56,7 @@ optimize_function (tree fn)
and (d) TARGET_ASM_OUTPUT_MI_THUNK is there to DTRT anyway. */
&& !DECL_THUNK_P (fn))
{
- /* ??? Work around GC problem. Call stack is
-
- -> instantiate_decl
- -> expand_or_defer_fn
- -> maybe_clone_body
- -> expand_body
- -> tree_rest_of_compilation
-
- which of course collects. This used to be protected by the
- "regular" nested call ggc_push_context that now lives in
- tree_rest_of_compilation.
-
- Two good fixes:
- (1) Do inlining in tree_rest_of_compilation. This is good
- in that this common optimization happens in common code.
- (2) Don't nest compilation of functions. Instead queue the
- new function to cgraph, and let it get picked up in the
- next round of "emit everything that needs emitting".
-
- For the nonce, just protect things here. */
-
- ggc_push_context ();
optimize_inline_calls (fn);
- ggc_pop_context ();
-
dump_function (TDI_inlined, fn);
}
Index: gcc/cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.775
diff -u -p -r1.775 pt.c
--- gcc/cp/pt.c 5 Sep 2003 18:04:15 -0000 1.775
+++ gcc/cp/pt.c 8 Sep 2003 15:48:03 -0000
@@ -10730,10 +10730,14 @@ instantiate_decl (tree d, int defer_ok)
timevar_push (TV_PARSE);
- /* We may be in the middle of deferred access check. Disable
- it now. */
+ /* We may be in the middle of deferred access check. Disable it now. */
push_deferring_access_checks (dk_no_deferred);
+ /* Our caller does not expect collection to happen, which it might if
+ we decide to compile the function to rtl now. Arrange for a new
+ gc context to be created if so. */
+ function_depth++;
+
/* Set TD to the template whose DECL_TEMPLATE_RESULT is the pattern
for the instantiation. */
td = template_for_substitution (d);
@@ -10978,6 +10982,7 @@ out:
input_location = saved_loc;
pop_deferring_access_checks ();
pop_tinst_level ();
+ function_depth--;
timevar_pop (TV_PARSE);
Index: gcc/cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.356
diff -u -p -r1.356 semantics.c
--- gcc/cp/semantics.c 5 Sep 2003 08:38:42 -0000 1.356
+++ gcc/cp/semantics.c 8 Sep 2003 15:48:05 -0000
@@ -2868,7 +2868,7 @@ expand_body (tree fn)
optimize_function (fn);
timevar_pop (TV_INTEGRATION);
- tree_rest_of_compilation (fn);
+ tree_rest_of_compilation (fn, function_depth > 1);
current_function_decl = saved_function;
input_location = saved_loc;
Index: gcc/cp/tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/tree.c,v
retrieving revision 1.345
diff -u -p -r1.345 tree.c
--- gcc/cp/tree.c 5 Sep 2003 08:24:21 -0000 1.345
+++ gcc/cp/tree.c 8 Sep 2003 15:48:06 -0000
@@ -2026,14 +2026,7 @@ cp_cannot_inline_tree_fn (tree* fnp)
(template_for_substitution (fn))))
return 1;
- /* Our caller does not expect us to call ggc_collect, but
- instantiate_decl can call rest_of_compilation so we must
- protect our caller. */
- ggc_push_context();
-
fn = *fnp = instantiate_decl (fn, /*defer_ok=*/0);
-
- ggc_pop_context();
if (TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
return 1;