From: squirek <squi...@adacore.com>

The patch fixes an issue in the compiler whereby a spurious accessibility
error gets generated in semantic checking mode (-gnatc) when an explicitly
aliased formal gets used as an actual for an access disriminant in a return
object.

gcc/ada/ChangeLog:

        * accessibility.adb
        (Check_Return_Construct_Accessibility): Disable check generation
        when we are only checking semantics.

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

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

diff --git a/gcc/ada/accessibility.adb b/gcc/ada/accessibility.adb
index 8c85173aa34..200f892a96f 100644
--- a/gcc/ada/accessibility.adb
+++ b/gcc/ada/accessibility.adb
@@ -1642,6 +1642,13 @@ package body Accessibility is
              (No (Extra_Accessibility_Of_Result (Scope_Id))
                and then Is_Formal_Of_Current_Function (Assoc_Expr)
                and then Is_Tagged_Type (Etype (Scope_Id)))
+
+           --  Disable the check generation when we are only checking semantics
+           --  since required locals do not get generated (e.g. extra
+           --  accessibility of result), and constant folding can occur and
+           --  lead to spurious errors.
+
+           and then Operating_Mode /= Check_Semantics
          then
             --  Generate a dynamic check based on the extra accessibility of
             --  the result or the scope of the current function.
-- 
2.43.0

Reply via email to