https://gcc.gnu.org/g:7f8fb37914c36d9c6048065cc1e71def5edef46e

commit r17-4579-g7f8fb37914c36d9c6048065cc1e71def5edef46e
Author: Eric Botcazou <[email protected]>
Date:   Tue Sep 22 21:22:27 2026 +0200

    Ada: Do not apply static accessibility checks to synthesized return
    
    This adds the same early return to Check_Return_Construct_Accessibility for
    static checks as the one present in Apply_Accessibility_Check_For_Return for
    dynamic checks.
    
    gcc/ada/
            * accessibility.adb (Check_Return_Construct_Accessibility): Bail
            out for the return synthesized in a function whose body has been
            wrapped in a  nested _Wrapped_Statements function.

Diff:
---
 gcc/ada/accessibility.adb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/accessibility.adb b/gcc/ada/accessibility.adb
index f7104930e72d..42092bebbf92 100644
--- a/gcc/ada/accessibility.adb
+++ b/gcc/ada/accessibility.adb
@@ -2137,11 +2137,14 @@ package body Accessibility is
                                           | N_Simple_Return_Statement);
 
       --  Only perform checks on record types with access discriminants and
-      --  functions present in the source.
+      --  functions present in the source, but no checks are needed for the
+      --  return synthesized in a function whose body has been wrapped in a
+      --  nested _Wrapped_Statements function.
 
       if not Is_Record_Type (R_Type)
         or else not Has_Anonymous_Access_Discriminant (R_Type)
         or else not Comes_From_Source (Scope_Id)
+        or else Present (Wrapped_Statements (Scope_Id))
       then
          return;
       end if;

Reply via email to