From ce51aec0583912e46a4c519f5da04deabb400f8e Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 12 Jun 2025 21:58:49 +0200 Subject: [PATCH] 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. --- gcc/ada/exp_ch6.adb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 0db67b9b57e..6f3621c423e 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -5391,9 +5391,14 @@ package body Exp_Ch6 is end if; -- Note that object declarations are also distributed into conditional - -- expressions but we may be invoked before this distribution is done. + -- 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; -- 2.47.2