From dd7ce4f8d57ad460b067828756681b2566f7947c Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 17 Mar 2003 10:46:37 -0500 Subject: [PATCH] re PR c++/9993 (destructor not called for local object created within and returned from infinite loop) PR c++/9993 * decl.c (finish_function): Only allow the NRVO to use variables declared at function scope. From-SVN: r64489 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6487a59218c6..28883b2b91e1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2003-03-17 Jason Merrill + + PR c++/9993 + * decl.c (finish_function): Only allow the NRVO to use variables + declared at function scope. + 2003-03-16 Kriang Lerdsuwanakij PR c++/6440 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 3e23c8aeecee..7ba863d4347e 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -14309,11 +14309,21 @@ finish_function (flags) if (current_function_return_value) { tree r = current_function_return_value; - /* This is only worth doing for fns that return in memory--and - simpler, since we don't have to worry about promoted modes. */ + tree outer; + if (r != error_mark_node - && aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl)))) + /* This is only worth doing for fns that return in memory--and + simpler, since we don't have to worry about promoted modes. */ + && aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl))) + /* Only allow this for variables declared in the outer scope of + the function so we know that their lifetime always ends with a + return; see g++.dg/opt/nrv6.C. We could be more flexible if + we were to do this optimization in tree-ssa. */ + /* Skip the artificial function body block. */ + && (outer = BLOCK_SUBBLOCKS (BLOCK_SUBBLOCKS (DECL_INITIAL (fndecl))), + chain_member (r, BLOCK_VARS (outer)))) { + DECL_ALIGN (r) = DECL_ALIGN (DECL_RESULT (fndecl)); walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl), nullify_returns_r, r); -- 2.47.2