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

commit r17-5776-gccb3f88ea36442c64de0f9717165ab468313c3db
Author: Eric Botcazou <[email protected]>
Date:   Sat Oct 31 17:14:04 2026 +0100

    Ada: Fix compiler hang on structural generic instantiation
    
    This happens when the first reference to the structural instance is made
    within an expression function, because the implicit instantiation is not
    performed in an appropriate state by the semantic analyzer.
    
    gcc/ada/
            * sem_ch12.adb (Analyze_Structural_Associations): Even in the local
            case, make sure that the implicit instantiation is performed in an
            appropriate state by the semantic analyzer.

Diff:
---
 gcc/ada/sem_ch12.adb | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 35aa7c72018a..58e117a91ab4 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -6517,8 +6517,28 @@ package body Sem_Ch12 is
                   Inside_A_Generic := S_Inside_A_Generic;
                end;
 
+            --  If the scope is local, the instantiation must be fully analyzed
+            --  as well as expanded if the context is not a generic unit.
+
             else
-               Add_Local_Declaration (R, N, Scop => Scop);
+               declare
+                  S_Expander_Active : constant Boolean := Expander_Active;
+                  S_Full_Analysis   : constant Boolean := Full_Analysis;
+                  S_In_Spec_Expr    : constant Boolean := In_Spec_Expression;
+
+               begin
+                  Expander_Active :=
+                    Operating_Mode = Opt.Generate_Code
+                      and then not Inside_A_Generic;
+                  Full_Analysis := True;
+                  In_Spec_Expression := False;
+
+                  Add_Local_Declaration (R, N, Scop => Scop);
+
+                  Expander_Active := S_Expander_Active;
+                  Full_Analysis := S_Full_Analysis;
+                  In_Spec_Expression := S_In_Spec_Expr;
+               end;
             end if;
 
             Ent := Defining_Entity_Of_Instance (R);

Reply via email to