On 01/08/2016 06:18 AM, Richard Biener wrote:
On Fri, Jan 8, 2016 at 8:22 AM, Eric Botcazou <ebotca...@adacore.com> wrote:
But it occurs to me that since the real problem I was trying to catch is
creation of temporaries of TREE_ADDRESSABLE type in the back end, we
should guard that instead.  So this patch moves the assert into assign_temp.

FWIW create_tmp_var has a slightly stronger version:

   gcc_assert (!TREE_ADDRESSABLE (type) && COMPLETE_TYPE_P (type));

Ok with the assert changed to match that of create_tmp_var.

OK, here's what I'm checking in, along with a couple of front-end patches, one for the testcase in a later comment, and one to remove a no longer necessary workaround.

Tested x86_64-pc-linux-gnu, applying to trunk. Second patch also applying to 5 and 4.9.

commit b19275b06469777575364c62c8976d79c95bbb68
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu Jan 7 09:46:59 2016 -0500

    	PR c++/68983
    
    	PR c++/67557
    gcc/
    	* function.c (assign_temp): Guard against TREE_ADDRESSABLE types here.
    	* expr.c (store_field): Not here.
    	* tree-cfgcleanup.c (fixup_noreturn_call): Don't clear LHS of a
    	call with TREE_ADDRESSABLE type.
    	* tree-cfg.c (verify_gimple_call): Adjust.
    gcc/cp/
    	* cvt.c (convert_to_void): Don't strip a TARGET_EXPR of
    	TREE_ADDRESSABLE type.

diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index d79f13b..f381f9b 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -1229,11 +1229,12 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
 
     case TARGET_EXPR:
       /* Don't bother with the temporary object returned from a function if
-	 we don't use it and don't need to destroy it.  We'll still
+	 we don't use it, don't need to destroy it, and won't abort in
+	 assign_temp.  We'll still
 	 allocate space for it in expand_call or declare_return_variable,
 	 but we don't need to track it through all the tree phases.  */
       if (TARGET_EXPR_IMPLICIT_P (expr)
-	  && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (expr)))
+	  && !TREE_ADDRESSABLE (TREE_TYPE (expr)))
 	{
 	  tree init = TARGET_EXPR_INITIAL (expr);
 	  if (TREE_CODE (init) == AGGR_INIT_EXPR
diff --git a/gcc/expr.c b/gcc/expr.c
index 8973893..0c5dff8 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -6655,9 +6655,6 @@ store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos,
       rtx temp;
       gimple *nop_def;
 
-      /* Using bitwise copy is not safe for TREE_ADDRESSABLE types.  */
-      gcc_assert (!TREE_ADDRESSABLE (TREE_TYPE (exp)));
-
       /* If EXP is a NOP_EXPR of precision less than its mode, then that
 	 implies a mask operation.  If the precision is the same size as
 	 the field we're storing into, that mask is redundant.  This is
diff --git a/gcc/function.c b/gcc/function.c
index 603ea80..1ac8e26 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -956,6 +956,10 @@ assign_temp (tree type_or_decl, int memory_required,
   unsignedp = TYPE_UNSIGNED (type);
 #endif
 
+  /* Allocating temporaries of TREE_ADDRESSABLE type must be done in the front
+     end.  See also create_tmp_var for the gimplification-time check.  */
+  gcc_assert (!TREE_ADDRESSABLE (type) && COMPLETE_TYPE_P (type));
+
   if (mode == BLKmode || memory_required)
     {
       HOST_WIDE_INT size = int_size_in_bytes (type);
diff --git a/gcc/testsuite/g++.dg/init/base1.C b/gcc/testsuite/g++.dg/init/base1.C
new file mode 100644
index 0000000..bce2f17
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/base1.C
@@ -0,0 +1,14 @@
+// PR c++/68983
+
+class SvxOptionsGrid {
+  int nFldDrawX;
+  bool bEqualGrid;
+public:
+  ~SvxOptionsGrid();
+};
+class A : SvxOptionsGrid {
+public:
+  A(SvxOptionsGrid p1) : SvxOptionsGrid(p1) {}
+};
+SvxOptionsGrid a;
+void fn1() { A b(a); }
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index e75774e..dbfa506 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -3371,7 +3371,8 @@ verify_gimple_call (gcall *stmt)
   if (lhs
       && gimple_call_ctrl_altering_p (stmt)
       && gimple_call_noreturn_p (stmt)
-      && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) == INTEGER_CST)
+      && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) == INTEGER_CST
+      && !TREE_ADDRESSABLE (TREE_TYPE (lhs)))
     {
       error ("LHS in noreturn call");
       return true;
diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c
index bd7c3c9..46d0fa3 100644
--- a/gcc/tree-cfgcleanup.c
+++ b/gcc/tree-cfgcleanup.c
@@ -601,9 +601,11 @@ fixup_noreturn_call (gimple *stmt)
 
   /* If there is an LHS, remove it, but only if its type has fixed size.
      The LHS will need to be recreated during RTL expansion and creating
-     temporaries of variable-sized types is not supported.  */
+     temporaries of variable-sized types is not supported.  Also don't
+     do this with TREE_ADDRESSABLE types, as assign_temp will abort.  */
   tree lhs = gimple_call_lhs (stmt);
-  if (lhs && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) == INTEGER_CST)
+  if (lhs && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) == INTEGER_CST
+      && !TREE_ADDRESSABLE (TREE_TYPE (lhs)))
     {
       gimple_call_set_lhs (stmt, NULL_TREE);
 
commit eef2dcae0cf13cc66db2e7b524f2afa9583b0641
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu Jan 7 09:31:44 2016 -0500

    	PR c++/68983
    
    	PR c++/67557
    	* call.c (unsafe_copy_elision_p): Look through COMPOUND_EXPR.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 4c3c415..ad2c1bc 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7161,6 +7161,9 @@ unsafe_copy_elision_p (tree target, tree exp)
       && resolves_to_fixed_type_p (target, NULL))
     return false;
   tree init = TARGET_EXPR_INITIAL (exp);
