]> 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 07:48:22 +0000 (09:48 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Thu, 3 Jul 2025 09:41:37 +0000 (11:41 +0200)
Since the introduction of the Finalizable aspect, there can be types
for which Is_Controlled returns True but that don't have all three
finalization primitives. The Generate_Finalization_Actions raised an
exception in that case before this patch, which fixes the problem.

gcc/ada/ChangeLog:

* exp_aggr.adb (Generate_Finalization_Actions): Stop assuming that
initialize primitive exists.

gcc/ada/exp_aggr.adb

index b6c16052ee08b51752d7bca6afacb828dc375854..29db1cd2fb12671a3d4985ed6289db886358afc3 100644 (file)
@@ -2490,12 +2490,21 @@ package body Exp_Aggr is
             Ref := Convert_To (Init_Typ, New_Copy_Tree (Target));
             Set_Assignment_OK (Ref);
 
-            Append_To (L,
-              Make_Procedure_Call_Statement (Loc,
-                Name                   =>
-                  New_Occurrence_Of
-                    (Find_Controlled_Prim_Op (Init_Typ, Name_Initialize), Loc),
-                Parameter_Associations => New_List (New_Copy_Tree (Ref))));
+            declare
+               Intlz : constant Entity_Id :=
+                 Find_Controlled_Prim_Op (Init_Typ, Name_Initialize);
+            begin
+               if Present (Intlz) then
+                  Append_To
+                    (L,
+                     Make_Procedure_Call_Statement
+                       (Loc,
+                        Name                   =>
+                          New_Occurrence_Of (Intlz, Loc),
+                        Parameter_Associations =>
+                          New_List (New_Copy_Tree (Ref))));
+               end if;
+            end;
          end if;
       end Generate_Finalization_Actions;