From 82e9c7c9c1ba3ce16c0cca83fddb70fb85df8eff Mon Sep 17 00:00:00 2001
From: Eric Botcazou <ebotcazou@adacore.com>
Date: Fri, 6 Dec 2024 15:30:49 +0100
Subject: [PATCH] ada: Fix finalization issue introduced by previous change

When detecting calls to subprograms specified for aspects of a type, the
entity denoted by the aspects must go through Ultimate_Alias, since that
of the name of the calls did the same.

gcc/ada/ChangeLog:

	* exp_ch6.adb (Expand_Call_Helper): Call Ultimate_Alias for the
	detection of calls to subprograms specified for Constant_Indexing.
	* exp_util.adb (Is_Indexed_Container): Likewise.
	(Is_Iterated_Container): Likewise for Default_Iterator.
---
 gcc/ada/exp_ch6.adb  | 5 +++--
 gcc/ada/exp_util.adb | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index c65ea91cb13b..e6e5d50dbbf6 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -5331,16 +5331,17 @@ package body Exp_Ch6 is
 
       elsif Nkind (Call_Node) = N_Function_Call
         and then Nkind (Parent (Call_Node)) = N_Function_Call
+        and then Is_Entity_Name (Name (Parent (Call_Node)))
       then
          declare
             Aspect : constant Node_Id :=
               Find_Value_Of_Aspect
                 (Etype (Call_Node), Aspect_Constant_Indexing);
+            Subp   : constant Entity_Id := Entity (Name (Parent (Call_Node)));
 
          begin
             if Present (Aspect)
-              and then Is_Entity_Name (Name (Parent (Call_Node)))
-              and then Entity (Name (Parent (Call_Node))) = Entity (Aspect)
+              and then Subp = Ultimate_Alias (Entity (Aspect))
             then
                --  Resolution is now finished, make sure we don't start
                --  analysis again because of the duplication.
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index a9424b95880b..25f9f077174b 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -8945,7 +8945,7 @@ package body Exp_Util is
          Aspect := Find_Value_Of_Aspect (Typ, Aspect_Constant_Indexing);
 
          if Present (Aspect) then
-            Index := Entity (Aspect);
+            Index := Ultimate_Alias (Entity (Aspect));
 
             --  Examine the statements following the container object and
             --  look for a call to the default indexing routine where the
@@ -9030,7 +9030,7 @@ package body Exp_Util is
          Aspect := Find_Value_Of_Aspect (Typ, Aspect_Default_Iterator);
 
          if Present (Aspect) then
-            Iter := Entity (Aspect);
+            Iter := Ultimate_Alias (Entity (Aspect));
 
             --  Examine the statements following the container object and
             --  look for a call to the default iterate routine where the
-- 
GitLab