[Ada] Passing actual parameter values to out formals when Default_Value is set
authorGary Dismukes <dismukes@adacore.com>
Tue, 31 Mar 2020 22:27:06 +0000 (18:27 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 15 Jun 2020 08:04:32 +0000 (04:04 -0400)
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.

gcc/ada/exp_ch6.adb

index e7d2ccc..b2b81ee 100644 (file)
@@ -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;