From: Gabriel Dos Reis Date: Mon, 13 Sep 2004 08:39:17 +0000 (+0000) Subject: re PR rtl-optimization/15857 (Wrong code with optimization >= -O1) X-Git-Tag: releases/gcc-3.3.5~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=892e970aa2498b303eb6d9a12f00822f650bf5c9;p=thirdparty%2Fgcc.git re PR rtl-optimization/15857 (Wrong code with optimization >= -O1) PR c++/15857 Backport from gcc-3_4-branch 2004-08-24 Jason Merrill PR c++/15461 * semantics.c (nullify_returns_r): Replace a DECL_STMT for the NRV with an INIT_EXPR. From-SVN: r87429 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c12a9918650d..e21cb0ac08ec 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,6 @@ 2004-09-13 Gabriel Dos Reis + PR c++/15857 Backport from gcc-3_4-branch 2004-08-24 Jason Merrill PR c++/15461 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 110eb3a9e7ab..f9d6b53fd38e 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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; } diff --git a/gcc/testsuite/g++.dg/opt/nrv7.C b/gcc/testsuite/g++.dg/opt/nrv7.C index c5034ecc0f21..43c44a0944f1 100644 --- a/gcc/testsuite/g++.dg/opt/nrv7.C +++ b/gcc/testsuite/g++.dg/opt/nrv7.C @@ -10,4 +10,4 @@ inline A foo () { return a; } -A tv = foo(); +A tv = foo();