This occurs when the pragma is in a configuration file.  The problem is that 
Find_Direct_Name manually walks the scope stack while it is still empty.

Tested on x86-64/Linux, applied on the mainline, 16, 15 and 14 branches.


2026-10-07  Eric Botcazou  <[email protected]>

        PR ada/126125
        * sem_ch8.adb (Find_Direct_Name): Add missing guard to the manual
        walk of the scope stack used to cope with the Rtsfind mechanism.

-- 
Eric Botcazou
diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index 661aa6beef3..96bdc286993 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -6485,6 +6477,7 @@ package body Sem_Ch8 is
 
          Level := Scope_Stack.Last;
          loop
+            exit when Level < 0;
             Scop := Scope_Stack.Table (Level).Entity;
             exit when Scop = Scope (E);
             Level := Level - 1;

Reply via email to