]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix fallout of recent finalization fix for limited types
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 13 Nov 2025 20:12:54 +0000 (21:12 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 27 Nov 2025 12:57:43 +0000 (13:57 +0100)
The recent finalization fix made for limited types has uncovered cases where
the object returned by calls to build-in-place functions was not finalized
in selected anonymous contexts, most notably the dependent expressions of
conditional expressions.  The specific finalization machinery that handles
conditional expressions requires the temporaries built for their dependent
expressions to be visible as early as possible, and this was not the case.

gcc/ada/ChangeLog:

* exp_ch4.adb (Expand_N_Case_Expression): When not optimizing for a
specific context, call Make_Build_In_Place_Call_In_Anonymous_Context
on expressions of alternatives when they are calls to BIP functions.
(Expand_N_If_Expression): Likewise for the Then & Else expressions.

gcc/ada/exp_ch4.adb

index 7c90aa0d1b8ee5130e348ec271cbeb4b978700a9..520ab683a6e232d71576f025c44feb115151fcc2 100644 (file)
@@ -5368,7 +5368,17 @@ package body Exp_Ch4 is
          --  When the alternative's expression involves controlled function
          --  calls, generated temporaries are chained on the corresponding
          --  list of actions. These temporaries need to be finalized after
-         --  the case expression is evaluated.
+         --  the case expression is evaluated. We first need to make them
+         --  explicit for build-in-place functions in anonymous contexts,
+         --  because calls to these do not go through Expand_Ctrl_Actions.
+
+         if Is_Build_In_Place_Function_Call (Expression (Alt))
+           and then not Optimize_Assignment_Stmt
+           and then not Optimize_Return_Stmt
+           and then not Optimize_Object_Decl
+         then
+            Make_Build_In_Place_Call_In_Anonymous_Context (Expression (Alt));
+         end if;
 
          Process_Transients_In_Expression (N, Actions (Alt));
 
@@ -6345,7 +6355,17 @@ package body Exp_Ch4 is
          --  When the "then" or "else" expressions involve controlled function
          --  calls, generated temporaries are chained on the corresponding list
          --  of actions. These temporaries need to be finalized after the if
-         --  expression is evaluated.
+         --  expression is evaluated. We first need to make them explicit for
+         --  build-in-place functions in anonymous contexts, because calls to
+         --  these do not go through Expand_Ctrl_Actions.
+
+         if Is_Build_In_Place_Function_Call (Thenx) then
+            Make_Build_In_Place_Call_In_Anonymous_Context (Thenx);
+         end if;
+
+         if Is_Build_In_Place_Function_Call (Elsex) then
+            Make_Build_In_Place_Call_In_Anonymous_Context (Elsex);
+         end if;
 
          Process_Transients_In_Expression (N, Then_Actions (N));
          Process_Transients_In_Expression (N, Else_Actions (N));