+  /* build_compound_expr pushes COMPOUND_EXPR inside TARGET_EXPR.  */
+  while (TREE_CODE (init) == COMPOUND_EXPR)
+    init = TREE_OPERAND (init, 1);
   return (TREE_CODE (init) == AGGR_INIT_EXPR
 	  && !AGGR_INIT_VIA_CTOR_P (init));
 }
diff --git a/gcc/testsuite/g++.dg/init/elide4.C b/gcc/testsuite/g++.dg/init/elide4.C
new file mode 100644
index 0000000..f85d6ee
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/elide4.C
@@ -0,0 +1,13 @@
+// PR c++/67557
+
+class A {
+public:
+  A m_fn1();
+  A(A const &);
+  int *L;
+  int ref;
+};
+struct B : A {
+  B();
+};
+B::B() : A((0, m_fn1())) {}
commit f2adb8a5b5117dc016b403cb697d7ad765578f87
Author: Jason Merrill <ja...@redhat.com>
Date:   Fri Jan 8 10:38:56 2016 -0500

    	* constexpr.c (cxx_eval_call_expression): Remove convert_to_void
    	workaround.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index bcf26a6..c6c3467 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1285,16 +1285,6 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
       ctx->values->put (new_ctx.object, ctor);
       ctx = &new_ctx;
     }
-  else if (DECL_BY_REFERENCE (DECL_RESULT (fun))
-	   && TREE_CODE (t) != AGGR_INIT_EXPR)
-    {
-      /* convert_to_void stripped our AGGR_INIT_EXPR, in which case we don't
-	 care about a constant value.  ??? we could still optimize away the
-	 call.  */
-      gcc_assert (ctx->quiet && !ctx->object);
-      *non_constant_p = true;
-      return t;
-    }
 
   bool non_constant_args = false;
   cxx_bind_parameters_in_call (ctx, t, &new_call,

Reply via email to