[COMMITTED,23/27] ada: Avoid ghost context errors when preanalyzing Loop_Invariant

Message ID 20250915130135.2720894-23-poulhies@adacore.com
State Committed
Commit e8de28890655d7766bea5263afcf9889393ea000
Headers
Series [COMMITTED,01/27] ada: Fix documentation of Is_Ancestor_Package |

Commit Message

Marc Poulhiès Sept. 15, 2025, 1:01 p.m. UTC
  From: Viljar Indus <indus@adacore.com>

gcc/ada/ChangeLog:

	* sem_prag.adb (Analyze_Pragma): Disable context checks for
	the preanalysis of the expression for Loop_Invariant pragmas
	as the ghost region for the pragma has not been set up yet.

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

---
 gcc/ada/sem_prag.adb | 6 ++++++
 1 file changed, 6 insertions(+)
  

Patch

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index b1fefa8a2972..f75f1f7eb4d1 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -14455,9 +14455,15 @@  package body Sem_Prag is
 
                --  Perform preanalysis to deal with embedded Loop_Entry
                --  attributes.
+               --
+               --  But ignore the ghost context checks for now. The expression
+               --  will be reanalyzed with the correct ghost region once the
+               --  pragma has been converted to pragma check.
 
+               Ghost_Context_Checks_Disabled := True;
                Preanalyze_And_Resolve_Assert_Expression
                   (Arg_Check, Any_Boolean);
+               Ghost_Context_Checks_Disabled := False;
             end if;
 
             --  Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating