From 2357b2948db15d5e3529d2368e11b4f6caa2dca0 Mon Sep 17 00:00:00 2001 From: Javier Miranda Date: Tue, 30 Jun 2020 14:20:09 -0400 Subject: [PATCH] [Ada] Crash in generic renaming declaration of child unit gcc/ada/ * sem_ch12.adb (Check_Generic_Child_Unit): When the child unit is a renaming of a generic child unit then traverse the scope containing the renaming declaration to locate the instance of its parent. Otherwise the parent is not installed and the frontend cannot process the instantiation. --- gcc/ada/sem_ch12.adb | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index a626eb3f867..5f44e813b2f 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -7512,11 +7512,60 @@ package body Sem_Ch12 is null; elsif Present (Entity (Gen_Id)) + and then No (Renamed_Entity (Entity (Gen_Id))) and then Is_Child_Unit (Entity (Gen_Id)) and then not In_Open_Scopes (Inst_Par) then Install_Parent (Inst_Par); Parent_Installed := True; + + -- Handle renaming of generic child unit + + elsif Present (Entity (Gen_Id)) + and then Present (Renamed_Entity (Entity (Gen_Id))) + and then Is_Child_Unit (Renamed_Entity (Entity (Gen_Id))) + then + declare + E : Entity_Id; + Ren_Decl : Node_Id; + + begin + -- The entity of the renamed generic child unit does not + -- have any reference to the instantiated parent. In order to + -- locate it we traverse the scope containing the renaming + -- declaration; the instance of the parent is available in + -- the prefix of the renaming declaration. For example: + + -- package A is + -- package Inst_Par is new ... + -- generic package Ren_Child renames Ins_Par.Child; + -- end; + + -- with A; + -- package B is + -- package Inst_Child is new A.Ren_Child; + -- end; + + E := First_Entity (Entity (Prefix (Gen_Id))); + while Present (E) loop + if Present (Renamed_Entity (E)) + and then + Renamed_Entity (E) = Renamed_Entity (Entity (Gen_Id)) + then + Ren_Decl := Parent (E); + Inst_Par := Entity (Prefix (Name (Ren_Decl))); + + if not In_Open_Scopes (Inst_Par) then + Install_Parent (Inst_Par); + Parent_Installed := True; + end if; + + exit; + end if; + + E := Next_Entity (E); + end loop; + end; end if; elsif In_Enclosing_Instance then