https://gcc.gnu.org/g:ce51aec0583912e46a4c519f5da04deabb400f8e

commit r15-9909-gce51aec0583912e46a4c519f5da04deabb400f8e
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 | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 0db67b9b57e4..6f3621c423ee 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;

Reply via email to