From: Gary Dismukes Date: Tue, 31 Mar 2020 22:27:06 +0000 (-0400) Subject: [Ada] Passing actual parameter values to out formals when Default_Value is set X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c873714ff0cdefda09729bf04a7fc6c049d024f5;p=gcc.git [Ada] Passing actual parameter values to out formals when Default_Value is set 2020-06-15 Gary Dismukes gcc/ada/ * exp_ch6.adb (Add_Call_By_Copy_Code): In the case of a view conversion passed to a scalar out-mode parameter where the formal has Default_Value set, declare the copy temp with the base type of the formal's subtype and initialize the copy temp with the actual's value. --- diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index e7d2cccda58..b2b81eee9a1 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -1446,6 +1446,25 @@ package body Exp_Ch6 is then Init := New_Occurrence_Of (Var, Loc); + -- View conversions when the formal type has the Default_Value aspect + -- require passing in the value of the conversion's operand. The type + -- of that operand also has Default_Value, as required by AI12-0074 + -- (RM 6.4.1(5.3/4)). The subtype denoted by the subtype_indication + -- is changed to the base type of the formal subtype, to ensure that + -- the actual's value can be assigned without a constraint check + -- (note that no check is done on passing to an out parameter). Also + -- note that the two types necessarily share the same ancestor type, + -- as required by 6.4.1(5.2/4), so underlying base types will match. + + elsif Ekind (Formal) = E_Out_Parameter + and then Is_Scalar_Type (Etype (F_Typ)) + and then Nkind (Actual) = N_Type_Conversion + and then Present (Default_Aspect_Value (Etype (F_Typ))) + then + Indic := New_Occurrence_Of (Base_Type (F_Typ), Loc); + Init := Convert_To + (Base_Type (F_Typ), New_Occurrence_Of (Var, Loc)); + else Init := Empty; end if;