diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2024-01-21 00:29:45 +0100 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2024-05-13 10:03:28 +0200 |
commit | 8d6c7fccd04944804f7ca0f7ba7b4a3a7f1082dd (patch) | |
tree | 20cea0a60d5d967d4da48fd01636ea231b34ed26 /gcc/ada/exp_ch6.adb | |
parent | 8e76c189f10ee3b766cfde6b1ccb59b49342b0e5 (diff) | |
download | gcc-8d6c7fccd04944804f7ca0f7ba7b4a3a7f1082dd.zip gcc-8d6c7fccd04944804f7ca0f7ba7b4a3a7f1082dd.tar.gz gcc-8d6c7fccd04944804f7ca0f7ba7b4a3a7f1082dd.tar.bz2 |
ada: Restore fix for controlled dynamic allocation with BIP function call
The resolution made some time ago had been that a dynamic allocation for
a limited type that needs finalization with a function call as expression
always needs to be done in the called function, even if the limited type
has a known size. But the fix implementing this resolution was dropped
inadvertently at some point.
The change also contains a small tweak for Expand_N_Object_Declaration
and a small related cleanup in the finalization machinery.
gcc/ada/
* exp_ch3.adb (Expand_N_Object_Declaration): In the case of a
return object of a BIP function that needs finalization, save
the assignment statement made to initialize it, if any.
* exp_ch6.ads (BIP_Formal_Kind): Adjust description.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Make a
couple of adjustments to the commentary.
(Needs_BIP_Alloc_Form): Also return true if the function needs
a BIP_Finalization_Master parameter.
* exp_ch7.adb (Build_BIP_Cleanup_Stmts): Remove now always true
test on Needs_BIP_Alloc_Form.
(Attach_Object_To_Master_Node): Remove duplication in comment.
Diffstat (limited to 'gcc/ada/exp_ch6.adb')
-rw-r--r-- | gcc/ada/exp_ch6.adb | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index a89c9af..9e1844a 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -158,9 +158,9 @@ package body Exp_Ch6 is Alloc_Form : BIP_Allocation_Form := Unspecified; Alloc_Form_Exp : Node_Id := Empty; Pool_Actual : Node_Id := Make_Null (No_Location)); - -- Ada 2005 (AI-318-02): Add the actuals needed for a build-in-place - -- function call that returns a caller-unknown-size result (BIP_Alloc_Form - -- and BIP_Storage_Pool). If Alloc_Form_Exp is present, then use it, + -- Ada 2005 (AI-318-02): If the result type of a build-in-place call needs + -- them, add the actuals parameters BIP_Alloc_Form and BIP_Storage_Pool. + -- If Alloc_Form_Exp is present, then pass it for the first parameter, -- otherwise pass a literal corresponding to the Alloc_Form parameter -- (which must not be Unspecified in that case). Pool_Actual is the -- parameter to pass to BIP_Storage_Pool. @@ -8328,9 +8328,11 @@ package body Exp_Ch6 is Set_Can_Never_Be_Null (Acc_Type, False); -- It gets initialized to null, so we can't have that - -- When the result subtype is constrained, the return object is created - -- on the caller side, and access to it is passed to the function. This - -- optimization is disabled when the result subtype needs finalization + -- When the result subtype is returned on the secondary stack or is + -- tagged, the called function itself must perform the allocation of + -- the return object, so we pass parameters indicating that. + + -- But that's also the case when the result subtype needs finalization -- actions because the caller side allocation may result in undesirable -- finalization. Consider the following example: -- @@ -8351,11 +8353,6 @@ package body Exp_Ch6 is -- will be finalized when access type Lim_Ctrl_Ptr goes out of scope -- since it is already attached on the related finalization master. - -- Here and in related routines, we must examine the full view of the - -- type, because the view at the point of call may differ from the - -- one in the function body, and the expansion mechanism depends on - -- the characteristics of the full view. - if Needs_BIP_Alloc_Form (Function_Id) then Temp_Init := Empty; @@ -8386,6 +8383,10 @@ package body Exp_Ch6 is Return_Obj_Actual := Empty; + -- When the result subtype neither is returned on the secondary stack + -- nor is tagged, the return object is created on the caller side, and + -- access to it is passed to the function. + else -- Replace the initialized allocator of form "new T'(Func (...))" -- with an uninitialized allocator of form "new T", where T is the @@ -8428,11 +8429,6 @@ package body Exp_Ch6 is (Result_Subt, Make_Explicit_Dereference (Loc, Prefix => New_Occurrence_Of (Return_Obj_Access, Loc))); - - -- When the result subtype is unconstrained, the function itself must - -- perform the allocation of the return object, so we pass parameters - -- indicating that. - end if; -- Declare the temp object @@ -9636,6 +9632,12 @@ package body Exp_Ch6 is Typ : constant Entity_Id := Underlying_Type (Etype (Func_Id)); begin + -- See Make_Build_In_Place_Call_In_Allocator for the rationale + + if Needs_BIP_Finalization_Master (Func_Id) then + return True; + end if; + -- A formal giving the allocation method is needed for build-in-place -- functions whose result type is returned on the secondary stack or -- is a tagged type. Tagged primitive build-in-place functions need |