]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix crash with Finalizable in corner case
authorRonan Desplanques <desplanques@adacore.com>
Thu, 5 Jun 2025 10:03:46 +0000 (12:03 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 3 Jul 2025 08:16:24 +0000 (10:16 +0200)
The Finalizable aspect introduced controlled types for which not all the
finalization primitives exist. This patch makes Make_Deep_Record_Body
handle this case correctly.

gcc/ada/ChangeLog:

* exp_ch7.adb (Make_Deep_Record_Body): Fix case of absent Initialize
primitive.

gcc/ada/exp_ch7.adb

index 95a790e5cee890684d113ffd7a9fd72797e641cf..e4daf4bc7a3aa5bca85095263ed880fb2c4ddcb8 100644 (file)
@@ -7830,13 +7830,23 @@ package body Exp_Ch7 is
 
          when Initialize_Case =>
             if Is_Controlled (Typ) then
-               return New_List (
-                 Make_Procedure_Call_Statement (Loc,
-                   Name                   =>
-                     New_Occurrence_Of
-                       (Find_Controlled_Prim_Op (Typ, Name_Initialize), Loc),
-                   Parameter_Associations => New_List (
-                     Make_Identifier (Loc, Name_V))));
+               declare
+                  Intlz : constant Entity_Id :=
+                    Find_Controlled_Prim_Op (Typ, Name_Initialize);
+               begin
+                  if Present (Intlz) then
+                     return
+                       New_List
+                         (Make_Procedure_Call_Statement
+                            (Loc,
+                             Name                   =>
+                               New_Occurrence_Of (Intlz, Loc),
+                             Parameter_Associations =>
+                               New_List (Make_Identifier (Loc, Name_V))));
+                  else
+                     return Empty_List;
+                  end if;
+               end;
             else
                return Empty_List;
             end if;