From: Steve Baird <[email protected]>

A homonyms list should be acyclic. Do not introduce a cycle in an error case.

gcc/ada/ChangeLog:

        * sem_ch6.adb (Install_Entity): If the entity to be installed is
        already installed, assert that an error has already been flagged
        and then return without introducing a cycle in the entity's
        Homonyms list.

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

---
 gcc/ada/sem_ch6.adb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index b0eeab5bdb6..400c3069f9f 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -10932,9 +10932,14 @@ package body Sem_Ch6 is
    procedure Install_Entity (E : Entity_Id) is
       Prev : constant Entity_Id := Current_Entity (E);
    begin
+      if Prev = E then
+         --  avoid creating a Homonym-list cycle
+         pragma Assert (Serious_Errors_Detected > 0);
+         return;
+      end if;
+
       Set_Is_Immediately_Visible (E);
       Set_Current_Entity (E);
-      pragma Assert (Prev /= E);
       Set_Homonym (E, Prev);
    end Install_Entity;
 
-- 
2.53.0

Reply via email to