73 lines
1.8 KiB
Diff
73 lines
1.8 KiB
Diff
2007-08-13 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.
|
|
|
|
* g++.dg/opt/nrv14.C: New test.
|
|
|
|
--- gcc/cp/typeck.c.jj 2007-08-13 15:10:19.000000000 +0200
|
|
+++ gcc/cp/typeck.c 2007-08-13 18:00:15.000000000 +0200
|
|
@@ -6446,6 +6446,7 @@ check_return_expr (tree retval, bool *no
|
|
&& 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
|
|
--- gcc/cp/decl.c.jj 2007-08-13 15:10:19.000000000 +0200
|
|
+++ gcc/cp/decl.c 2007-08-13 18:09:33.000000000 +0200
|
|
@@ -11566,7 +11566,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;
|
|
--- gcc/testsuite/g++.dg/opt/nrv14.C.jj 2007-08-13 18:07:09.000000000 +0200
|
|
+++ gcc/testsuite/g++.dg/opt/nrv14.C 2007-08-13 18:07:46.000000000 +0200
|
|
@@ -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;
|
|
+}
|