From cb2ce45bfeca0a99aba1136d02dcb9ae491e477d Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Thu, 4 Jul 2019 08:07:00 +0000 Subject: [PATCH] [Ada] Spurious error on instantiation and limited_with_clause This patch fixes a spurious error during the construction of an instance body in the inlining phase of the frontend, when the package declaration for the main unit has a limited_with_clause on some unit P, and the main unit itself does not have a corresponding regular with_clause, but some other unit in the context has with_clause that has compiled P. P must be removed from visibility to prevent conflicts with homonyms in the generic body to be instantiated. The following must compile quietly: gcc -c gpr2-project-view.adb ---- package GNATCOLL is end GNATCOLL; package GNATCOLL.Refcount is generic type Element_Type (<>) is private; package Shared_Pointers is type Ref is tagged private; type Element_Access is access all Element_Type; type Reference_Type (Element : access Element_Type) is limited null record; function Unchecked_Get (Self : Ref'Class) return Element_Access; function Get (Self : Ref'Class) return Reference_Type is ((Element => Unchecked_Get (Self))); private type Ref is tagged null record; end Shared_Pointers; type Refcounted is abstract tagged null record; generic type Encapsulated is abstract new Refcounted with private; package Smart_Pointers is type Encapsulated_Access is access all Encapsulated'Class; type Ref is tagged private; procedure Set (Self : in out Ref; Data : Encapsulated'Class); procedure Set (Self : in out Ref; Data : access Encapsulated'Class); private type Ref is tagged null record; end Smart_Pointers; end GNATCOLL.Refcount; ---- package body GNATCOLL.Refcount is package body Shared_Pointers is function Unchecked_Get (Self : Ref'Class) return Element_Access is begin return null; end Unchecked_Get; end Shared_Pointers; package body Smart_Pointers is procedure Set (Self : in out Ref; Data : access Encapsulated'Class) is begin null; end Set; procedure Set (Self : in out Ref; Data : Encapsulated'Class) is Tmp : constant Encapsulated_Access := new Encapsulated'Class'(Data); begin Set (Self, Tmp); end Set; end Smart_Pointers; end GNATCOLL.Refcount; ---- package GPR2 is end GPR2; ---- package GPR2.Parser is end GPR2.Parser; ---- with GPR_Parser.Analysis; package GPR2.Parser.Project is end GPR2.Parser.Project; ---- package GPR2.Project is end GPR2.Project; ---- with GPR2.Parser.Project; package GPR2.Project.Configuration is end GPR2.Project.Configuration; ---- with GPR2.Project.Configuration; with GPR2.Unit.Set; package GPR2.Project.Definition is end GPR2.Project.Definition; ---- limited with GPR2.Unit.Set; package GPR2.Project.View is procedure Require_Body; end GPR2.Project.View; ---- with GPR2.Project.Definition; package body GPR2.Project.View is procedure Require_Body is null; end GPR2.Project.View; ---- package GPR2.Unit is end GPR2.Unit; package GPR2.Unit.Set is end GPR2.Unit.Set; ... package GPR_Parser is end GPR_Parser; ---- with GNATCOLL.Refcount; package GPR_Parser.Analysis is type Unit_Provider_Interface is null record; package Unit_Provider_References is new GNATCOLL.Refcount.Shared_Pointers (Unit_Provider_Interface); end GPR_Parser.Analysis; 2019-07-04 Ed Schonberg gcc/ada/ * sem_ch10.adb (Remove_Context_Clauses): Handle properly the removal of a limited_with_clause which appears in the library unit oF the main unit, when some other unit in the context has a regular with_clause on the same unit, to prevent spurious visibility errors in the subsequent analysis of pending instance bodies. From-SVN: r273067 --- gcc/ada/ChangeLog | 9 +++++++++ gcc/ada/sem_ch10.adb | 28 ++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 9d46f39912a..be3241e09f4 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,12 @@ +2019-07-04 Ed Schonberg + + * sem_ch10.adb (Remove_Context_Clauses): Handle properly the + removal of a limited_with_clause which appears in the library + unit oF the main unit, when some other unit in the context has a + regular with_clause on the same unit, to prevent spurious + visibility errors in the subsequent analysis of pending instance + bodies. + 2019-07-04 Hristian Kirtchev * sem_elab.adb: Add new type Elaboration_Phase_Status along with diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb index 407e84fc621..b8d7c6a2f47 100644 --- a/gcc/ada/sem_ch10.adb +++ b/gcc/ada/sem_ch10.adb @@ -6379,22 +6379,38 @@ package body Sem_Ch10 is begin -- Ada 2005 (AI-50217): We remove the context clauses in two phases: - -- limited-views first and regular-views later (to maintain the - -- stack model). + -- limited-views first and regular-views later (to maintain the stack + -- model). -- First Phase: Remove limited_with context clauses Item := First (Context_Items (N)); while Present (Item) loop - -- We are interested only in with clauses which got installed - -- on entry. + -- We are interested only in with clauses that got installed on entry if Nkind (Item) = N_With_Clause and then Limited_Present (Item) - and then Limited_View_Installed (Item) then - Remove_Limited_With_Clause (Item); + if Limited_View_Installed (Item) then + Remove_Limited_With_Clause (Item); + + -- An unusual case: If the library unit of the Main_Unit has + -- a limited with_clause on some unit P and the context somewhere + -- includes a with_clause on P, P has been analyzed. The entity + -- for P is still visible, which in general is harmless because + -- this is the end of the compilation, but it can affect pending + -- instantiations that may have been generated elsewhere, so it + -- it is necessary to remove U from visibility so that inlining + -- and the analysis of instance bodies can proceed cleanly. + + elsif Current_Sem_Unit = Main_Unit + and then Serious_Errors_Detected = 0 + and then not Implicit_With (Item) + then + Set_Is_Immediately_Visible + (Defining_Entity (Unit (Library_Unit (Item))), False); + end if; end if; Next (Item); -- 2.30.2