aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorJavier Miranda <miranda@adacore.com>2020-06-30 14:20:09 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2020-10-16 03:34:52 -0400
commit2357b2948db15d5e3529d2368e11b4f6caa2dca0 (patch)
treed09f6f8a6e7379142f18de3ec61d1c1405e15a9d /gcc/ada
parent8dfdfd4048e7a67f2ba01e9efc5d83554d6546ba (diff)
downloadgcc-2357b2948db15d5e3529d2368e11b4f6caa2dca0.zip
gcc-2357b2948db15d5e3529d2368e11b4f6caa2dca0.tar.gz
gcc-2357b2948db15d5e3529d2368e11b4f6caa2dca0.tar.bz2
[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.
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/sem_ch12.adb49
1 files changed, 49 insertions, 0 deletions
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index a626eb3..5f44e81 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