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

commit r17-4598-gd470d6b931344eb972cf653932a7c4df3b937421
Author: Eric Botcazou <[email protected]>
Date:   Wed Sep 23 11:08:57 2026 +0200

    Ada: Fix infinite recursion on broken subunit with -gnatc
    
    This just adds a cut-off for broken subunits.
    
    gcc/ada/
            * sem_elab.adb (Invocation_Graph.Process_Package_Declaration): Add
            cut-off for broken subunits.

Diff:
---
 gcc/ada/sem_elab.adb | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/sem_elab.adb b/gcc/ada/sem_elab.adb
index fefb01029d39..06b7be53f057 100644
--- a/gcc/ada/sem_elab.adb
+++ b/gcc/ada/sem_elab.adb
@@ -12777,9 +12777,24 @@ package body Sem_Elab is
             if Present (Body_Id)
               and then Save_Invocation_Graph_Of_Body (Cunit (Main_Unit))
             then
-               Process_Declarations
-                 (Decls    => Declarations (Unit_Declaration_Node (Body_Id)),
-                  In_State => In_State);
+               declare
+                  Decl : constant Node_Id := Declaration_Node (Body_Id);
+
+               begin
+                  --  Prevent infinite recursion for broken subunit
+
+                  if Nkind (Decl) = N_Package_Body_Stub
+                    and then No (Stub_Subunit (Decl))
+                  then
+                     null;
+
+                  else
+                     Process_Declarations
+                       (Decls    =>
+                          Declarations (Unit_Declaration_Node (Body_Id)),
+                        In_State => In_State);
+                  end if;
+               end;
             end if;
          end if;
       end Process_Package_Declaration;

Reply via email to