[Ada] Crash on instantiation with renamed formal package.

Pierre-Marie de Rodat derodat@adacore.com
Mon Sep 25 09:26:00 GMT 2017


This patch fixes a compiler abort on a package instantiation when the
corresponding generic has a formal package, and the instantiation has an
actual that renames the desired package instance.

The following must compile quietly:

   gcc -c mc.adb

---
package MC is
  procedure Dump_States;
end MC;
---
with Configurations;
with UCTL;
package body MC is
  package MyConfigurations is new Configurations;
  package Configurations renames MyConfigurations;

  package MyUCTL0 is new UCTL(MYConfigurations);
  package MyUCTL is new UCTL(Configurations);

  procedure Dump_States is
  begin
    MyUCTL.Doit;
  end Dump_States;
begin
  null;
end MC;
---
generic
package Configurations is
 procedure Doit;
end Configurations;
---
package body Configurations is
 procedure Doit is begin null; end;
begin
  null;
end Configurations;
---
with Configurations;
generic
with package MyConfigurations is new Configurations(<>);
package UCTL is
  procedure Doit;
end UCTL;
---
package body UCTL is
 procedure Doit is
 begin
   MyConfigurations.Doit;
 end;
end;

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-09-25  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch12.adb (Analyze_Associations, case N_Formal_Package): If the
	actual is a renaming, indicate that it is the renamed package that must
	be frozen before the instantiation.

-------------- next part --------------
Index: sem_ch12.adb
===================================================================
--- sem_ch12.adb	(revision 253135)
+++ sem_ch12.adb	(working copy)
@@ -1980,8 +1980,22 @@
 
                            if Needs_Freezing then
                               Check_Generic_Parent;
-                              Set_Has_Delayed_Freeze (Actual);
-                              Append_Elmt (Actual, Actuals_To_Freeze);
+
+                              --  If the actual is a renaming of a proper
+                              --  instance of the formal package, indicate
+                              --  that it is the instance that must be frozen.
+
+                              if Nkind (Parent (Actual)) =
+                                N_Package_Renaming_Declaration
+                              then
+                                 Set_Has_Delayed_Freeze
+                                   (Renamed_Entity (Actual));
+                                 Append_Elmt
+                                  (Renamed_Entity (Actual), Actuals_To_Freeze);
+                              else
+                                 Set_Has_Delayed_Freeze (Actual);
+                                 Append_Elmt (Actual, Actuals_To_Freeze);
+                              end if;
                            end if;
                         end if;
                      end Explicit_Freeze_Check;


More information about the Gcc-patches mailing list