diff options
author | Gary Dismukes <dismukes@adacore.com> | 2020-03-31 18:27:06 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-06-15 04:04:32 -0400 |
commit | c873714ff0cdefda09729bf04a7fc6c049d024f5 (patch) | |
tree | 8dba00f6f089d9bf0ebab4ea620e72dd8231b81d | |
parent | 773e99ac3e61bd84f9848e78e17867a920f9ae53 (diff) |
[Ada] Passing actual parameter values to out formals when Default_Value is set
2020-06-15 Gary Dismukes <dismukes@adacore.com>
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.
-rw-r--r-- | gcc/ada/exp_ch6.adb | 19 |
1 files changed, 19 insertions, 0 deletions
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; |