From: Eric Botcazou <[email protected]>
The predicate check may cause the creation of a temporary when it is applied
to a function call and the temporary will be finalized, so any assignment of
the temporary must be followed by an adjustment of the target.
gcc/ada/ChangeLog:
* exp_ch5.adb (Expand_N_Assignment_Statement): If a predicate check
made on the RHS forced the capture of a function call to remove its
side effects, demote No_Ctrl_Actions into No_Finalize_Actions on the
N_Assignment_Statement node.
Tested on x86_64-pc-linux-gnu (before the recent bootstrap breakage), committed
on master.
---
gcc/ada/exp_ch5.adb | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
index d9ef17ffabc..6424f0a1d55 100644
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -2527,6 +2527,20 @@ package body Exp_Ch5 is
end if;
Apply_Predicate_Check (Rhs, Typ);
+
+ -- If the generation of the check required capturing a function
+ -- call to remove its side effects, and the assignment initially
+ -- was to be done without controlled actions, then change it to
+ -- be done without finalization only, in other words restore the
+ -- adjustment of the LHS, because the RHS is now a temporary that
+ -- will be finalized after the assignment is complete.
+
+ if No_Ctrl_Actions (N)
+ and then Is_Captured_Function_Call (Rhs)
+ then
+ Set_No_Ctrl_Actions (N, False);
+ Set_No_Finalize_Actions (N, True);
+ end if;
end if;
end if;
--
2.51.0