https://gcc.gnu.org/g:8ac7ca238c42d8c28905ecabaa3217b1bcaf72c2
commit r17-886-g8ac7ca238c42d8c28905ecabaa3217b1bcaf72c2 Author: Eric Botcazou <[email protected]> Date: Fri Mar 6 14:30:23 2026 +0100 ada: Fix assertion failure on invalid String_Literal aspect The root cause is that a subprogram declared in the body is incorrectly considered as a primitive operation of a type declared in a package spec. gcc/ada/ChangeLog: * einfo.ads (In_Package_Body): Update description. (In_Private_Part): Likewise. * sem_ch3.adb (Analyze_Object_Declaration): Compute In_Package_Body along with In_Private_Part for the object if its scope is a package. * sem_ch6.adb (Analyze_Expression_Function): Do not compute In_Private_Part here. (Enter_Overloaded_Entity): Compute In_Package_Body & In_Private_Part for the entity if its scope is a package. * sem_util.adb (Collect_Primitive_Operations): Skip the subprograms declared in the body for types declared in a package specification. Diff: --- gcc/ada/einfo.ads | 21 ++++++++++++--------- gcc/ada/sem_ch3.adb | 9 ++++----- gcc/ada/sem_ch6.adb | 11 ++++++++--- gcc/ada/sem_util.adb | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index b1ec7f885e73..85fca2c2b2cc 100644 --- a/gcc/ada/einfo.ads +++ b/gcc/ada/einfo.ads @@ -2294,17 +2294,20 @@ package Einfo is -- to multiple subprogram entities). -- In_Package_Body --- Defined in package entities. Set on the entity that denotes the --- package (the defining occurrence of the package declaration) while --- analyzing and expanding the package body. Reset on completion of --- analysis/expansion. +-- Defined in all entities. Can be set only in package entities, objects +-- and overloadable entities. For package entities, this flag is set to +-- indicate that the body of the package is being analyzed. The flag is +-- reset at the end of the package body. For objects and overloadable +-- entities, indicates that the declaration of the entity occurs in the +-- body of a package. -- In_Private_Part --- Defined in all entities. Can be set only in package entities and --- objects. For package entities, this flag is set to indicate that the --- private part of the package is being analyzed. The flag is reset at --- the end of the package declaration. For objects it indicates that the --- declaration of the object occurs in the private part of a package. +-- Defined in all entities. Can be set only in package entities, objects +-- and overloadable entities. For package entities, this flag is set to +-- indicate that the private part of the package is being analyzed. The +-- flag is reset at the end of the package declaration. For objects and +-- overloadable entities, indicates that the declaration of the entity +-- occurs in the private part of a package. -- Incomplete_Actuals -- Defined on package entities that are instances. Indicates the actuals diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index db71829d7f44..710d09a4192c 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -5473,12 +5473,11 @@ package body Sem_Ch3 is Check_Eliminated (Id); - -- Deal with setting In_Private_Part flag if in private part + -- Deal with setting In_Package_Body and In_Private_Part flags - if Ekind (Scope (Id)) = E_Package - and then In_Private_Part (Scope (Id)) - then - Set_In_Private_Part (Id); + if Ekind (Scope (Id)) = E_Package then + Set_In_Package_Body (Id, In_Package_Body (Scope (Id))); + Set_In_Private_Part (Id, In_Private_Part (Scope (Id))); end if; <<Leave>> diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index 18a77b980be2..dc9dd449ab8a 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -535,8 +535,6 @@ package body Sem_Ch6 is Def_Id := Defining_Entity (N); Set_Is_Inlined (Def_Id); - Set_In_Private_Part (Def_Id, In_Private_Part (Scope (Def_Id))); - Typ := Etype (Def_Id); -- Propagate the results of the resolution of the specification of @@ -9723,7 +9721,14 @@ package body Sem_Ch6 is if Is_Inherited_Operation (S) then Append_Inherited_Subprogram (S); else - Append_Entity (S, Current_Scope); + Append_Entity (S, Scope (S)); + end if; + + -- Deal with setting In_Package_Body and In_Private_Part flags + + if Ekind (Scope (S)) = E_Package then + Set_In_Package_Body (S, In_Package_Body (Scope (S))); + Set_In_Private_Part (S, In_Private_Part (Scope (S))); end if; Set_Public_Status (S); diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 486c31ee1710..6d1647f96cd6 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -5892,7 +5892,7 @@ package body Sem_Util is -- predefined "=" operator. if Is_Overloadable (Id) - and then (Is_Type_In_Pkg + and then ((Is_Type_In_Pkg and then not In_Package_Body (Id)) or else Is_Primitive (Id) or else not Comes_From_Source (Id))
