aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch3.adb
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2022-07-17 12:38:15 +0200
committerMarc Poulhiès <poulhies@adacore.com>2022-09-05 09:21:01 +0200
commitae035e3437c1ec7d96773b31e631ec121bb4153f (patch)
treeffa89f6d57401aa54b31a9b09c23e9ec8a343305 /gcc/ada/sem_ch3.adb
parent88fbab0d71bc161aae1353a817594d14d977b0ea (diff)
downloadgcc-ae035e3437c1ec7d96773b31e631ec121bb4153f.zip
gcc-ae035e3437c1ec7d96773b31e631ec121bb4153f.tar.gz
gcc-ae035e3437c1ec7d96773b31e631ec121bb4153f.tar.bz2
[Ada] Fix crash for Default_Initial_Condition on derived enumeration type
This fixes a crash on the declaration of a private derived enumeration type with the Default_Initial_Condition aspect and in the process makes a couple of related adjustments: 1) removes the early freezing of implicit character and numeric base types and 2) fixes an oversight in the implementation of delayed representation aspects. gcc/ada/ * aspects.ads (Delaying Evaluation of Aspect): Fix typos. * exp_ch3.adb (Freeze_Type): Do not generate Invariant and DIC procedures for internal types. * exp_util.adb (Build_DIC_Procedure_Body): Adjust comment. * freeze.adb (Freeze_Entity): Call Inherit_Delayed_Rep_Aspects for subtypes and derived types only after the base or parent type has been frozen. Remove useless freezing for first subtype. (Freeze_Fixed_Point_Type): Call Inherit_Delayed_Rep_Aspects too. * layout.adb (Set_Elem_Alignment): Deal with private types. * sem_ch3.adb (Build_Derived_Enumeration_Type): Build the implicit base as an itype and do not insert its declaration in the tree. (Build_Derived_Numeric_Type): Do not freeze the implicit base. (Derived_Standard_Character): Likewise. (Constrain_Enumeration): Inherit the chain of representation items instead of replacing it. * sem_ch13.ads (Inherit_Aspects_At_Freeze_Point): Add ??? comment. (Inherit_Delayed_Rep_Aspects): Declare. * sem_ch13.adb (Analyze_Aspects_At_Freeze_Point): Do not invoke Inherit_Delayed_Rep_Aspects. (Inherit_Aspects_At_Freeze_Point): Deal with private types. (Inherit_Delayed_Rep_Aspects): Move to library level.
Diffstat (limited to 'gcc/ada/sem_ch3.adb')
-rw-r--r--gcc/ada/sem_ch3.adb83
1 files changed, 23 insertions, 60 deletions
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 223849c..00c2e67 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -7412,12 +7412,13 @@ package body Sem_Ch3 is
Analyze (High_Bound (Range_Expression (Constraint (Indic))));
end if;
- -- Introduce an implicit base type for the derived type even if there
+ -- Create an implicit base type for the derived type even if there
-- is no constraint attached to it, since this seems closer to the
- -- Ada semantics. Build a full type declaration tree for the derived
- -- type using the implicit base type as the defining identifier. Then
- -- build a subtype declaration tree which applies the constraint (if
- -- any) have it replace the derived type declaration.
+ -- Ada semantics. Use an Itype like for the implicit base type of
+ -- other kinds of derived type, but build a full type declaration
+ -- for it so as to analyze the new literals properly. Then build a
+ -- subtype declaration tree which applies the constraint (if any)
+ -- and have it replace the derived type declaration.
Literal := First_Literal (Parent_Type);
Literals_List := New_List;
@@ -7450,8 +7451,7 @@ package body Sem_Ch3 is
end loop;
Implicit_Base :=
- Make_Defining_Identifier (Sloc (Derived_Type),
- Chars => New_External_Name (Chars (Derived_Type), 'B'));
+ Create_Itype (E_Enumeration_Type, N, Derived_Type, 'B');
-- Indicate the proper nature of the derived type. This must be done
-- before analysis of the literals, to recognize cases when a literal
@@ -7464,12 +7464,12 @@ package body Sem_Ch3 is
Type_Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Implicit_Base,
- Discriminant_Specifications => No_List,
Type_Definition =>
Make_Enumeration_Type_Definition (Loc, Literals_List));
- Mark_Rewrite_Insertion (Type_Decl);
- Insert_Before (N, Type_Decl);
+ -- Do not insert the declarationn, just analyze it in the context
+
+ Set_Parent (Type_Decl, Parent (N));
Analyze (Type_Decl);
-- The anonymous base now has a full declaration, but this base
@@ -7770,35 +7770,6 @@ package body Sem_Ch3 is
-- must be converted to the derived type.
Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
-
- -- The implicit_base should be frozen when the derived type is frozen,
- -- but note that it is used in the conversions of the bounds. For fixed
- -- types we delay the determination of the bounds until the proper
- -- freezing point. For other numeric types this is rejected by GCC, for
- -- reasons that are currently unclear (???), so we choose to freeze the
- -- implicit base now. In the case of integers and floating point types
- -- this is harmless because subsequent representation clauses cannot
- -- affect anything, but it is still baffling that we cannot use the
- -- same mechanism for all derived numeric types.
-
- -- There is a further complication: actually some representation
- -- clauses can affect the implicit base type. For example, attribute
- -- definition clauses for stream-oriented attributes need to set the
- -- corresponding TSS entries on the base type, and this normally
- -- cannot be done after the base type is frozen, so the circuitry in
- -- Sem_Ch13.New_Stream_Subprogram must account for this possibility
- -- and not use Set_TSS in this case.
-
- -- There are also consequences for the case of delayed representation
- -- aspects for some cases. For example, a Size aspect is delayed and
- -- should not be evaluated to the freeze point. This early freezing
- -- means that the size attribute evaluation happens too early???
-
- if Is_Fixed_Point_Type (Parent_Type) then
- Conditional_Delay (Implicit_Base, Parent_Type);
- else
- Freeze_Before (N, Implicit_Base);
- end if;
end Build_Derived_Numeric_Type;
--------------------------------
@@ -14443,14 +14414,18 @@ package body Sem_Ch3 is
begin
Mutate_Ekind (Def_Id, E_Enumeration_Subtype);
- Set_First_Literal (Def_Id, First_Literal (Base_Type (T)));
+ Set_First_Literal (Def_Id, First_Literal (Base_Type (T)));
+ Set_Etype (Def_Id, Base_Type (T));
+ Set_Size_Info (Def_Id, (T));
+ Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
+ Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
- Set_Etype (Def_Id, Base_Type (T));
- Set_Size_Info (Def_Id, (T));
- Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
- Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
+ -- Inherit the chain of representation items instead of replacing it
+ -- because Build_Derived_Enumeration_Type rewrites the declaration of
+ -- the derived type as a subtype declaration and the former needs to
+ -- preserve existing representation items (see Build_Derived_Type).
- Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
+ Inherit_Rep_Item_Chain (Def_Id, T);
Set_Discrete_RM_Size (Def_Id);
end Constrain_Enumeration;
@@ -16992,11 +16967,9 @@ package body Sem_Ch3 is
Low_Bound => Lo,
High_Bound => Hi));
- Conditional_Delay (Derived_Type, Parent_Type);
-
- Mutate_Ekind (Derived_Type, E_Enumeration_Subtype);
- Set_Etype (Derived_Type, Implicit_Base);
- Set_Size_Info (Derived_Type, Parent_Type);
+ Mutate_Ekind (Derived_Type, E_Enumeration_Subtype);
+ Set_Etype (Derived_Type, Implicit_Base);
+ Set_Size_Info (Derived_Type, Parent_Type);
if not Known_RM_Size (Derived_Type) then
Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
@@ -17015,16 +16988,6 @@ package body Sem_Ch3 is
end if;
Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
-
- -- Because the implicit base is used in the conversion of the bounds, we
- -- have to freeze it now. This is similar to what is done for numeric
- -- types, and it equally suspicious, but otherwise a nonstatic bound
- -- will have a reference to an unfrozen type, which is rejected by Gigi
- -- (???). This requires specific care for definition of stream
- -- attributes. For details, see comments at the end of
- -- Build_Derived_Numeric_Type.
-
- Freeze_Before (N, Implicit_Base);
end Derived_Standard_Character;
------------------------------