]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/32992 (Incorrect code generated for anonymous union and return)
authorJakub Jelinek <jakub@redhat.com>
Mon, 20 Aug 2007 08:17:21 +0000 (10:17 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 20 Aug 2007 08:17:21 +0000 (10:17 +0200)
PR c++/32992
* typeck.c (check_return_expr): Don't NRV optimize vars in
anonymous unions.
* decl.c (finish_function): Comment fix.

* g++.dg/opt/nrv14.C: New test.

From-SVN: r127641

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/nrv14.C [new file with mode: 0644]

index dcbef47211344aab50b351eaa397fbb3dfe98083..3d66b0ef992987969a937fc57b65185f9f1c1319 100644 (file)
@@ -1,3 +1,10 @@
+2007-08-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/32992
+       * typeck.c (check_return_expr): Don't NRV optimize vars in
+       anonymous unions.
+       * decl.c (finish_function): Comment fix.
+
 2007-08-18  Paolo Carlini  <pcarlini@suse.de>
 
        PR c++/32112
index 32040abfa4f80cbdd021d0f6e1753e87a9eb23dd..4aac4eebef37db77691d25cf41482016b50cb548 100644 (file)
@@ -11058,7 +11058,7 @@ finish_function (int flags)
   gcc_assert (stmts_are_full_exprs_p ());
 
   /* Set up the named return value optimization, if we can.  Candidate
-     variables are selected in check_return_value.  */
+     variables are selected in check_return_expr.  */
   if (current_function_return_value)
     {
       tree r = current_function_return_value;
index a0935272b5d477cb9b7beaceeb2a263fb7442578..07fc4768b9964dc0f4038c04971ba2a31e4eb1fc 100644 (file)
@@ -6439,6 +6439,7 @@ check_return_expr (tree retval, bool *no_warning)
          && TREE_CODE (retval) == VAR_DECL
          && DECL_CONTEXT (retval) == current_function_decl
          && ! TREE_STATIC (retval)
+         && ! DECL_HAS_VALUE_EXPR_P (retval)
          && (DECL_ALIGN (retval)
              >= DECL_ALIGN (DECL_RESULT (current_function_decl)))
          && same_type_p ((TYPE_MAIN_VARIANT
index 177640227cbf9c27b6ac2374e0cfbc03cafb6963..a3c554d2321924380574583e5ee0757276ee8ce3 100644 (file)
@@ -1,3 +1,8 @@
+2007-08-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/32992
+       * g++.dg/opt/nrv14.C: New test.
+
 2007-08-18  Paolo Carlini  <pcarlini@suse.de>
 
        PR c++/32112
diff --git a/gcc/testsuite/g++.dg/opt/nrv14.C b/gcc/testsuite/g++.dg/opt/nrv14.C
new file mode 100644 (file)
index 0000000..22526d6
--- /dev/null
@@ -0,0 +1,39 @@
+// PR c++/32992
+// { dg-do run }
+// { dg-options "-O2" }
+
+extern "C" void abort (void);
+
+struct A
+{
+  long int a1;
+  long int a2;
+  long int a3;
+};
+
+struct B
+{
+  long int f[3];
+  operator A ()
+  {
+    union
+    {
+      long int t[3];
+      A a;
+    };
+    for (int i = 0; i < 3; i++)
+      t[i] = f[i];
+    return a;
+  }
+};
+
+int
+main ()
+{
+  B b = { {1, 3, 5} };
+  A a = b;
+
+  if (a.a1 != b.f[0] || a.a2 != b.f[1] || a.a3 != b.f[2])
+    abort ();
+  return 0;
+}