[COMMITTED,43/51] ada: Do not generate accessibility checks for specific synthesized return

Message ID 20260602084541.3829876-43-poulhies@adacore.com
State Committed
Headers
Series [COMMITTED,01/51] ada: Rename Private_Component function |

Commit Message

Marc Poulhiès June 2, 2026, 8:45 a.m. UTC
  From: Eric Botcazou <ebotcazou@adacore.com>

This is the return synthesized in a function whose body has been wrapped in
a nested _Wrapped_Statements function, since it only propagates the result.

gcc/ada/ChangeLog:

	* accessibility.adb (Apply_Accessibility_Check_For_Return): Bail out
	for the return synthesized in a function with _Wrapped_Statements.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/accessibility.adb | 7 +++++++
 1 file changed, 7 insertions(+)
  

Patch

diff --git a/gcc/ada/accessibility.adb b/gcc/ada/accessibility.adb
index 9b5d0fba73a..52d4810987f 100644
--- a/gcc/ada/accessibility.adb
+++ b/gcc/ada/accessibility.adb
@@ -1671,6 +1671,13 @@  package body Accessibility is
          return;
       end if;
 
+      --  No checks are needed for the return synthesized in a function whose
+      --  body has been wrapped in a nested _Wrapped_Statements function.
+
+      if Present (Wrapped_Statements (Func)) then
+         return;
+      end if;
+
       --  Ada 2005 (AI95-344): If the result type is class-wide, then insert
       --  a check that the level of the return expression's underlying type
       --  is not deeper than the level of the master enclosing the function.