C++ copy elision and alignment

Submitted by Marc Glisse on May 18, 2013, 4:17 p.m.

Details

Message ID alpine.DEB.2.02.1305181810420.28297@stedding.saclay.inria.fr
State New
Headers show

Commit Message

Marc Glisse May 18, 2013, 4:17 p.m.
Hello,

this patch passes bootstrap+testsuite on x86_64-linux-gnu. As explained in 
the PR, it seems that the check for alignment is in the wrong direction 
(tree-nrv.c and ada have the reverse one).

2013-05-18  Marc Glisse  <marc.glisse@inria.fr>

 	PR c++/57175
gcc/cp/
 	* typeck.c (check_return_expr): Reverse the alignment comparison.

gcc/testsuite/
 	* g++.dg/pr57175.C: New testcase.

Comments

Jason Merrill May 20, 2013, 1:39 a.m.
OK.

Jason

Patch hide | download patch | download mbox

Index: testsuite/g++.dg/pr57175.C
===================================================================
--- testsuite/g++.dg/pr57175.C	(revision 0)
+++ testsuite/g++.dg/pr57175.C	(revision 0)
@@ -0,0 +1,19 @@ 
+/* { dg-do compile } */
+/* { dg-options "-std=c++11" } */
+
+extern "C" void do_not_remove ();
+
+struct A
+{
+  A () { }
+  A (A const&) { do_not_remove (); }
+};
+
+A
+f ()
+{
+  alignas (2 * alignof (A)) A x;
+  return x;
+}
+
+/* { dg-final { scan-assembler "do_not_remove" } } */

Property changes on: testsuite/g++.dg/pr57175.C
___________________________________________________________________
Added: svn:eol-style
   + native
Added: svn:keywords
   + Author Date Id Revision URL

Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 199049)
+++ cp/typeck.c	(working copy)
@@ -8362,21 +8362,21 @@  check_return_expr (tree retval, bool *no
 
      See finish_function and finalize_nrv for the rest of this optimization.  */
 
   named_return_value_okay_p = 
     (retval != NULL_TREE
      /* Must be a local, automatic variable.  */
      && VAR_P (retval)
      && DECL_CONTEXT (retval) == current_function_decl
      && ! TREE_STATIC (retval)
      && ! DECL_ANON_UNION_VAR_P (retval)
-     && (DECL_ALIGN (retval) >= DECL_ALIGN (result))
+     && (DECL_ALIGN (retval) <= DECL_ALIGN (result))
      /* The cv-unqualified type of the returned value must be the
         same as the cv-unqualified return type of the
         function.  */
      && same_type_p ((TYPE_MAIN_VARIANT (TREE_TYPE (retval))),
                      (TYPE_MAIN_VARIANT (functype)))
      /* And the returned value must be non-volatile.  */
      && ! TYPE_VOLATILE (TREE_TYPE (retval)));
      
   if (fn_returns_value_p && flag_elide_constructors)
     {