]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Perform predicate check before, not after, parameter copy back.
authorSteve Baird <baird@adacore.com>
Thu, 21 Aug 2025 21:20:51 +0000 (14:20 -0700)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 11 Sep 2025 09:10:49 +0000 (11:10 +0200)
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.

gcc/ada/exp_ch6.adb

index 18551d4899e3d819f98d7e3382d2b8c2da3e11cc..1a9002ce3a8bfebb141a7b5bf5fcabf176cd4add 100644 (file)
@@ -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;