]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix missing finalization with conditional expression in extended return
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 12 Jun 2025 19:58:49 +0000 (21:58 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 3 Jul 2025 08:16:28 +0000 (10:16 +0200)
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

index 72d00bcb3189f693a00de616912e54bf358e0355..e9a73e16b07e2f24cb8d4a02bc6d3f1b72e7d740 100644 (file)
@@ -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;