diff mbox series

[COMMITTED,14/17] ada: Fix missing finalization for call to function returning limited view

Message ID 20240829130750.1651060-14-poulhies@adacore.com
State New
Headers show
Series [COMMITTED,01/17] ada: Update documentation for conditional when constructs | expand

Commit Message

Marc Poulhiès Aug. 29, 2024, 1:07 p.m. UTC
From: Eric Botcazou <ebotcazou@adacore.com>

The call is legal because it is made from the body, which has visibility on
the nonlimited view, so this changes the code in Expand_Call_Helper to look
at the Etype of the call node instead of the Etype of the function.

gcc/ada/

	* exp_ch6.adb (Expand_Call_Helper): In the case of a function
	call, look at the Etype of the call node to determine whether
	finalization actions need to be performed.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch6.adb | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 420d5f44a69..3c87c0e8220 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -5262,7 +5262,9 @@  package body Exp_Ch6 is
       --  function call is transformed into a reference to the result that has
       --  been built either on the primary or the secondary stack.
 
-      if Needs_Finalization (Etype (Subp)) then
+      if Nkind (Call_Node) = N_Function_Call
+        and then Needs_Finalization (Etype (Call_Node))
+      then
          if not Is_Build_In_Place_Function_Call (Call_Node)
            and then
              (No (First_Formal (Subp))
@@ -5270,7 +5272,7 @@  package body Exp_Ch6 is
                  not Is_Concurrent_Record_Type (Etype (First_Formal (Subp))))
          then
             Expand_Ctrl_Function_Call
-              (Call_Node, Needs_Secondary_Stack (Etype (Subp)));
+              (Call_Node, Needs_Secondary_Stack (Etype (Call_Node)));
 
          --  Build-in-place function calls which appear in anonymous contexts
          --  need a transient scope to ensure the proper finalization of the
@@ -5292,7 +5294,7 @@  package body Exp_Ch6 is
                  Is_Build_In_Place_Function_Call (Parent (Call_Node)))
          then
             Establish_Transient_Scope
-              (Call_Node, Needs_Secondary_Stack (Etype (Subp)));
+              (Call_Node, Needs_Secondary_Stack (Etype (Call_Node)));
          end if;
       end if;
    end Expand_Call_Helper;