aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch3.adb
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2023-03-08 12:15:13 -0500
committerMarc Poulhiès <poulhies@adacore.com>2023-05-25 09:44:18 +0200
commit14bf9f7bb7fe6176532414093f9a5084bbd41428 (patch)
treec88ab2fa628b09bcc7b498bf5a028fd2d92ac5ed /gcc/ada/sem_ch3.adb
parent5b8bdb676dae45d51af82c7e56968d1e1af1a494 (diff)
downloadgcc-14bf9f7bb7fe6176532414093f9a5084bbd41428.zip
gcc-14bf9f7bb7fe6176532414093f9a5084bbd41428.tar.gz
gcc-14bf9f7bb7fe6176532414093f9a5084bbd41428.tar.bz2
ada: Switch from E_Void to Is_Not_Self_Hidden
We had previously used Ekind = E_Void to indicate that a declaration is self-hidden. We now use the Is_Not_Self_Hidden flag instead. This allows us to avoid many "vanishing fields", which are (possibly-latent) bugs, and we now enable the assertions in Atree that detect such bugs. gcc/ada/ * atree.adb (Check_Vanishing_Fields): Fix bug in the "blah type only" cases. Remove the special cases for E_Void. Misc cleanup. (Mutate_Nkind): Disallow mutating to the same kind. (Mutate_Ekind): Disallow mutating to E_Void. (From E_Void is still OK -- entities start out as E_Void by default.) Fix bug in statistics gathering -- was setting the wrong count. Enable Check_Vanishing_Fields for entities. * sem_ch8.adb (Is_Self_Hidden): New function. (Find_Direct_Name): Call Is_Self_Hidden to use the new Is_Not_Self_Hidden flag to determine whether a declaration is hidden from all visibility by itself. This replaces the old method of checking E_Void. (Find_Expanded_Name): Likewise. (Find_Selected_Component): Likewise. * sem_util.adb (Enter_Name): Remove setting of Ekind to E_Void. * sem_ch3.adb: Set the Is_Not_Self_Hidden flag in appropriate places. Comment fixes. (Inherit_Component): Remove setting of Ekind to E_Void. * sem_ch9.adb (Analyze_Protected_Type_Declaration): Update comment. Skip Itypes, which should not be turned into components. * atree.ads (Mutate_Nkind): Document error case. (Mutate_Ekind): Remove comments apologizing for E_Void mutations. Document error cases.
Diffstat (limited to 'gcc/ada/sem_ch3.adb')
-rw-r--r--gcc/ada/sem_ch3.adb50
1 files changed, 24 insertions, 26 deletions
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index db2bbb5..1ed590ba 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -7589,6 +7589,7 @@ package body Sem_Ch3 is
end if;
Mutate_Ekind (New_Lit, E_Enumeration_Literal);
+ Set_Is_Not_Self_Hidden (New_Lit);
Set_Enumeration_Pos (New_Lit, Enumeration_Pos (Literal));
Set_Enumeration_Rep (New_Lit, Enumeration_Rep (Literal));
Set_Enumeration_Rep_Expr (New_Lit, Empty);
@@ -8123,6 +8124,7 @@ package body Sem_Ch3 is
Build_Derived_Type
(N, Full_Parent, Full_Der,
Is_Completion => False, Derive_Subps => False);
+ Set_Is_Not_Self_Hidden (Full_Der);
end if;
Set_Has_Private_Declaration (Full_Der);
@@ -9917,8 +9919,8 @@ package body Sem_Ch3 is
-- There is no completion for record extensions declared in the
-- parameter part of a generic, so we need to complete processing for
- -- these generic record extensions here. The Record_Type_Definition call
- -- will change the Ekind of the components from E_Void to E_Component.
+ -- these generic record extensions here. Record_Type_Definition will
+ -- set the Is_Not_Self_Hidden flag.
elsif Private_Extension and then Is_Generic_Type (Derived_Type) then
Record_Type_Definition (Empty, Derived_Type);
@@ -11959,6 +11961,8 @@ package body Sem_Ch3 is
return;
end if;
+ Set_Is_Not_Self_Hidden (Typ);
+
Comp := First (Component_Items (Comp_List));
while Present (Comp) loop
if Nkind (Comp) = N_Component_Declaration then
@@ -12930,13 +12934,14 @@ package body Sem_Ch3 is
-- Set common attributes for all subtypes: kind, convention, etc.
- Mutate_Ekind (Full, Subtype_Kind (Ekind (Full_Base)));
- Set_Convention (Full, Convention (Full_Base));
+ Mutate_Ekind (Full, Subtype_Kind (Ekind (Full_Base)));
+ Set_Is_Not_Self_Hidden (Full);
+ Set_Convention (Full, Convention (Full_Base));
Set_Is_First_Subtype (Full, False);
- Set_Scope (Full, Scope (Priv));
- Set_Size_Info (Full, Full_Base);
- Copy_RM_Size (To => Full, From => Full_Base);
- Set_Is_Itype (Full);
+ Set_Scope (Full, Scope (Priv));
+ Set_Size_Info (Full, Full_Base);
+ Copy_RM_Size (To => Full, From => Full_Base);
+ Set_Is_Itype (Full);
-- A subtype of a private-type-without-discriminants, whose full-view
-- has discriminants with default expressions, is not constrained.
@@ -15094,6 +15099,7 @@ package body Sem_Ch3 is
-- in the private part is the full declaration.
Exchange_Entities (Priv, Full);
+ Set_Is_Not_Self_Hidden (Priv);
Append_Entity (Full, Scope (Full));
end Copy_And_Swap;
@@ -16046,6 +16052,7 @@ package body Sem_Ch3 is
begin
New_Subp := New_Entity (Nkind (Parent_Subp), Sloc (Derived_Type));
Mutate_Ekind (New_Subp, Ekind (Parent_Subp));
+ Set_Is_Not_Self_Hidden (New_Subp);
-- Check whether the inherited subprogram is a private operation that
-- should be inherited but not yet made visible. Such subprograms can
@@ -17662,6 +17669,8 @@ package body Sem_Ch3 is
-- Avoid deriving parent primitives of underlying record views
+ Set_Is_Not_Self_Hidden (T);
+
Build_Derived_Type (N, Parent_Type, T, Is_Completion,
Derive_Subps => not Is_Underlying_Record_View (T));
@@ -17750,6 +17759,7 @@ package body Sem_Ch3 is
while Present (L) loop
if Ekind (L) /= E_Enumeration_Literal then
Mutate_Ekind (L, E_Enumeration_Literal);
+ Set_Is_Not_Self_Hidden (L);
Set_Enumeration_Pos (L, Ev);
Set_Enumeration_Rep (L, Ev);
Set_Is_Known_Valid (L, True);
@@ -19197,22 +19207,6 @@ package body Sem_Ch3 is
end if;
end if;
- -- In derived tagged types it is illegal to reference a non
- -- discriminant component in the parent type. To catch this, mark
- -- these components with an Ekind of E_Void. This will be reset in
- -- Record_Type_Definition after processing the record extension of
- -- the derived type.
-
- -- If the declaration is a private extension, there is no further
- -- record extension to process, and the components retain their
- -- current kind, because they are visible at this point.
-
- if Is_Tagged and then Ekind (New_C) = E_Component
- and then Nkind (N) /= N_Private_Extension_Declaration
- then
- Mutate_Ekind (New_C, E_Void);
- end if;
-
if Plain_Discrim then
Set_Corresponding_Discriminant (New_C, Old_C);
Build_Discriminal (New_C);
@@ -20222,6 +20216,7 @@ package body Sem_Ch3 is
Op := Make_Defining_Operator_Symbol (Loc, Name_Op_Concat);
Mutate_Ekind (Op, E_Operator);
+ Set_Is_Not_Self_Hidden (Op);
Set_Scope (Op, Current_Scope);
Set_Etype (Op, Typ);
Set_Homonym (Op, Get_Name_Entity_Id (Name_Op_Concat));
@@ -20940,6 +20935,7 @@ package body Sem_Ch3 is
end if;
Mutate_Ekind (Id, E_Discriminant);
+ Set_Is_Not_Self_Hidden (Id);
Reinit_Component_Location (Id);
Reinit_Esize (Id);
Set_Discriminant_Number (Id, Discr_Number);
@@ -22762,6 +22758,8 @@ package body Sem_Ch3 is
T := Prev_T;
end if;
+ Set_Is_Not_Self_Hidden (T);
+
Final_Storage_Only := not Is_Controlled (T);
-- Ada 2005: Check whether an explicit "limited" is present in a derived
@@ -22803,6 +22801,7 @@ package body Sem_Ch3 is
then
Mutate_Ekind (Component, E_Component);
Reinit_Component_Location (Component);
+ Set_Is_Not_Self_Hidden (Component);
end if;
Propagate_Concurrent_Flags (T, Etype (Component));
@@ -23022,9 +23021,8 @@ package body Sem_Ch3 is
-- Reset the kind of the subtype during analysis of the range, to
-- catch possible premature use in the bounds themselves.
- Mutate_Ekind (Def_Id, E_Void);
Process_Range_Expr_In_Decl (R, Subt, Subtyp => Def_Id);
- Mutate_Ekind (Def_Id, Kind);
+ pragma Assert (Ekind (Def_Id) = Kind);
end Set_Scalar_Range_For_Subtype;
--------------------------------------------------------