aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2003-09-08 08:56:27 -0700
committerRichard Henderson <rth@gcc.gnu.org>2003-09-08 08:56:27 -0700
commitc1f927e84ec73debafbc0114cc4d81abd1b27ae7 (patch)
treead932cb4dec8a82eb9fd686cb0a6c341596f0816
parent7f14bbe68f1fac27349b5154730aeb2e23e97dfa (diff)
downloadgcc-c1f927e84ec73debafbc0114cc4d81abd1b27ae7.zip
gcc-c1f927e84ec73debafbc0114cc4d81abd1b27ae7.tar.gz
gcc-c1f927e84ec73debafbc0114cc4d81abd1b27ae7.tar.bz2
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
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-decl.c9
-rw-r--r--gcc/cp/ChangeLog10
-rw-r--r--gcc/cp/decl.c1
-rw-r--r--gcc/cp/decl2.c3
-rw-r--r--gcc/cp/optimize.c24
-rw-r--r--gcc/cp/pt.c9
-rw-r--r--gcc/cp/semantics.c2
-rw-r--r--gcc/cp/tree.c7
-rw-r--r--gcc/toplev.h2
-rw-r--r--gcc/tree-optimize.c22
11 files changed, 38 insertions, 57 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5582bc2..af01922 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index f4896f3..6afcd7a 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -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))
{
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 60aaf36..9fea09b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index ca13790..6886fe4d 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index e1fe120..209f793 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -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 ();
}
}
diff --git a/gcc/cp/optimize.c b/gcc/cp/optimize.c
index 7be410e..bcb74e4 100644
--- a/gcc/cp/optimize.c
+++ b/gcc/cp/optimize.c
@@ -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);
}
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 8169cf3..bb93047 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -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);
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index d8ac60d9..8b765ef 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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;
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 8310bf1..0c729d6 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -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;
}
diff --git a/gcc/toplev.h b/gcc/toplev.h
index 3ebd8e4..ae05f4b 100644
--- a/gcc/toplev.h
+++ b/gcc/toplev.h
@@ -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);
diff --git a/gcc/tree-optimize.c b/gcc/tree-optimize.c
index e5bea3e..253fda2 100644
--- a/gcc/tree-optimize.c
+++ b/gcc/tree-optimize.c
@@ -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);
}