]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix crash on nested access-to-subprogram types
authorRonan Desplanques <desplanques@adacore.com>
Fri, 18 Apr 2025 14:45:10 +0000 (16:45 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Mon, 30 Jun 2025 17:14:15 +0000 (19:14 +0200)
This patch fixes a crash on some subprograms with anonymous
access-to-subprogram parameters by removing delayed freezing of
subprograms in some cases where it wasn't necessary. The -gnatD output
for itypes is also improved.

gcc/ada/ChangeLog:

* sem_ch6.adb (Check_Delayed_Subprogram, Possible_Freeze): Restrict
cases where freezing is delayed.
* sem_ch6.ads (Check_Delayed_Subprogram): Improve documentation
comment.
* sprint.adb (Write_Itype): Improve output.

gcc/ada/sem_ch6.adb
gcc/ada/sem_ch6.ads
gcc/ada/sprint.adb

index 05bbeeddae413ad1867408bee559c5ce931a1c5a..aed983f7a3118ba97aec9911e373861a32c4d5e6 100644 (file)
@@ -6319,12 +6319,6 @@ package body Sem_Ch6 is
 
          elsif Has_Delayed_Freeze (T) and then not Is_Frozen (T) then
             Set_Has_Delayed_Freeze (Designator);
-
-         elsif Is_Access_Type (T)
-           and then Has_Delayed_Freeze (Designated_Type (T))
-           and then not Is_Frozen (Designated_Type (T))
-         then
-            Set_Has_Delayed_Freeze (Designator);
          end if;
       end Possible_Freeze;
 
@@ -6351,6 +6345,13 @@ package body Sem_Ch6 is
          Next_Formal (F);
       end loop;
 
+      --  RM 13.14 (15.1/6): the primitive subprograms of a tagged type are
+      --  frozen at the place where the type is frozen.
+
+      if Is_Dispatching_Operation (Designator) then
+         Set_Has_Delayed_Freeze (Designator);
+      end if;
+
       --  Mark functions that return by reference. Note that it cannot be done
       --  for delayed_freeze subprograms because the underlying returned type
       --  may not be known yet (for private types).
index bd4b730dc60701128c4a58bb64f5c7bdf612e2a2..ee9b2ef2d759b50ab55deaf05b0ebfe229bde9a9 100644 (file)
@@ -64,9 +64,8 @@ package Sem_Ch6 is
    --  respective counterparts.
 
    procedure Check_Delayed_Subprogram (Designator : Entity_Id);
-   --  Designator can be a E_Subprogram_Type, E_Procedure or E_Function. If a
-   --  type in its profile depends on a private type without a full
-   --  declaration, indicate that the subprogram or type is delayed.
+   --  Designator can be a E_Subprogram_Type, E_Procedure or E_Function. Set
+   --  Has_Delayed_Freeze on Designator if its freezing needs to be delayed.
 
    procedure Check_Discriminant_Conformance
      (N        : Node_Id;
index 938d2b23910abc5a0cebb86b10e6fd63dbf71dbc..6b74be14b40c168944c6b49f7e615c2d58b0c89c 100644 (file)
@@ -4634,7 +4634,7 @@ package body Sprint is
                            Param : Entity_Id;
 
                         begin
-                           Param := First_Entity (Typ);
+                           Param := First_Formal (Typ);
                            loop
                               Write_Id (Param);
                               Write_Str (" : ");
@@ -4646,7 +4646,7 @@ package body Sprint is
                               end if;
 
                               Write_Id (Etype (Param));
-                              Next_Entity (Param);
+                              Next_Formal (Param);
                               exit when No (Param);
                               Write_Str (", ");
                            end loop;