[Ada] Improved handling of circular compilation dependencies

Message ID 20191212100431.GA114805@adacore.com
State New
Headers show
Series
  • [Ada] Improved handling of circular compilation dependencies
Related show

Commit Message

Pierre-Marie de Rodat Dec. 12, 2019, 10:04 a.m.
In the case described on this ticket, a predefined unit (the body of
Ada.Finalization) is recompiled with a configuration pragma in effect
(an Interrupt_State pragma) which has has the effect of introducing a
circular compilation dependency.  Previously this resulted in an
internal error. With this change, a better error message is produced.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-12-12  Steve Baird  <baird@adacore.com>

gcc/ada/

	* sem_ch10.adb (Install_With_Clause): Check for the case of a
	circular dependency involving a predefined (or GNAT-defined)
	unit and handle that case by generating an appropropriate error
	message.

Patch

--- gcc/ada/sem_ch10.adb
+++ gcc/ada/sem_ch10.adb
@@ -5336,6 +5336,20 @@  package body Sem_Ch10 is
             Error_Msg_N
               ("instantiation depends on itself", Name (With_Clause));
 
+         elsif not Analyzed (Uname)
+           and then Is_Internal_Unit (Current_Sem_Unit)
+           and then not Is_Visible_Lib_Unit (Uname)
+           and then No (Scope (Uname))
+         then
+            if Is_Predefined_Unit (Current_Sem_Unit) then
+               Error_Msg_N
+                 ("predefined unit depends on itself", Name (With_Clause));
+            else
+               Error_Msg_N
+                 ("GNAT-defined unit depends on itself", Name (With_Clause));
+            end if;
+            return;
+
          elsif not Is_Visible_Lib_Unit (Uname) then
 
             --  Abandon processing in case of previous errors