]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR rtl-optimization/15857 (Wrong code with optimization >= -O1)
authorGabriel Dos Reis <gdr@integrable-solutions.net>
Mon, 13 Sep 2004 08:39:17 +0000 (08:39 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Mon, 13 Sep 2004 08:39:17 +0000 (08:39 +0000)
        PR c++/15857
        Backport from gcc-3_4-branch
        2004-08-24  Jason Merrill  <jason@redhat.com>
        PR c++/15461
        * semantics.c (nullify_returns_r): Replace a DECL_STMT
        for the NRV with an INIT_EXPR.

From-SVN: r87429

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/opt/nrv7.C

index c12a9918650d93fe28e401a176af67a19d89a434..e21cb0ac08ecb72db247be96312833561b7cff8c 100644 (file)
@@ -1,5 +1,6 @@
 2004-09-13  Gabriel Dos Reis  <gdr@integrable-solutions.net>
 
+       PR c++/15857
        Backport from gcc-3_4-branch
        2004-08-24  Jason Merrill  <jason@redhat.com>
        PR c++/15461
index 110eb3a9e7ab864d13acf0d134dfc6c034810a4e..f9d6b53fd38e93392dbca6ca5a5735b2f47dffda 100644 (file)
@@ -2457,7 +2457,28 @@ nullify_returns_r (tp, walk_subtrees, data)
   else if (TREE_CODE (*tp) == CLEANUP_STMT
           && CLEANUP_DECL (*tp) == nrv)
     CLEANUP_EH_ONLY (*tp) = 1;
-
+  /* Replace the DECL_STMT for the NRV with an initialization of the
+     RESULT_DECL, if needed.  */
+  else if (TREE_CODE (*tp) == DECL_STMT
+          && DECL_STMT_DECL (*tp) == nrv)
+    {
+      tree init;
+      if (DECL_INITIAL (nrv)
+         && DECL_INITIAL (nrv) != error_mark_node)
+       {
+         init = build (INIT_EXPR, void_type_node,
+                       DECL_RESULT (current_function_decl),
+                       DECL_INITIAL (nrv));
+         DECL_INITIAL (nrv) = error_mark_node;
+       }
+      else
+       init = NULL_TREE;
+      init = build_stmt (EXPR_STMT, init);
+      TREE_CHAIN (init) = TREE_CHAIN (*tp);
+      STMT_LINENO (init) = STMT_LINENO (*tp);
+      *tp = init;
+    }
   /* Keep iterating.  */
   return NULL_TREE;
 }
index c5034ecc0f21fa47ab05a8ed81c8a9867a63054d..43c44a0944f1359858b0d9989a6b55a09ef19950 100644 (file)
@@ -10,4 +10,4 @@ inline A foo () {
     return a;  
 } 
  
-A tv = foo(); 
+A tv = foo();