From: Steve Baird <baird@adacore.com>
In some cases, the RM 8.5.1(3.1) legality rule about uses of renamings of
limited views of packages was implemented incorrectly, resulting in rejecting
legal uses.
gcc/ada/ChangeLog:
* gen_il-fields.ads: add new Renames_Limited_View field.
* gen_il-gen-gen_entities.adb: add Renames_Limited_View flag for
packages.
* einfo.ads: add comment documenting Renames_Limited_View flag.
* sem_ch8.adb (Analyze_Package_Renaming): Set new Renames_Limited_View
flag. Test new Renames_Limited_View flag instead of calling
Has_Limited_With. If Has_Limited_With is True, that just means
that somebody, sometime during this compilation needed to
reference the limited view of the package; so that function
returns True too often to be used here.
(Find_Expanded_Name): Test new Renames_Limited_View flag instead of
calling Has_Limited_With.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/einfo.ads | 9 +++++++++
gcc/ada/gen_il-fields.ads | 1 +
gcc/ada/gen_il-gen-gen_entities.adb | 1 +
gcc/ada/sem_ch8.adb | 7 ++++---
4 files changed, 15 insertions(+), 3 deletions(-)
@@ -4247,6 +4247,15 @@ package Einfo is
-- within an accept statement. For all remaining cases (discriminants,
-- loop parameters) the field is Empty.
+-- Renames_Limited_View
+-- Defined in package entities. True for a package renaming if either
+-- a) the renamed package is not itself a renaming, and the renaming
+-- denotes a limited view of the renamed package (as seen at the
+-- point of the renaming declaration, as opposed to later on when
+-- the renaming is referenced); or
+-- b) the renamed package is itself a renaming and the
+-- Renames_Limited_View flag is True for the renamed package.
+
-- Requires_Overriding
-- Defined in all subprograms and entries. Set for subprograms that
-- require overriding as defined by RM-2005-3.9.3(6/2). Note that this
@@ -879,6 +879,7 @@ package Gen_IL.Fields is
Relative_Deadline_Variable,
Renamed_In_Spec,
Renamed_Or_Alias, -- Shared among Alias, Renamed_Entity, Renamed_Object
+ Renames_Limited_View,
Requires_Overriding,
Return_Applies_To,
Return_Present,
@@ -1281,6 +1281,7 @@ begin -- Gen_IL.Gen.Gen_Entities
Sm (Related_Instance, Node_Id),
Sm (Renamed_In_Spec, Flag),
Sm (Renamed_Or_Alias, Node_Id),
+ Sm (Renames_Limited_View, Flag),
Sm (Scope_Depth_Value, Unat),
Sm (SPARK_Aux_Pragma, Node_Id),
Sm (SPARK_Aux_Pragma_Inherited, Flag),
@@ -1665,8 +1665,7 @@ package body Sem_Ch8 is
Set_Etype (New_P, Standard_Void_Type);
elsif Present (Renamed_Entity (Old_P))
- and then (From_Limited_With (Renamed_Entity (Old_P))
- or else Has_Limited_View (Renamed_Entity (Old_P)))
+ and then Renames_Limited_View (Old_P)
and then not
Unit_Is_Visible (Cunit (Get_Source_Unit (Renamed_Entity (Old_P))))
then
@@ -1691,8 +1690,10 @@ package body Sem_Ch8 is
if Present (Renamed_Entity (Old_P)) then
Set_Renamed_Entity (New_P, Renamed_Entity (Old_P));
+ Set_Renames_Limited_View (New_P, Renames_Limited_View (Old_P));
else
Set_Renamed_Entity (New_P, Old_P);
+ Set_Renames_Limited_View (New_P, From_Limited_With (Old_P));
end if;
-- The package renaming declaration may become Ghost if it renames a
@@ -7077,7 +7078,7 @@ package body Sem_Ch8 is
("renaming of limited view of package & not usable in this"
& " context (RM 8.5.3(3.1/2))", Prefix (N), P_Name);
- elsif Has_Limited_View (P_Name)
+ elsif Renames_Limited_View (Entity (Prefix (N)))
and then not Unit_Is_Visible (Cunit (Get_Source_Unit (P_Name)))
and then not Is_Visible_Through_Renamings (P_Name)
then