https://gcc.gnu.org/g:b776b08b718feb059fed80b1de6bcf280fd6f03c
commit r15-3398-gb776b08b718feb059fed80b1de6bcf280fd6f03c Author: Bob Duff <d...@adacore.com> Date: Thu Aug 22 12:32:00 2024 -0400 ada: Fix Finalize_Storage_Only bug in b-i-p calls Do not pass null for the Collection parameter when Finalize_Storage_Only is in effect. If the collection is null in that case, we will blow up later when we deallocate the object. gcc/ada/ * exp_ch6.adb (Add_Collection_Actual_To_Build_In_Place_Call): Remove Finalize_Storage_Only from the code that checks whether to pass null to the Collection parameter. Having done that, we don't need to check for Is_Library_Level_Entity, because No_Heap_Finalization requires that. And if we ever change No_Heap_Finalization to allow nested access types, we will still want to pass null. Note that the comment "Such a type lacks a collection." is incorrect in the case of Finalize_Storage_Only; such types have a collection. Diff: --- gcc/ada/exp_ch6.adb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 3c87c0e8220c..c868234655ea 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -517,15 +517,11 @@ package body Exp_Ch6 is else Desig_Typ := Directly_Designated_Type (Ptr_Typ); - -- Check for a library-level access type whose designated type has - -- suppressed finalization or the access type is subject to pragma - -- No_Heap_Finalization. Such an access type lacks a collection. Pass - -- a null actual to callee in order to signal a missing collection. - - if Is_Library_Level_Entity (Ptr_Typ) - and then (Finalize_Storage_Only (Desig_Typ) - or else No_Heap_Finalization (Ptr_Typ)) - then + -- Check for a type that is subject to pragma No_Heap_Finalization. + -- Such a type lacks a collection. Pass a null actual to callee to + -- signal a missing collection. + + if No_Heap_Finalization (Ptr_Typ) then Actual := Make_Null (Loc); -- Types in need of finalization actions