From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: "Marc Poulhiès" <poulhies@adacore.com>
Subject: [COMMITTED] ada: Fix generic instantiation of sibling package
Date: Thu, 5 Jan 2023 15:39:18 +0100 [thread overview]
Message-ID: <20230105143918.155693-1-poulhies@adacore.com> (raw)
The compiler would crash because it is failing at setting up the scope
stack correctly for a generic instantiation of a sibling package within
a child package instance. In this case, the parent instance isn't
explicitly referenced and it must be found differently.
gcc/ada/
* sem_ch12.adb (Instantiate_Package_Body): Correctly find the
parent instance to place on the scope stack.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_ch12.adb | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 1ea95845a16..0f2dd39b53c 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -12150,8 +12150,26 @@ package body Sem_Ch12 is
end;
-- If it is a child unit, make the parent instance (which is an
- -- instance of the parent of the generic) visible. The parent
- -- instance is the prefix of the name of the generic unit.
+ -- instance of the parent of the generic) visible.
+
+ -- 1) The child unit's parent is an explicit parent instance (the
+ -- prefix of the name of the generic unit):
+
+ -- package Child_Package is new Parent_Instance.Child_Unit;
+
+ -- 2) The child unit's parent is an implicit parent instance (e.g.
+ -- when instantiating a sibling package):
+
+ -- generic
+ -- package Parent.Second_Child is
+ -- ...
+
+ -- generic
+ -- package Parent.First_Child is
+ -- package Sibling_Package is new Second_Child;
+
+ -- 3) The child unit's parent is not an instance, so the scope is
+ -- simply the one of the unit.
if Ekind (Scope (Gen_Unit)) = E_Generic_Package
and then Nkind (Gen_Id) = N_Expanded_Name
@@ -12161,6 +12179,17 @@ package body Sem_Ch12 is
Install_Parent (Par_Ent, In_Body => True);
Par_Installed := True;
+ elsif Ekind (Scope (Gen_Unit)) = E_Generic_Package
+ and then Ekind (Scope (Act_Decl_Id)) = E_Package
+ and then Is_Generic_Instance (Scope (Act_Decl_Id))
+ then
+ Par_Ent := Entity
+ (Prefix (Name (Get_Unit_Instantiation_Node
+ (Scope (Act_Decl_Id)))));
+ Par_Vis := Is_Immediately_Visible (Par_Ent);
+ Install_Parent (Par_Ent, In_Body => True);
+ Par_Installed := True;
+
elsif Is_Child_Unit (Gen_Unit) then
Par_Ent := Scope (Gen_Unit);
Par_Vis := Is_Immediately_Visible (Par_Ent);
--
2.34.1
reply other threads:[~2023-01-05 14:39 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=20230105143918.155693-1-poulhies@adacore.com \
--to=poulhies@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).