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]
Other format: [Raw text]

Two C++ cleanup PATCHes


1) Some changes to constant initialization that were needed by an early version of the "trivial but deleted" patch. They aren't needed anymore, but still seem correct.

2) We had two functions for building cleanup calls, which is unnecessary duplication. Also, there's no point in limiting use of LOOKUP_NONVIRTUAL in cxx_maybe_build_cleanup because it will be added anyway in build_new_method_call.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit d2987bf536b65ef47ab537d84659caebb501cfc1
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Oct 22 16:35:25 2013 -0400

    	* semantics.c (cxx_eval_call_expression): Handle trivial
    	value-initialization.
    	* typeck2.c (store_init_value): Call maybe_constant_init after
    	cxx_constant_value.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index bbdf81a..de3e8e7 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -8289,12 +8289,18 @@ cxx_eval_call_expression (const constexpr_call *old_call, tree t,
       return t;
     }
 
-  /* Shortcut trivial copy constructor/op=.  */
-  if (call_expr_nargs (t) == 2 && trivial_fn_p (fun))
+  /* Shortcut trivial constructor/op=.  */
+  if (trivial_fn_p (fun))
     {
-      tree arg = convert_from_reference (get_nth_callarg (t, 1));
-      return cxx_eval_constant_expression (old_call, arg, allow_non_constant,
-					   addr, non_constant_p, overflow_p);
+      if (call_expr_nargs (t) == 2)
+	{
+	  tree arg = convert_from_reference (get_nth_callarg (t, 1));
+	  return cxx_eval_constant_expression (old_call, arg, allow_non_constant,
+					       addr, non_constant_p, overflow_p);
+	}
+      else if (TREE_CODE (t) == AGGR_INIT_EXPR
+	       && AGGR_INIT_ZERO_FIRST (t))
+	return build_zero_init (DECL_CONTEXT (fun), NULL_TREE, false);
     }
 
   /* If in direct recursive call, optimize definition search.  */
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index d6ff3ca..9da8e3d 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -775,7 +775,6 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
     {
       bool const_init;
       value = fold_non_dependent_expr (value);
-      value = maybe_constant_init (value);
       if (DECL_DECLARED_CONSTEXPR_P (decl)
 	  || DECL_IN_AGGR_P (decl))
 	{
@@ -786,6 +785,7 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
 	  else
 	    value = cxx_constant_value (value);
 	}
+      value = maybe_constant_init (value);
       const_init = (reduced_constant_expression_p (value)
 		    || error_operand_p (value));
       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = const_init;
commit 72431a75a083a8e89cb44b0f2258b6400c98add6
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Oct 17 14:05:37 2013 -0400

    	* decl.c (cxx_maybe_build_cleanup): Always set LOOKUP_NONVIRTUAL.
    	* decl2.c (build_cleanup): Just call cxx_maybe_build_cleanup.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 476d559..09c1daa 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -14298,9 +14298,7 @@ cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
   type = TREE_TYPE (decl);
   if (type_build_dtor_call (type))
     {
-      int flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
-      bool has_vbases = (TREE_CODE (type) == RECORD_TYPE
-			 && CLASSTYPE_VBASECLASSES (type));
+      int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
       tree addr;
       tree call;
 
@@ -14309,10 +14307,6 @@ cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
       else
 	addr = build_address (decl);
 
-      /* Optimize for space over speed here.  */
-      if (!has_vbases || flag_expensive_optimizations)
-	flags |= LOOKUP_NONVIRTUAL;
-
       call = build_delete (TREE_TYPE (addr), addr,
 			   sfk_complete_destructor, flags, 0, complain);
       if (call == error_mark_node)
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index d776471..18e0e52 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -2722,26 +2722,9 @@ import_export_decl (tree decl)
 tree
 build_cleanup (tree decl)
 {
-  tree temp;
-  tree type = TREE_TYPE (decl);
-
-  /* This function should only be called for declarations that really
-     require cleanups.  */
-  gcc_assert (!TYPE_HAS_TRIVIAL_DESTRUCTOR (type));
-
-  /* Treat all objects with destructors as used; the destructor may do
-     something substantive.  */
-  mark_used (decl);
-
-  if (TREE_CODE (type) == ARRAY_TYPE)
-    temp = decl;
-  else
-    temp = build_address (decl);
-  temp = build_delete (TREE_TYPE (temp), temp,
-		       sfk_complete_destructor,
-		       LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0,
-		       tf_warning_or_error);
-  return temp;
+  tree clean = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
+  gcc_assert (clean != NULL_TREE);
+  return clean;
 }
 
 /* Returns the initialization guard variable for the variable DECL,

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