]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix assertion failure on access to uninitialized package entity
authorEric Botcazou <ebotcazou@adacore.com>
Sat, 30 May 2026 19:11:44 +0000 (21:11 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 18 Jun 2026 08:03:42 +0000 (10:03 +0200)
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.

gcc/ada/sem_ch12.adb

index 1ebda12cde28e4e5e8e0985e6e5fdeadd91d9c45..79d5e6f0aed70551d138dd538ba49d56fec536dd 100644 (file)
@@ -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