https://gcc.gnu.org/g:f44fdf332d94779375395d9ac6cc9850882dddf1
commit r17-858-gf44fdf332d94779375395d9ac6cc9850882dddf1 Author: Ronan Desplanques <[email protected]> Date: Wed Feb 18 17:37:27 2026 +0100 ada: Clean up around Is_Immutably_Limited_Type This improves the documentation comments of Is_Immutably_Limited_Type and Is_Inherently_Limited_Type and rewrites the body of Is_Inherently_Limited_Type to leverage Is_Immutably_Limited_Type. gcc/ada/ChangeLog: * sem_aux.ads (Is_Immutably_Limited_Type, Is_Inherently_Limited_Type): Improve documentation comments. * sem_aux.adb (Is_Inherently_Limited_Type): Replace inline code with call to Is_Immutably_Limited_Type. Diff: --- gcc/ada/sem_aux.adb | 55 +++++++++++++---------------------------------------- gcc/ada/sem_aux.ads | 28 +++++++++++++++------------ 2 files changed, 29 insertions(+), 54 deletions(-) diff --git a/gcc/ada/sem_aux.adb b/gcc/ada/sem_aux.adb index 648ceee816f9..c39e50a596b9 100644 --- a/gcc/ada/sem_aux.adb +++ b/gcc/ada/sem_aux.adb @@ -1157,51 +1157,23 @@ package body Sem_Aux is Btype : constant Entity_Id := Available_View (Base_Type (Ent)); begin - if Is_Limited_Record (Btype) then + if Is_Immutably_Limited_Type (Ent) then return True; + end if; - elsif Ekind (Btype) = E_Limited_Private_Type - and then Nkind (Parent (Btype)) = N_Formal_Type_Declaration - then - return not In_Package_Body (Scope ((Btype))); - - elsif Is_Private_Type (Btype) then - - -- AI05-0063: A type derived from a limited private formal type is - -- not immutably limited in a generic body. - - if Is_Derived_Type (Btype) - and then Is_Generic_Type (Etype (Btype)) - then - if not Is_Limited_Type (Etype (Btype)) then + if Is_Private_Type (Btype) then + declare + Utyp : constant Entity_Id := Underlying_Type (Btype); + begin + if No (Utyp) then return False; - - -- A descendant of a limited formal type is not immutably limited - -- in the generic body, or in the body of a generic child. - - elsif Ekind (Scope (Etype (Btype))) = E_Generic_Package then - return not In_Package_Body (Scope (Btype)); - else - return False; + return Is_Inherently_Limited_Type (Utyp); end if; + end; + end if; - else - declare - Utyp : constant Entity_Id := Underlying_Type (Btype); - begin - if No (Utyp) then - return False; - else - return Is_Inherently_Limited_Type (Utyp); - end if; - end; - end if; - - elsif Is_Concurrent_Type (Btype) then - return True; - - elsif Is_Record_Type (Btype) then + if Is_Record_Type (Btype) then -- Note that we return True for all limited interfaces, even though -- (unsynchronized) limited interfaces can have descendants that are @@ -1242,10 +1214,9 @@ package body Sem_Aux is elsif Is_Array_Type (Btype) then return Is_Inherently_Limited_Type (Component_Type (Btype)); - - else - return False; end if; + + return False; end Is_Inherently_Limited_Type; ---------------------- diff --git a/gcc/ada/sem_aux.ads b/gcc/ada/sem_aux.ads index fb59ef405b1d..cf80ec793ba5 100644 --- a/gcc/ada/sem_aux.ads +++ b/gcc/ada/sem_aux.ads @@ -314,20 +314,24 @@ package Sem_Aux is -- should be cleaned up??? function Is_Immutably_Limited_Type (Ent : Entity_Id) return Boolean; - -- Implements definition in Ada 2012 RM-7.5 (8.1/3). This differs from the - -- following predicate in that an untagged record with immutably limited - -- components is NOT by itself immutably limited. This matters, e.g. when - -- checking the legality of an access to the current instance. + -- Ent is any entity. True if and only if Ent is a type that's immutably + -- limited as defined by RM 7.5 (8.1/3). function Is_Inherently_Limited_Type (Ent : Entity_Id) return Boolean; - -- Ent is any entity. True for a type that is "inherently" limited (i.e. - -- cannot become nonlimited). From the Ada 2005 RM-7.5(8.1/2), "a type with - -- a part that is of a task, protected, or explicitly limited record type". - -- These are the types that are defined as return-by-reference types in Ada - -- 95 (see RM95-6.5(11-16)). In Ada 2005, these are the types that require - -- build-in-place for function calls. Note that build-in-place is allowed - -- for other types, too. This is also used for identifying pure procedures - -- whose calls should not be eliminated (RM 10.2.1(18/2)). + -- Ent is any entity. True if and only if Ent is a type such that objects + -- of type Ent must be built in place because of RM 7.6 (17.2/3). + -- + -- Note that Is_Immutably_Limited_Type => Is_Inherently_Limited_Type holds, + -- but the reverse implication doesn't. For example with + -- + -- type T1 is limited null record; + -- + -- type T2 is record + -- C : T1; + -- end record; + -- + -- Is_Inherently_Limited_Type (T2) = True and + -- Is_Immutably_Limited_Type (T2) = False. function Nearest_Ancestor (Typ : Entity_Id) return Entity_Id; -- Given a subtype Typ, this function finds out the nearest ancestor from
