From 14af70d6573102798316915f9b4a65b39e2c9ccb Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Sun, 2 Nov 2025 17:11:19 +0100 Subject: [PATCH] ada: Fix internal error on protected entry and private record This is a freezing issue introduced by the new support for deferred extra formals. The freezing of local types created during the expansion of the entry construct happens in the wrong scope when the expansion is deferred, causing reference-before-freezing in the expanded code. gcc/ada/ChangeLog: * exp_ch9.adb (Expand_N_Entry_Declaration): In the deferred case, freeze immediately all the newly created entities. --- gcc/ada/exp_ch9.adb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb index a9eac808af6..4c63ec978ff 100644 --- a/gcc/ada/exp_ch9.adb +++ b/gcc/ada/exp_ch9.adb @@ -8212,15 +8212,27 @@ package body Exp_Ch9 is -- as part of the regular flow of the front end at the end of -- analysis of the enclosing task/protected type declaration. + -- Freeze immediately all the newly created entities, because + -- otherwise they might be frozen in the wrong scope (in the + -- non-deferred case, they are frozen when the enclosing task/ + -- protected type is frozen, but they didn't exist by that time). + if Was_Deferred then - Push_Scope (Scope (Entry_Ent)); + declare + From : constant Entity_Id := Last_Entity (Scope (Entry_Ent)); - while First_Decl /= Last_Decl loop - Next (First_Decl); - Analyze (First_Decl); - end loop; + begin + Push_Scope (Scope (Entry_Ent)); - End_Scope; + while First_Decl /= Last_Decl loop + Next (First_Decl); + Analyze (First_Decl); + end loop; + + Freeze_All (From, Last_Decl); + + End_Scope; + end; end if; end if; end Expand_N_Entry_Declaration; -- 2.47.3