This patch fixes a crash in the compiler when enabling unnesting of subprograms
on a generic unit.
The following must compile quietly:
gcc -c -gnatg -gnatd.1 a-btgbso.adb
Tested on x86_64-pc-linux-gnu, committed on trunk
2017-12-15 Ed Schonberg <[email protected]>
* exp_unst.adb (Unnest_Subprograms): Nothing to do if the main unit is
a generic package body. Unnesting is only an issue when generating
code, and if the main unit is generic then nested instance bodies have
not been created and analyzed, and unnesting will crash in the absence
of those bodies,
Index: exp_unst.adb
===================================================================
--- exp_unst.adb (revision 255680)
+++ exp_unst.adb (working copy)
@@ -302,6 +302,16 @@
return;
end if;
+ -- If the main unit is a package body then we need to examine the spec
+ -- to determine whether the main unit is generic (the scope stack is not
+ -- present when this is called on the main unit).
+
+ if Ekind (Cunit_Entity (Main_Unit)) = E_Package_Body
+ and then Is_Generic_Unit (Spec_Entity (Cunit_Entity (Main_Unit)))
+ then
+ return;
+ end if;
+
-- At least for now, do not unnest anything but main source unit
if not In_Extended_Main_Source_Unit (Subp_Body) then
@@ -553,8 +563,8 @@
Ent := Entity (Name (N));
-- We are only interested in calls to subprograms nested
- -- within Subp. Calls to Subp itself or to subprograms that
- -- are outside the nested structure do not affect us.
+ -- within Subp. Calls to Subp itself or to subprograms
+ -- that are outside the nested structure do not affect us.
if Scope_Within (Ent, Subp) then
@@ -1653,7 +1663,6 @@
if Present (STT.ARECnF)
and then Nkind (CTJ.N) /= N_Attribute_Reference
then
-
-- CTJ.N is a call to a subprogram which may require a pointer
-- to an activation record. The subprogram containing the call
-- is CTJ.From and the subprogram being called is CTJ.To, so we