This patch fixes a loop in the compiler when an address clause is used to specify an overlay, and the overlaid object has an illegal object declaration in which the expression is a premature reference to the object itself.
Compiling p.ads must yield: p.ads:3:33: object "Nowhere" cannot be used before end of its declaration --- with system; use system; --- with System; use System; package P is Nowhere : constant Address := Nowhere; Thing : Integer; for Thing'Address use Nowhere; end; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-05-02 Ed Schonberg <schonb...@adacore.com> * sem_ch8.adb (Premature_Usage): If the premature usage of an entity is as the expression in its own object decaration, rewrite the reference as Any_Id to prevent cascaded errors or compiler loops when such an entity is used in an address clause.
Index: sem_ch8.adb =================================================================== --- sem_ch8.adb (revision 247461) +++ sem_ch8.adb (working copy) @@ -8562,6 +8562,14 @@ else Error_Msg_N ("object& cannot be used before end of its declaration!", N); + + -- If the premature reference appears as the expression in its own + -- declaration, rewrite it to prevent compiler loops in subsequent + -- uses of this mangled declaration in address clauses. + + if Nkind (Parent (N)) = N_Object_Declaration then + Set_Entity (N, Any_Id); + end if; end if; end Premature_Usage;