public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [COMMITTED] ada: Further cleanup in finalization machinery
Date: Tue, 21 Nov 2023 11:00:39 +0100	[thread overview]
Message-ID: <20231121100039.1964698-1-poulhies@adacore.com> (raw)

From: Eric Botcazou <ebotcazou@adacore.com>

The bodies of generic units are instantiated separately by GNAT at the end
of the processing of the compilation unit.  This requires the deferral of
the generation of cleanups and finalization actions in enclosing scopes,
except for instantiations in generic units where they are not generated.

The criterion used to detect this latter case is Inside_A_Generic, but this
global variable is not properly updated during the instantiation of generic
bodies, leading to problems with nested instantiations, so it is changed to
Expander_Active instead.  As a matter of fact, the exact same idiom is used
a few lines above to clear the Needs_Body variable.

gcc/ada/

	* sem_ch12.adb (Analyze_Package_Instantiation): Test Expander_Active
	to detect generic contexts for the generation of cleanup actions.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch12.adb | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 31fcbedf774..7c645c490ae 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -4824,10 +4824,7 @@ package body Sem_Ch12 is
                      --  Cleanup actions are not generated within generic units
                      --  or in the formal part of generic units.
 
-                     if Inside_A_Generic
-                       or else Is_Generic_Unit (S)
-                       or else Ekind (S) = E_Void
-                     then
+                     if not Expander_Active then
                         exit;
 
                      --  For package scopes, cleanup actions are generated only
-- 
2.42.0


             reply	other threads:[~2023-11-21 10:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21 10:00 Marc Poulhiès [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-12-19 14:30 Marc Poulhiès
2023-12-19 14:29 Marc Poulhiès
2023-11-28  9:39 Marc Poulhiès
2023-11-21 10:00 Marc Poulhiès

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=20231121100039.1964698-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=ebotcazou@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).