From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 579A53858C30; Thu, 5 Jan 2023 14:38:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 579A53858C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672929505; bh=KCksOJjYHhEDzAcsYZ9sR+lYsmWn6em420lIX3k5m5g=; h=From:To:Subject:Date:From; b=tkpbawPMIDrDSnTTas81N+NA4JnAyu7RelG0U4ESglu/rPn17q4XStXbFbPWGZp8u KYNFHA5K33NqSrUOKCOHf/adOWq3TQkLDNGCmdzvNaoNZKldzsOzxlb/kyehqcpoE/ RR2a1IiQ5Gz/00yyREvgyu4BdAjwrZvhgMMi5gfg= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5016] ada: Fix generic instantiation of sibling package X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 2aa5f94243c5d463cc62a3c91ebf87fb1c665b83 X-Git-Newrev: 912d1e184a4f6c66bc57893e5745ec74009b4fd1 Message-Id: <20230105143825.579A53858C30@sourceware.org> Date: Thu, 5 Jan 2023 14:38:25 +0000 (GMT) List-Id: https://gcc.gnu.org/g:912d1e184a4f6c66bc57893e5745ec74009b4fd1 commit r13-5016-g912d1e184a4f6c66bc57893e5745ec74009b4fd1 Author: Marc Poulhiès Date: Thu Dec 15 11:32:19 2022 +0100 ada: Fix generic instantiation of sibling package 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. Diff: --- 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);