]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix internal error on protected entry and private record
authorEric Botcazou <ebotcazou@adacore.com>
Sun, 2 Nov 2025 16:11:19 +0000 (17:11 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 13 Nov 2025 15:36:10 +0000 (16:36 +0100)
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

index a9eac808af6f9a98135925b0b03e7932a5c1a103..4c63ec978ff05d06463f1b401321c1c90ff5105b 100644 (file)
@@ -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;