https://gcc.gnu.org/g:499406992f48cc8da64448a107f95e681cea9039

commit r15-3302-g499406992f48cc8da64448a107f95e681cea9039
Author: Eric Botcazou <ebotca...@adacore.com>
Date:   Fri Aug 16 11:28:37 2024 +0200

    ada: Fix missing finalization for call to function returning limited view
    
    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.

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

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 420d5f44a69e..3c87c0e8220c 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;

Reply via email to