https://gcc.gnu.org/g:c8cf35fe67f80f829d924e10b1fd2bb2390c3684
commit r16-9137-gc8cf35fe67f80f829d924e10b1fd2bb2390c3684 Author: Eric Botcazou <[email protected]> Date: Sat May 30 21:11:44 2026 +0200 ada: Fix assertion failure on access to uninitialized package entity 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. Diff: --- 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 acbb47f29381..8b406f00a727 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -4584,10 +4584,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; @@ -4783,10 +4786,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
