From: Steve Baird <ba...@adacore.com> In the case of a call to a subprogram that has an out (or in-out) parameter that is passed by copy, the caller performs copy-back after the call returns. If the actual parameter is a view conversion to a subtype that has an enabled predicate, then the predicate check performed at that point should be performed before, not after, the operand of the view conversion is updated.
gcc/ada/ChangeLog: * exp_ch6.adb (Expand_Actuals): After building the tree for a predicate check, call Prepend_To instead of Append_To so that the check is performed before, instead of after, the corresponding parameter copy-back. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch6.adb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 18551d4899e3..1a9002ce3a8b 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -2946,7 +2946,11 @@ package body Exp_Ch6 is and then Predicate_Tests_On_Arguments (Subp) then - Append_To (Post_Call, + -- If Actual is a view conversion to a by-copy subtype + -- that is subject to a predicate, then the predicate + -- check must precede copy-back. So Prepend. + + Prepend_To (Post_Call, Make_Predicate_Check (Atyp, Actual)); end if; end By_Ref_Predicate_Check; -- 2.43.0