https://gcc.gnu.org/g:dcaabdd2daa7fefd24985cc3de5b0752c920df69

commit r16-3869-gdcaabdd2daa7fefd24985cc3de5b0752c920df69
Author: Viljar Indus <[email protected]>
Date:   Thu Aug 28 13:18:39 2025 +0300

    ada: Avoid ghost context check in early freeze
    
    We freeze the expression for expression functions that complete
    before we have set up the ghost region from both the existing spec
    and body. Avoid triggering the ghost context checks during the
    analysis for this early freeze as the expression will be reanalyzed
    when we analyze the new function body created for the expression
    function.
    
    gcc/ada/ChangeLog:
    
            * sem_ch6.adb (Analyze_Expression_Function): Disable ghost
            checks during the early freeze.

Diff:
---
 gcc/ada/sem_ch6.adb | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index 9042b3378ce7..4e5ede6b429e 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -436,11 +436,20 @@ package body Sem_Ch6 is
 
             Set_Parent (New_Body, Parent (N));
 
+            --  Disable Ghost checks for this early analysis on the expression.
+            --  We have not analyzed the new body of the expression function
+            --  yet so the ghost region is not set up properly for the ghost
+            --  context checks yet. Avoid the checks for now as the expression
+            --  will be re-analyzed when the expression function is replaced
+            --  with the function body.
+
+            Ghost_Context_Checks_Disabled := True;
             Freeze_Expr_Types
               (Def_Id => Def_Id,
                Typ    => Typ,
                Expr   => Expr,
                N      => N);
+            Ghost_Context_Checks_Disabled := False;
          end if;
 
          --  For navigation purposes, indicate that the function is a body

Reply via email to