From: Eric Botcazou <ebotca...@adacore.com> Get_Actual_Subtype can be used to access the Actual_Designated_Subtype of explicit dereferences with a storage model. As a side effect, this also handles the case where the prefix of the dereference is a formal parameter.
gcc/ada/ * exp_ch6.adb (Add_Simple_Call_By_Copy_Code): Use Get_Actual_Subtype to retrieve the actual subtype for all actuals and do it in only one place for all unconstrained composite formal types. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch6.adb | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index fce10d5e946..b2408140bef 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -1969,21 +1969,12 @@ package body Exp_Ch6 is F_Typ := Non_Limited_View (F_Typ); end if; - -- Use the actual designated subtype for a dereference, if any - - if Nkind (Actual) = N_Explicit_Dereference - and then Present (Actual_Designated_Subtype (Actual)) - then - Indic := - New_Occurrence_Of (Actual_Designated_Subtype (Actual), Loc); - -- Use formal type for temp, unless formal type is an unconstrained - -- array, in which case we don't have to worry about bounds checks, - -- and we use the actual type, since that has appropriate bounds. - - elsif Is_Array_Type (F_Typ) and then not Is_Constrained (F_Typ) then - Indic := New_Occurrence_Of (Etype (Actual), Loc); + -- composite, in which case we don't have to worry about checks and + -- we can use the actual type, since that has appropriate bounds. + if Is_Composite_Type (F_Typ) and then not Is_Constrained (F_Typ) then + Indic := New_Occurrence_Of (Get_Actual_Subtype (Actual), Loc); else Indic := New_Occurrence_Of (F_Typ, Loc); end if; @@ -1999,21 +1990,9 @@ package body Exp_Ch6 is -- with the input parameter unless we have an OUT formal or -- this is an initialization call. - -- If the formal is an out parameter with discriminants, the - -- discriminants must be captured even if the rest of the object - -- is in principle uninitialized, because the discriminants may - -- be read by the called subprogram. - if Ekind (Formal) = E_Out_Parameter then Incod := Empty; - if Has_Discriminants (F_Typ) - and then (Nkind (Actual) /= N_Explicit_Dereference - or else No (Actual_Designated_Subtype (Actual))) - then - Indic := New_Occurrence_Of (Etype (Actual), Loc); - end if; - elsif Inside_Init_Proc then -- Skip using the actual as the expression in Decl if we are in -- 2.40.0