]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Set Is_Local_Anonymous_Access on the anonymous access type of return objects
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 18 May 2026 22:54:00 +0000 (00:54 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 4 Jun 2026 08:42:23 +0000 (10:42 +0200)
It is already set on the anonymous access type of function results and will
prevent return objects from being treated as Ada 2012's stand-alone objects,
thus make it easier to enforce the RM 3.10.2(13.2) rule.

gcc/ada/ChangeLog:

* einfo.ads (Is_Local_Anonymous_Access): Mention return objects.
* accessibility.adb (Type_Access_Level): Call Enclosing_Subprogram.
* sem_ch3.adb (Find_Type_Of_Object): Set Is_Local_Anonymous_Access
on the anonymous access type of return objects.

gcc/ada/accessibility.adb
gcc/ada/einfo.ads
gcc/ada/sem_ch3.adb

index 635b162a5d796ef5a386d1bb87beeefdbadf1b71..a1472fab91988e81d53b55694bf02390110f6dbe 100644 (file)
@@ -2708,25 +2708,13 @@ package body Accessibility is
                 (Is_Itype (Btyp)
                   and then Nkind (Associated_Node_For_Itype (Btyp)) =
                                                          N_Object_Declaration
-                  and then Is_Return_Object
-                             (Defining_Identifier
-                                (Associated_Node_For_Itype (Btyp))))
+                  and then
+                    Is_Return_Object
+                      (Defining_Identifier (Associated_Node_For_Itype (Btyp))))
             then
-               declare
-                  Scop : Entity_Id;
-
-               begin
-                  Scop := Scope (Scope (Btyp));
-                  while Present (Scop) loop
-                     exit when Ekind (Scop) = E_Function;
-                     Scop := Scope (Scop);
-                  end loop;
-
-                  --  Treat the return object's type as having the level of the
-                  --  function's result subtype (as per RM05-6.5(5.3/2)).
-
-                  return Type_Access_Level (Etype (Scop), Allow_Alt_Model);
-               end;
+               return
+                 Type_Access_Level
+                   (Etype (Enclosing_Subprogram (Btyp)), Allow_Alt_Model);
             end if;
          end if;
 
index e22762e90a46fa6492eac22a51a6efdd38ed99a5..abd7398562f3d0a4110be0d7b975c2baf0a6684f 100644 (file)
@@ -3073,11 +3073,12 @@ package Einfo is
 --    Is_Local_Anonymous_Access
 --       Defined in access types. Set for an anonymous access type to indicate
 --       that the type is created for an array or record component with access
---       definition, an access result, or (pre-Ada 2012) a standalone object.
---       Such anonymous types have an accessibility level equal to that of the
---       declaration in which they appear, unlike the anonymous access types
---       that are created for access parameters, access discriminants, and
---       (as of Ada 2012) stand-alone objects.
+--       definition, an access result, a return object, or (before Ada 2012) a
+--       stand-alone object. Such anonymous types have an accessibility level
+--       equal to that of the declaration in which they appear (or something
+--       equivalent), unlike the anonymous access types that are created for
+--       access parameters, access discriminants, and (in Ada 2012 and later
+--       versions of the language) stand-alone objects.
 
 --    Is_Loop_Parameter
 --       Applies to all entities. Certain loops, in particular "for ... of"
index 337c99c032483199370359748835ae82a339aa3d..ca9826ddf8d8fd8d90b76bd04c0b2da6a26cf96b 100644 (file)
@@ -19251,8 +19251,9 @@ package body Sem_Ch3 is
 
          Set_Is_Local_Anonymous_Access
            (T, Ada_Version < Ada_2012
-                   or else Nkind (P) /= N_Object_Declaration
-                   or else Is_Library_Level_Entity (Defining_Identifier (P)));
+                 or else Nkind (P) /= N_Object_Declaration
+                 or else Is_Return_Object (Defining_Identifier (P))
+                 or else Is_Library_Level_Entity (Defining_Identifier (P)));
 
       --  Otherwise, either the object definition is just a subtype_mark or we
       --  are analyzing a component declaration.