]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix fallout of latest accessibility change with -gnata
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 19 Dec 2025 17:24:45 +0000 (18:24 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 9 Jan 2026 10:57:21 +0000 (11:57 +0100)
Compiling with assertion enabled may create _Wrapped_Statements functions
with access result, whose anonymous access result type is the same entity
as that of their parent function, which fools the accessibility logic.

gcc/ada/ChangeLog:

* accessibility.adb (Function_Call_Or_Allocator_Level): Adjust the
latest change to cope with _Wrapped_Statements functions.
* einfo.ads (Wrapped_Statements): Fix description.
* sem_util.adb (In_Return_Value): Fix typo in comment.

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

index 1e2dcbb475bfd20fbd3587f4c8378221e6cba52a..c3e69d45db5816bded08a2000c2c5cfcaee741be 100644 (file)
@@ -577,8 +577,17 @@ package body Accessibility is
             --  formal parameter in a return context and we return the library
             --  level to null them out there.
 
+            --  Note that we have to deal specifically with _Wrapped_Statements
+            --  functions of functions returning an access result, generated by
+            --  the expansion of contracts and postconditions, because they get
+            --  the same anonymous access result type as their parent function.
+
             if Is_Explicitly_Aliased (E)
-              and then Scope (E) = Current_Subprogram
+              and then (Scope (E) = Current_Subprogram
+                         or else (Has_Expanded_Contract (Scope (E))
+                                   and then
+                                     Wrapped_Statements (Scope (E)) =
+                                                           Current_Subprogram))
               and then (In_Return_Value (Expr) or else In_Return_Context)
             then
                return Make_Level_Literal (Scope_Depth (Standard_Standard));
index 357634a7ed51de94e02536dc8a15ed2d2a18abf2..63bfb7ca6da5525c84026290b6f86df61b7b36e2 100644 (file)
@@ -4860,7 +4860,7 @@ package Einfo is
 
 --    Wrapped_Statements
 --       Defined in functions, procedures, entries, and entry families. Refers
---       to the entity of the _Wrapped_Statements procedure, which gets
+--       to the entity of the _Wrapped_Statements subprogram, which gets
 --       generated as part of the expansion of contracts and postconditions
 --       and contains its enclosing subprogram's original source declarations
 --       and statements.
index c44af46ced5a61f161db1c4ed5c4f63c7870ee5e..bca32ffec11302b842b4fe32b5897c690e51b9e8 100644 (file)
@@ -14774,7 +14774,7 @@ package body Sem_Util is
    --  Start of processing for In_Return_Value
 
    begin
-      --  Move through parent nodes to determine if Expr contributes to the
+      --  Move through parent nodes to determine if Exp contributes to the
       --  return value of the current subprogram.
 
       Parent_Loop : while Present (P) loop