https://gcc.gnu.org/g:36b77268eec6e9791811b36b0d48c788ff696fb9

commit r15-9908-g36b77268eec6e9791811b36b0d48c788ff696fb9
Author: Ronan Desplanques <desplanq...@adacore.com>
Date:   Thu Jun 5 12:03:46 2025 +0200

    ada: Fix crash with Finalizable in corner case
    
    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.

Diff:
---
 gcc/ada/exp_ch7.adb | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index 381294b05d61..41438f40a888 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -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;

Reply via email to