From: Eric Botcazou Date: Mon, 24 Nov 2025 17:08:10 +0000 (+0100) Subject: ada: Fix premature finalization caused by predicate check on aggregate component X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48f841e26082d21b5a4d0d314161b79d3ba9f935;p=thirdparty%2Fgcc.git 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 --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;