From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Gary Dismukes <dismukes@adacore.com>
Subject: [COMMITTED] ada: Excess finalization on return of call to dispatching constructor
Date: Mon, 6 May 2024 11:18:43 +0200 [thread overview]
Message-ID: <20240506091843.1586654-1-poulhies@adacore.com> (raw)
From: Gary Dismukes <dismukes@adacore.com>
The compiler expands a too-early finalization call for the result
object of an extended return statement that returns a call to a
dispatching constructor function for a limited interface type,
resulting in premature (and extra) finalization of the result.
The temporary object that the compiler creates to hold the result
of the build-in-place call loses the fact that it comes from a
return, and the wrong BIP allocation form may be passed in the
call to the dispatching constructor, and the later code for dealing
with finalization in Exp_Ch7.Build_Finalizer incorrectly finalizes
the result object.
gcc/ada/
* exp_ch6.adb
(Make_Build_In_Place_Iface_Call_In_Object_Declaration): Set the
Is_Return_Object flag on the entity of the temp object created to
hold the BIP call result, from the flag on the passed-in object
declaration's entity. Update copyright notice to 2024.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/exp_ch6.adb | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index fcfd1d7f0bf..a89c9af0bb2 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -9393,6 +9393,16 @@ package body Exp_Ch6 is
Insert_Action (Obj_Decl, Tmp_Decl);
Expander_Mode_Restore;
+ -- Inherit Is_Return_Object from the parent object to the temp object,
+ -- so that Make_In_Build_Place_Call_In_Object_Declaration will handle
+ -- the temp properly in cases where there's a BIP_Alloc_Form formal of
+ -- an enclosing function that should be passed along (and which also
+ -- ensures that if the BIP call is used as a function result and it
+ -- requires finalization, then it will not be finalized prematurely
+ -- or redundantly).
+
+ Set_Is_Return_Object (Tmp_Id, Is_Return_Object (Obj_Id));
+
Make_Build_In_Place_Call_In_Object_Declaration
(Obj_Decl => Tmp_Decl,
Function_Call => Expression (Tmp_Decl));
--
2.43.2
reply other threads:[~2024-05-06 9:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240506091843.1586654-1-poulhies@adacore.com \
--to=poulhies@adacore.com \
--cc=dismukes@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).