From: Eric Botcazou Date: Sat, 30 May 2026 19:11:44 +0000 (+0200) Subject: ada: Fix assertion failure on access to uninitialized package entity X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60ea3af75ccf6356abac83aa9eecee5c672202d0;p=thirdparty%2Fgcc.git 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 --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