https://gcc.gnu.org/g:48f841e26082d21b5a4d0d314161b79d3ba9f935
commit r16-6601-g48f841e26082d21b5a4d0d314161b79d3ba9f935 Author: Eric Botcazou <[email protected]> Date: Mon Nov 24 18:08:10 2025 +0100 ada: Fix premature finalization caused by predicate check on aggregate component 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. Diff: --- 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 d9ef17ffabc2..6424f0a1d556 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;
