public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Marc Poulhi?s <dkm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-1863] ada: Fix wrong finalization for double subtype of bounded vector
Date: Thu, 15 Jun 2023 08:03:31 +0000 (GMT)	[thread overview]
Message-ID: <20230615080331.6665E3858000@sourceware.org> (raw)

https://gcc.gnu.org/g:59a8207f83855d756a6a87fa4b9537899d88f0a2

commit r14-1863-g59a8207f83855d756a6a87fa4b9537899d88f0a2
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Wed May 10 18:00:36 2023 +0200

    ada: Fix wrong finalization for double subtype of bounded vector
    
    The special handling of temporaries created for return values and subject
    to a renaming needs to be restricted to the top level, where it is needed
    to prevent dangling references to the frame of the elaboration routine from
    being created, because, at a lower level, the front-end may create implicit
    renamings of objects as these temporaries, so a copy is not allowed.
    
    gcc/ada/
    
            * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Restrict
            the special handling of temporaries created for return values and
            subject to a renaming to the top level.

Diff:
---
 gcc/ada/gcc-interface/decl.cc | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index e5e04ddad93..b2b77787bc0 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -1076,9 +1076,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
 		|| EXPRESSION_CLASS_P (inner)
 		/* We need to detect the case where a temporary is created to
 		   hold the return value, since we cannot safely rename it at
-		   top level as it lives only in the elaboration routine.  */
+		   top level because it lives only in the elaboration routine.
+		   But, at a lower level, an object initialized by a function
+		   call may be (implicitly) renamed as this temporary by the
+		   front-end and, in this case, we cannot make a copy.  */
 		|| (VAR_P (inner)
-		    && DECL_RETURN_VALUE_P (inner))
+		    && DECL_RETURN_VALUE_P (inner)
+		    && global_bindings_p ())
 		/* We also need to detect the case where the front-end creates
 		   a dangling 'reference to a function call at top level and
 		   substitutes it in the renaming, for example:
@@ -1092,12 +1096,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
 		     q__b : boolean renames q__R1s.all.e (1);
 
 		   We cannot safely rename the rewritten expression since the
-		   underlying object lives only in the elaboration routine.  */
+		   underlying object lives only in the elaboration routine but,
+		   as above, this cannot be done at a lower level.  */
 		|| (INDIRECT_REF_P (inner)
 		    && (inner
 			= remove_conversions (TREE_OPERAND (inner, 0), true))
 		    && VAR_P (inner)
-		    && DECL_RETURN_VALUE_P (inner)))
+		    && DECL_RETURN_VALUE_P (inner)
+		    && global_bindings_p ()))
 	      ;
 
 	    /* Otherwise, this is an lvalue being renamed, so it needs to be

                 reply	other threads:[~2023-06-15  8:03 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=20230615080331.6665E3858000@sourceware.org \
    --to=dkm@gcc.gnu.org \
    --cc=gcc-cvs@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).