diff mbox

[Ada] Compiler hang with full inlining and use clause in parent private part

Message ID 20150302112040.GA1211@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet March 2, 2015, 11:20 a.m. UTC
When compiling a descendant instance unit use_clauses in parent units are
chained to simplify removal at end of compilation. Use_clauses that appear in
the private part of parent are chained when compiling the private part of
the descendant. To prevent circularities in the list, use_clauses in the
private part of an ancestor should not be chained if there is an intervening
parent whose private part is already installed. 

The following must compile properly:
   gcc -c -gnatn2 main.adbo

---
with P2;
with P3;
package body Main is
   package P2_Instance is new P2.Instance (Boolean);
end;
---
package Main is
   pragma Elaborate_Body;
end;
---
package G1 is
   generic package Instance is end;
end;
---
generic package G2.Child is end;
package body G2 is
   procedure P is begin null; end;
end;
---
generic package G2 is
   procedure P;
   pragma Inline (P);
end;
---
with G2.Child;
package P1.G2_Instance.Child_Instance is new P1.G2_Instance.Child;
---
with G2;
package P1.G2_Instance is new G2;
---
with G1;
package P1 is
 private
   package G1_Instance is new G1.Instance;
   use G1_Instance;
end;
---
with P1.G2_Instance;
package body P2 is
   package body Instance is
      procedure R (X : T_Access) is begin null; end;
   end Instance;
end;
---
package P2 is
   generic
      type T is private;
   package Instance is
      type T_Access is access all T;
      procedure R (X : T_Access);
   end Instance;
end;
---
with P1.G2_Instance.Child_Instance;
package body P3 is end;
---
with S;
package P3 is
   pragma Elaborate_Body;
   function F (S : Boolean) return Integer is (0);
   function F (I : Integer) return Integer is (F(S.G(I)));
end;
---
package S is
   function G (I : Integer) return Boolean;
end;

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

2015-03-02  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch8.adb (Chain_Use_Clause): Do not chain use clause from
	ancestor to list of use clauses active in descendant unit if we
	are within the private part of an intervening parent, to prevent
	circularities in use clause list.
diff mbox

Patch

Index: sem_ch8.adb
===================================================================
--- sem_ch8.adb	(revision 221113)
+++ sem_ch8.adb	(working copy)
@@ -4026,6 +4026,15 @@ 
          if not In_Open_Scopes (Pack) then
             null;  --  default as well
 
+         --  If the use clause appears in an ancestor and we are in the
+         --  private part of the immediate parent, the use clauses are
+         --  already installed.
+
+         elsif Pack /= Scope (Current_Scope)
+           and then In_Private_Part (Scope (Current_Scope))
+         then
+            null;
+
          else
             --  Find entry for parent unit in scope stack