https://gcc.gnu.org/g:448e857b977ef673fa8a28d24dcd4567f4d5d0cd
commit r16-1951-g448e857b977ef673fa8a28d24dcd4567f4d5d0cd Author: Eric Botcazou <ebotca...@adacore.com> Date: Thu Jun 12 21:58:49 2025 +0200 ada: Fix missing finalization with conditional expression in extended return Declarations of return objects are not (yet) distributed into the dependent expressions of conditional expressions. gcc/ada/ChangeLog: * exp_ch6.adb (Expand_Ctrl_Function_Call): Do not bail out for the declarations of return objects. Diff: --- gcc/ada/exp_ch6.adb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 72d00bcb3189..e9a73e16b07e 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -5387,8 +5387,13 @@ package body Exp_Ch6 is -- Note that object declarations are also distributed into conditional -- expressions, but we may be invoked before this distribution is done. + -- However that's not the case for the declarations of return objects, + -- see the twin Is_Optimizable_Declaration predicates that are present + -- in Expand_N_Case_Expression and Expand_N_If_Expression of Exp_Ch4. - elsif Nkind (Uncond_Par) = N_Object_Declaration then + elsif Nkind (Uncond_Par) = N_Object_Declaration + and then not Is_Return_Object (Defining_Identifier (Uncond_Par)) + then return; end if;