This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++] PR19531 NRV is performed on volatile temporary
- From: Christian BRUEL <christian dot bruel at st dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 26 Sep 2007 09:19:01 +0200
- Subject: [C++] PR19531 NRV is performed on volatile temporary
Hello,
Here is a fix for PR 19531. testsuite tested for i686-pc-linux-gnu
thanks,
Christian
2007-09-24 Christian Bruel <christian.bruel@st.com>
PR c++/19531
* cp/decl.c (finish_function): Check volatility for nrv.
2007-09-24 Christian Bruel <christian.bruel@st.com>
PR c++/19531
* g++.dg/opt/nrv8.C: New.
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c (revision 128777)
+++ gcc/cp/decl.c (working copy)
@@ -11729,7 +11729,9 @@
return; see g++.dg/opt/nrv6.C. We could be more flexible if
we were to do this optimization in tree-ssa. */
&& (outer = outer_curly_brace_block (fndecl))
- && chain_member (r, BLOCK_VARS (outer)))
+ && chain_member (r, BLOCK_VARS (outer))
+ && !TYPE_VOLATILE (TREE_TYPE (r))
+ && !TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (fndecl))))
finalize_nrv (&DECL_SAVED_TREE (fndecl), r, DECL_RESULT (fndecl));
current_function_return_value = NULL_TREE;
// PR optimization/19531
// forbids NRV on volatile return value.
// { dg-options "-fno-inline" }
// { dg-do run }
extern "C" { void abort(); }
struct A
{
int d;
A () { d = 123; }
A (const A & o) { d = o.d; }
A (volatile const A & o) { d = o.d + 2; }
};
A bar()
{
volatile A l;
return l;
}
main()
{
A a = bar ();
if (a.d != 125)
abort();
return 0;
}