diff options
author | Christian Bruel <christian.bruel@st.com> | 2007-10-31 08:55:46 +0100 |
---|---|---|
committer | Christian Bruel <chrbr@gcc.gnu.org> | 2007-10-31 08:55:46 +0100 |
commit | 0e95aec103af4ec97f6d282b95882f2e0efb0b41 (patch) | |
tree | 1772c4492246ada1dc117970639ac519e3f39c9f | |
parent | 4ac4ec1822121b00c1d24d61a15ad71f066c2010 (diff) | |
download | gcc-0e95aec103af4ec97f6d282b95882f2e0efb0b41.zip gcc-0e95aec103af4ec97f6d282b95882f2e0efb0b41.tar.gz gcc-0e95aec103af4ec97f6d282b95882f2e0efb0b41.tar.bz2 |
fix PR c++/19531: NRV is performed on volatile temporary
Co-Authored-By: Mark Mitchell <mark@codesourcery.com>
From-SVN: r129792
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/opt/nrv8.C | 31 |
4 files changed, 46 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5e2447f..484d152 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2007-10-31 Christian Bruel <christian.bruel@st.com> + Mark Mitchell <mark@codesourcery.com> + + PR c++/19531 + * cp/typeck.c (check_return_expr): Don't set named_return_value_okay_p + if retval is volatile. + 2007-10-30 Jakub Jelinek <jakub@redhat.com> PR c++/33616 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 392e2db..c31a7a8 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6744,7 +6744,9 @@ check_return_expr (tree retval, bool *no_warning) function. */ && same_type_p ((TYPE_MAIN_VARIANT (TREE_TYPE (retval))), (TYPE_MAIN_VARIANT - (TREE_TYPE (TREE_TYPE (current_function_decl)))))); + (TREE_TYPE (TREE_TYPE (current_function_decl))))) + /* And the returned value must be non-volatile. */ + && ! TYPE_VOLATILE (TREE_TYPE (retval))); if (fn_returns_value_p && flag_elide_constructors) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 82dbb7a..9492582 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-10-31 Christian Bruel <christian.bruel@st.com> + + PR c++/19531 + * g++.dg/opt/nrv8.C: New. + 2007-10-30 Jakub Jelinek <jakub@redhat.com> PR c++/33709 diff --git a/gcc/testsuite/g++.dg/opt/nrv8.C b/gcc/testsuite/g++.dg/opt/nrv8.C new file mode 100644 index 0000000..19999a1 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/nrv8.C @@ -0,0 +1,31 @@ +// PR optimization/19531 +// forbids NRV on volatile return value. +// { dg-options -O2 } +// { 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; +} |