c-decl.c (c_expand_body_1): Push and pop function context here.

gcc/
        * 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.

From-SVN: r71208
This commit is contained in:
Richard Henderson 2003-09-08 08:56:27 -07:00 committed by Richard Henderson
parent 7f14bbe68f
commit c1f927e84e
11 changed files with 38 additions and 57 deletions

View File

@ -1,3 +1,9 @@
2003-09-08 Richard Henderson <rth@redhat.com>
* 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.
2003-09-08 Jakub Jelinek <jakub@redhat.com>
* toplev.c (rest_of_handle_stack_regs): Call split_all_insns before

View File

@ -6181,9 +6181,16 @@ c_expand_body_1 (tree fndecl, int nested_p)
/* 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))
{

View File

@ -1,3 +1,13 @@
2003-09-08 Richard Henderson <rth@redhat.com>
* 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.
2003-09-07 Gabriel Dos Reis <gcc@integrable-solutions.net>
PR c++/11762

View File

@ -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

View File

@ -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 ();
}
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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;

View File

@ -2026,15 +2026,8 @@ 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;
}

View File

@ -66,7 +66,7 @@ extern void inform (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
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);

View File

@ -93,21 +93,13 @@ clear_decl_rtl (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, void *data)
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
@ -240,11 +232,5 @@ 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);
}