This occurs when an overloaded subprogram of the package is locally renamed, 
because this renaming is not recorded as a reference to the package.

Tested on x86-64/Linux, applied on the mainline and 16 branch.


2026-10-07  Eric Botcazou  <[email protected]>

        PR ada/126448
        * sem_ch8.adb (Analyze_Subprogram_Renaming): Pass Nam instead of
        Name (N) in the calls to Find_Renamed_Entity.  Remove if_statement
        whose condition is always false.
        (Find_Renamed_Entity): In the overloaded case and if the overload
        resolution has succeeded, call Mark_Use_Clauses on the entity.


2026-10-07  Eric Botcazou  <[email protected]>

        * gnat.dg/renaming20.adb: New test.

-- 
Eric Botcazou
diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index 661aa6beef3..8591268edb1 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -3319,7 +3319,7 @@ package body Sem_Ch8 is
                --  Box present
 
                if Box_Present (Inst_Node) then
-                  Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
+                  Old_S := Find_Renamed_Entity (N, Nam, New_S, Is_Actual);
 
                --  If there is an immediately visible homonym of the operator
                --  and the declaration has a default, this is worth a warning
@@ -3679,7 +3679,7 @@ package body Sem_Ch8 is
       Ada_Version_Explicit := Ada_Version;
 
       if No (Old_S) then
-         Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
+         Old_S := Find_Renamed_Entity (N, Nam, New_S, Is_Actual);
 
          --  The visible operation may be an inherited abstract operation that
          --  was overridden in the private part, in which case a call will
@@ -3695,14 +3695,6 @@ package body Sem_Ch8 is
          then
             Old_S := Alias (Old_S);
          end if;
-
-         --  When the renamed subprogram is overloaded and used as an actual
-         --  of a generic, its entity is set to the first available homonym.
-         --  We must first disambiguate the name, then set the proper entity.
-
-         if Is_Actual and then Is_Overloaded (Nam) then
-            Set_Entity (Nam, Old_S);
-         end if;
       end if;
 
       --  Most common case: subprogram renames subprogram. No body is generated
@@ -8108,8 +8100,12 @@ package body Sem_Ch8 is
 
          Set_Entity (Nam, Old_S);
 
+         --  If overload resolution has succeeded, reset the flag and mark
+         --  relevant use clauses like Find_{Direct,Expanded}_Name above.
+
          if Old_S /= Any_Id then
             Set_Is_Overloaded (Nam, False);
+            Mark_Use_Clauses (Old_S);
          end if;
 
       --  Non-overloaded case
-- { dg-do compile }
-- { dg-options "-gnatwu" }

with Ada.Strings.Fixed;
with Ada.Text_IO;

procedure Renaming20 is

  use Ada.Strings;
  use Fixed;

  function T (Item : String; Side : Trim_End) return String
    renames Trim;

begin
  Ada.Text_IO.Put_Line (T (" Hello ", Left));
end;

Reply via email to