From: Eric Botcazou <[email protected]>

It occurs during the analysis of a generic package declared in a structural
instance of a parent generic package, on accessing the uninitialized entity
of the current semantic unit.  But this access is unnecessary because what
happens within an instance does not affect the current semantic unit here.

The change also adds the missing call to Unit_Requires_Body already present
in the generic subprogram case to the generic package case.

gcc/ada/ChangeLog:

        * sem_ch12.adb (Analyze_Generic_Package_Declaration): Do not set the
        Body_Needed_For_Inlining flag on the current semantic unit if the
        package is declared within an instance or does not require a body.
        (Analyze_Generic_Subprogram_Declaration): Similarly, do not set the
        Body_Needed_For_Inlining flag on the current semantic unit if the
        subprogram is declared within an instance.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch12.adb | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 1ebda12cde2..79d5e6f0aed 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -4605,10 +4605,13 @@ package body Sem_Ch12 is
       End_Package_Scope (Id);
       Exit_Generic_Scope (Id);
 
-      --  If the generic appears within a package unit, the body of that unit
-      --  has to be present for instantiation and inlining.
+      --  If the generic appears directly within a package unit and requires a
+      --  body, the package body of that unit has to be present for inlining.
 
-      if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration then
+      if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
+        and then not In_Instance
+        and then Unit_Requires_Body (Id)
+      then
          Set_Body_Needed_For_Inlining
            (Defining_Entity (Unit (Cunit (Current_Sem_Unit))));
       end if;
@@ -4806,10 +4809,11 @@ package body Sem_Ch12 is
          Set_Body_Required (Parent (N), Unit_Requires_Body (Id));
       end if;
 
-      --  If the generic appears within a package unit, the body of that unit
-      --  has to be present for instantiation and inlining.
+      --  If the generic appears directly within a package unit and requires a
+      --  body, the package body of that unit has to be present for inlining.
 
       if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
+        and then not In_Instance
         and then Unit_Requires_Body (Id)
       then
          Set_Body_Needed_For_Inlining
-- 
2.53.0

Reply via email to