OSDN Git Service

fix PR c++/19531: NRV is performed on volatile temporary
authorchrbr <chrbr@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 31 Oct 2007 07:55:46 +0000 (07:55 +0000)
committerchrbr <chrbr@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 31 Oct 2007 07:55:46 +0000 (07:55 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@129792 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 5e2447f..484d152 100644 (file)
@@ -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
index 392e2db..c31a7a8 100644 (file)
@@ -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)
     {
index 82dbb7a..9492582 100644 (file)
@@ -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 (file)
index 0000000..19999a1
--- /dev/null
@@ -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;
+}