C++ PATCH for c++/48370 (extending lifetime of temps in aggregate initialization)

Message ID 4EB819A2.9070304@redhat.com
State New
Headers show

Commit Message

Jason Merrill Nov. 7, 2011, 5:47 p.m.
On 11/04/2011 11:23 PM, Jason Merrill wrote:
> While working on a followup, I noticed that this patch runs temporary
> cleanups in the wrong order. Fixed (and tested) thus.

This patch broke bootstrap because it allocated a gc-able vector and 
held it across the definition of a function, at the end of which it was 
collected, but we still tried to use it.  Fixed by allocating it only in 
the cases where we might do something with it (i.e. variables).

Tested x86_64-pc-linux-gnu, applying to trunk.


commit 1cd13481ae03948febfc551ff1a4959e33892eef
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Nov 5 17:11:34 2011 -0400

    	* decl.c (cp_finish_decl): Only make_tree_vector if we're calling

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d2daf91..3b283d8 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6049,9 +6049,12 @@  cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 	  /* This variable seems to be a non-dependent constant, so process
 	     its initializer.  If check_initializer returns non-null the
 	     initialization wasn't constant after all.  */
-	  tree init_code = check_initializer (decl, init, flags, &cleanups);
+	  tree init_code;
+	  cleanups = make_tree_vector ();
+	  init_code = check_initializer (decl, init, flags, &cleanups);
 	  if (init_code == NULL_TREE)
 	    init = NULL_TREE;
+	  release_tree_vector (cleanups);
       else if (!DECL_PRETTY_FUNCTION_P (decl))
 	/* Deduce array size even if the initializer is dependent.  */
@@ -6150,6 +6153,7 @@  cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 		error ("Java object %qD not allocated with %<new%>", decl);
 	      init = NULL_TREE;
+	  cleanups = make_tree_vector ();
 	  init = check_initializer (decl, init, flags, &cleanups);
 	  /* Thread-local storage cannot be dynamically initialized.  */
 	  if (DECL_THREAD_LOCAL_P (decl) && init)
@@ -6320,6 +6324,7 @@  cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
       unsigned i; tree t;
       FOR_EACH_VEC_ELT (tree, cleanups, i, t)
 	push_cleanup (decl, t, false);
+      release_tree_vector (cleanups);
   if (was_readonly)