diff options
author | Bob Duff <duff@adacore.com> | 2021-06-15 09:12:36 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2021-07-12 12:50:57 +0000 |
commit | 0c8ff35eb982a49882ed71b1b85e8436675adf88 (patch) | |
tree | 71b6ac19dfcaef9f49b23a1221eac331546922cb /gcc/ada | |
parent | 5cb3843bca9a28c28dbc1fafd88c144a43e141df (diff) | |
download | gcc-0c8ff35eb982a49882ed71b1b85e8436675adf88.zip gcc-0c8ff35eb982a49882ed71b1b85e8436675adf88.tar.gz gcc-0c8ff35eb982a49882ed71b1b85e8436675adf88.tar.bz2 |
[Ada] Clean up Uint fields
gcc/ada/
* uintp.ads, types.h: New subtypes of Uint: Valid_Uint, Unat,
Upos, Nonzero_Uint with predicates. These correspond to new
field types in Gen_IL.
* gen_il-types.ads (Valid_Uint, Unat, Upos, Nonzero_Uint): New
field types.
* einfo-utils.ads, einfo-utils.adb, fe.h (Known_Alignment,
Init_Alignment): Use the initial zero value to represent
"unknown". This will ensure that if Alignment is called before
Set_Alignment, the compiler will blow up (if assertions are
enabled).
* atree.ads, atree.adb, atree.h, gen_il-gen.adb
(Get_Valid_32_Bit_Field): New generic low-level getter for
subtypes of Uint.
(Copy_Alignment): New procedure to copy Alignment field even
when Unknown.
(Init_Object_Size_Align, Init_Size_Align): Do not bypass the
Init_ procedures.
* exp_pakd.adb, freeze.adb, layout.adb, repinfo.adb,
sem_util.adb: Protect calls to Alignment with Known_Alignment.
Use Copy_Alignment when it might be unknown.
* gen_il-gen-gen_entities.adb (Alignment,
String_Literal_Length): Use type Unat instead of Uint, to ensure
that the field is always Set_ before we get it, and that it is
set to a nonnegative value.
(Enumeration_Pos): Unat.
(Enumeration_Rep): Valid_Uint. Can be negative, but must be
valid before fetching.
(Discriminant_Number): Upos.
(Renaming_Map): Remove.
* gen_il-gen-gen_nodes.adb (Char_Literal_Value, Reason): Unat.
(Intval, Corresponding_Integer_Value): Valid_Uint.
* gen_il-internals.ads: New functions for dealing with special
defaults and new subtypes of Uint.
* scans.ads: Correct comments.
* scn.adb (Post_Scan): Do not set Intval to No_Uint; that is no
longer allowed.
* sem_ch13.adb (Analyze_Enumeration_Representation_Clause): Do
not set Enumeration_Rep to No_Uint; that is no longer allowed.
(Offset_Value): Protect calls to Alignment with Known_Alignment.
* sem_prag.adb (Set_Atomic_VFA): Do not use Uint_0 to mean
"unknown"; call Init_Alignment instead.
* sinfo.ads: Minor comment fix.
* treepr.adb: Deal with printing of new field types.
* einfo.ads, gen_il-fields.ads (Renaming_Map): Remove.
* gcc-interface/decl.c (gnat_to_gnu_entity): Use Known_Alignment
before calling Alignment. This preserve some probably buggy
behavior: if the alignment is not set, it previously defaulted
to Uint_0; we now make that explicit. Use Copy_Alignment,
because "Set_Alignment (Y, Alignment (X));" no longer works when
the Alignment of X has not yet been set.
* gcc-interface/trans.c (process_freeze_entity): Use
Copy_Alignment.
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/atree.adb | 24 | ||||
-rw-r--r-- | gcc/ada/atree.ads | 8 | ||||
-rw-r--r-- | gcc/ada/atree.h | 9 | ||||
-rw-r--r-- | gcc/ada/einfo-utils.adb | 25 | ||||
-rw-r--r-- | gcc/ada/einfo-utils.ads | 7 | ||||
-rw-r--r-- | gcc/ada/einfo.ads | 12 | ||||
-rw-r--r-- | gcc/ada/exp_pakd.adb | 4 | ||||
-rw-r--r-- | gcc/ada/fe.h | 3 | ||||
-rw-r--r-- | gcc/ada/freeze.adb | 12 | ||||
-rw-r--r-- | gcc/ada/gcc-interface/decl.c | 8 | ||||
-rw-r--r-- | gcc/ada/gcc-interface/trans.c | 2 | ||||
-rw-r--r-- | gcc/ada/gen_il-fields.ads | 1 | ||||
-rw-r--r-- | gcc/ada/gen_il-gen-gen_entities.adb | 27 | ||||
-rw-r--r-- | gcc/ada/gen_il-gen-gen_nodes.adb | 12 | ||||
-rw-r--r-- | gcc/ada/gen_il-gen.adb | 72 | ||||
-rw-r--r-- | gcc/ada/gen_il-internals.ads | 21 | ||||
-rw-r--r-- | gcc/ada/gen_il-types.ads | 19 | ||||
-rw-r--r-- | gcc/ada/layout.adb | 2 | ||||
-rw-r--r-- | gcc/ada/repinfo.adb | 24 | ||||
-rw-r--r-- | gcc/ada/scans.ads | 6 | ||||
-rw-r--r-- | gcc/ada/scn.adb | 9 | ||||
-rw-r--r-- | gcc/ada/sem_ch13.adb | 26 | ||||
-rw-r--r-- | gcc/ada/sem_prag.adb | 2 | ||||
-rw-r--r-- | gcc/ada/sem_util.adb | 4 | ||||
-rw-r--r-- | gcc/ada/sinfo.ads | 12 | ||||
-rw-r--r-- | gcc/ada/treepr.adb | 43 | ||||
-rw-r--r-- | gcc/ada/types.h | 4 | ||||
-rw-r--r-- | gcc/ada/uintp.ads | 5 |
28 files changed, 268 insertions, 135 deletions
diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb index 33cde5a..c7e295b 100644 --- a/gcc/ada/atree.adb +++ b/gcc/ada/atree.adb @@ -25,7 +25,7 @@ -- Assertions in this package are too slow, and are mostly needed when working -- on this package itself, or on gen_il, so we disable them. --- To debug low-level bugs in this area, comment out the following pragmas, +-- To debug low-level bugs in this area, comment out the following pragma, -- and run with -gnatd_v. pragma Assertion_Policy (Ignore); @@ -521,19 +521,37 @@ package body Atree is (N : Node_Or_Entity_Id; Offset : Field_Offset) return Field_Type is function Get_Field is new Get_32_Bit_Field (Field_Type) with Inline; + Result : Field_Type; begin -- If the field has not yet been set, it will be equal to zero. -- That is of the "wrong" type, so we fetch it as a -- Field_Size_32_Bit. if Get_32_Bit_Val (N, Offset) = 0 then - return Default_Val; + Result := Default_Val; else - return Get_Field (N, Offset); + Result := Get_Field (N, Offset); end if; + + return Result; end Get_32_Bit_Field_With_Default; + function Get_Valid_32_Bit_Field + (N : Node_Or_Entity_Id; Offset : Field_Offset) return Field_Type + is + pragma Assert (Get_32_Bit_Val (N, Offset) /= 0); + -- If the field has not yet been set, it will be equal to zero. + -- This asserts that we don't call Get_ before Set_. Note that + -- the predicate on the Val parameter of Set_ checks for the No_... + -- value, so it can't possibly be (for example) No_Uint here. + + function Get_Field is new Get_32_Bit_Field (Field_Type) with Inline; + Result : constant Field_Type := Get_Field (N, Offset); + begin + return Result; + end Get_Valid_32_Bit_Field; + procedure Set_1_Bit_Field (N : Node_Or_Entity_Id; Offset : Field_Offset; Val : Field_Type) is diff --git a/gcc/ada/atree.ads b/gcc/ada/atree.ads index 42df950..6fb5aa6 100644 --- a/gcc/ada/atree.ads +++ b/gcc/ada/atree.ads @@ -764,6 +764,14 @@ package Atree is generic type Field_Type is private; + function Get_Valid_32_Bit_Field + (N : Node_Or_Entity_Id; Offset : Field_Offset) return Field_Type + with Inline; + -- Assert that the field has already been set. This is currently used + -- only for Uints, but could be used more generally. + + generic + type Field_Type is private; procedure Set_1_Bit_Field (N : Node_Or_Entity_Id; Offset : Field_Offset; Val : Field_Type) with Inline; diff --git a/gcc/ada/atree.h b/gcc/ada/atree.h index e4750e1..08b791c 100644 --- a/gcc/ada/atree.h +++ b/gcc/ada/atree.h @@ -79,6 +79,7 @@ INLINE unsigned int Get_8_Bit_Field (Node_Id, Field_Offset); INLINE unsigned int Get_32_Bit_Field (Node_Id, Field_Offset); INLINE unsigned int Get_32_Bit_Field_With_Default (Node_Id, Field_Offset, unsigned int); +INLINE unsigned int Get_Valid_32_Bit_Field (Node_Id, Field_Offset); INLINE unsigned int Get_1_Bit_Field (Node_Id N, Field_Offset Offset) @@ -127,6 +128,14 @@ Get_32_Bit_Field_With_Default (Node_Id N, Field_Offset Offset, return slot == Empty ? Default_Value : slot; } +INLINE unsigned int +Get_Valid_32_Bit_Field (Node_Id N, Field_Offset Offset) +{ + any_slot slot = *(Slots_Ptr + Node_Offsets_Ptr[N] + Offset); + gcc_assert (slot != Empty); + return slot; +} + #ifdef __cplusplus } #endif diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb index 21d7bfb..4690c8f 100644 --- a/gcc/ada/einfo-utils.adb +++ b/gcc/ada/einfo-utils.adb @@ -364,7 +364,7 @@ package body Einfo.Utils is procedure Init_Alignment (Id : E) is begin - Set_Alignment (Id, Uint_0); + Reinit_Field_To_Zero (Id, F_Alignment); end Init_Alignment; procedure Init_Alignment (Id : E; V : Int) is @@ -452,6 +452,15 @@ package body Einfo.Utils is Set_RM_Size (Id, UI_From_Int (V)); end Init_RM_Size; + procedure Copy_Alignment (To, From : E) is + begin + if Known_Alignment (From) then + Set_Alignment (To, Alignment (From)); + else + Init_Alignment (To); + end if; + end Copy_Alignment; + ----------------------------- -- Init_Component_Location -- ----------------------------- @@ -471,8 +480,8 @@ package body Einfo.Utils is procedure Init_Object_Size_Align (Id : E) is begin - Set_Esize (Id, Uint_0); - Set_Alignment (Id, Uint_0); + Init_Esize (Id); + Init_Alignment (Id); end Init_Object_Size_Align; --------------- @@ -499,9 +508,9 @@ package body Einfo.Utils is procedure Init_Size_Align (Id : E) is begin pragma Assert (Ekind (Id) in Type_Kind | E_Void); - Set_Esize (Id, Uint_0); - Set_RM_Size (Id, Uint_0); - Set_Alignment (Id, Uint_0); + Init_Esize (Id); + Init_RM_Size (Id); + Init_Alignment (Id); end Init_Size_Align; ---------------------------------------------- @@ -509,9 +518,9 @@ package body Einfo.Utils is ---------------------------------------------- function Known_Alignment (E : Entity_Id) return B is + Result : constant B := not Field_Is_Initial_Zero (E, F_Alignment); begin - return Alignment (E) /= Uint_0 - and then Alignment (E) /= No_Uint; + return Result; end Known_Alignment; function Known_Component_Bit_Offset (E : Entity_Id) return B is diff --git a/gcc/ada/einfo-utils.ads b/gcc/ada/einfo-utils.ads index dbf3ad6..a6517b9 100644 --- a/gcc/ada/einfo-utils.ads +++ b/gcc/ada/einfo-utils.ads @@ -454,6 +454,13 @@ package Einfo.Utils is procedure Init_Normalized_Position_Max (Id : E); procedure Init_RM_Size (Id : E); + -- The following Copy_xxx procedures copy the value of xxx from From to + -- To. If xxx is set to its initial invalid (zero-bits) value, then it is + -- reset to invalid in To. We only have Copy_Alignment so far, but more are + -- planned. + + procedure Copy_Alignment (To, From : E); + pragma Inline (Init_Alignment); pragma Inline (Init_Component_Bit_Offset); pragma Inline (Init_Component_Size); diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index 6a8d493..e87ce4c 100644 --- a/gcc/ada/einfo.ads +++ b/gcc/ada/einfo.ads @@ -4173,15 +4173,6 @@ package Einfo is -- within an accept statement. For all remaining cases (discriminants, -- loop parameters) the field is Empty. --- Renaming_Map --- Defined in generic subprograms, generic packages, and their --- instances. Also defined in the instances of the corresponding --- bodies. Denotes the renaming map (generic entities => instance --- entities) used to construct the instance by giving an index into --- the tables used to represent these maps. See Sem_Ch12 for further --- details. The maps for package instances are also used when the --- instance is the actual corresponding to a formal 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 @@ -5474,7 +5465,6 @@ package Einfo is -- E_Function -- E_Generic_Function -- Mechanism (Mechanism_Type) - -- Renaming_Map -- Handler_Records (non-generic case only) -- Protected_Body_Subprogram -- Next_Inlined_Subprogram @@ -5734,7 +5724,6 @@ package Einfo is -- E_Package -- E_Generic_Package -- Dependent_Instances (for an instance) - -- Renaming_Map -- Handler_Records (non-generic case only) -- Generic_Homonym (generic case only) -- Associated_Formal_Package @@ -5832,7 +5821,6 @@ package Einfo is -- E_Procedure -- E_Generic_Procedure -- Associated_Node_For_Itype $$$ E_Procedure - -- Renaming_Map -- Handler_Records (non-generic case only) -- Protected_Body_Subprogram -- Next_Inlined_Subprogram diff --git a/gcc/ada/exp_pakd.adb b/gcc/ada/exp_pakd.adb index 47919fc..88f86f4 100644 --- a/gcc/ada/exp_pakd.adb +++ b/gcc/ada/exp_pakd.adb @@ -613,7 +613,7 @@ package body Exp_Pakd is -- type or component, take it into account. if Csize <= 2 or else Csize = 4 or else Csize mod 2 /= 0 - or else Alignment (Typ) = 1 + or else (Known_Alignment (Typ) and then Alignment (Typ) = 1) or else Component_Alignment (Typ) = Calign_Storage_Unit then if Reverse_Storage_Order (Typ) then @@ -623,7 +623,7 @@ package body Exp_Pakd is end if; elsif Csize mod 4 /= 0 - or else Alignment (Typ) = 2 + or else (Known_Alignment (Typ) and then Alignment (Typ) = 2) then if Reverse_Storage_Order (Typ) then PB_Type := RTE (RE_Rev_Packed_Bytes2); diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h index d7ab361b..4517c59 100644 --- a/gcc/ada/fe.h +++ b/gcc/ada/fe.h @@ -636,6 +636,9 @@ B Known_Static_Normalized_Position_Max (Entity_Id E); #define Known_Static_RM_Size einfo__utils__known_static_rm_size B Known_Static_RM_Size (Entity_Id E); +#define Copy_Alignment einfo__utils__copy_alignment +B Copy_Alignment(Entity_Id To, Entity_Id From); + #define Is_Discrete_Or_Fixed_Point_Type einfo__utils__is_discrete_or_fixed_point_type B Is_Discrete_Or_Fixed_Point_Type (E Id); diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index 12d10ee..84502d8 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -3307,7 +3307,7 @@ package body Freeze is -- cases of types whose alignment exceeds their size (the -- padded type cases). - if Csiz /= 0 then + if Csiz /= 0 and then Known_Alignment (Ctyp) then declare A : constant Uint := Alignment_In_Bits (Ctyp); begin @@ -3478,9 +3478,12 @@ package body Freeze is -- Processing that is done only for subtypes else - -- Acquire alignment from base type + -- Acquire alignment from base type. Known_Alignment of the base + -- type is False for Wide_String, for example. - if not Known_Alignment (Arr) then + if not Known_Alignment (Arr) + and then Known_Alignment (Base_Type (Arr)) + then Set_Alignment (Arr, Alignment (Base_Type (Arr))); Adjust_Esize_Alignment (Arr); end if; @@ -3642,7 +3645,8 @@ package body Freeze is end if; if not Has_Alignment_Clause (Arr) then - Set_Alignment (Arr, Alignment (Packed_Array_Impl_Type (Arr))); + Copy_Alignment + (To => Arr, From => Packed_Array_Impl_Type (Arr)); end if; end if; diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index b09e20d..83ca31a 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -4417,9 +4417,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) const bool derived_p = Is_Derived_Type (gnat_entity); const Entity_Id gnat_parent = derived_p ? Etype (Base_Type (gnat_entity)) : Empty; + /* The following test for Known_Alignment preserves the old behavior, + but is probably wrong. */ const unsigned int inherited_align = derived_p - ? UI_To_Int (Alignment (gnat_parent)) * BITS_PER_UNIT + ? (Known_Alignment (gnat_parent) + ? UI_To_Int (Alignment (gnat_parent)) * BITS_PER_UNIT + : 0) : POINTER_SIZE; const unsigned int align = MAX (TYPE_ALIGN (gnu_type), inherited_align); @@ -4724,7 +4728,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) && Present (gnat_annotate_type)) { if (!Known_Alignment (gnat_entity)) - Set_Alignment (gnat_entity, Alignment (gnat_annotate_type)); + Copy_Alignment (gnat_entity, gnat_annotate_type); if (!Known_Esize (gnat_entity)) Set_Esize (gnat_entity, Esize (gnat_annotate_type)); if (!Known_RM_Size (gnat_entity)) diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 8f8bc70..f61183d 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -9274,7 +9274,7 @@ process_freeze_entity (Node_Id gnat_node) /* Propagate back-annotations from full view to partial view. */ if (!Known_Alignment (gnat_entity)) - Set_Alignment (gnat_entity, Alignment (full_view)); + Copy_Alignment (gnat_entity, full_view); if (!Known_Esize (gnat_entity)) Set_Esize (gnat_entity, Esize (full_view)); diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads index e2592ee..0a3046e 100644 --- a/gcc/ada/gen_il-fields.ads +++ b/gcc/ada/gen_il-fields.ads @@ -868,7 +868,6 @@ package Gen_IL.Fields is Relative_Deadline_Variable, Renamed_In_Spec, Renamed_Or_Alias, -- Shared among Alias, Renamed_Entity, Renamed_Object - Renaming_Map, Requires_Overriding, Return_Applies_To, Return_Present, diff --git a/gcc/ada/gen_il-gen-gen_entities.adb b/gcc/ada/gen_il-gen-gen_entities.adb index d5977ad..41dd232 100644 --- a/gcc/ada/gen_il-gen-gen_entities.adb +++ b/gcc/ada/gen_il-gen-gen_entities.adb @@ -246,7 +246,7 @@ begin -- Gen_IL.Gen.Gen_Entities -- dummy type for the return type of a procedure (the reason we create -- this type is to share the circuits for performing overload -- resolution on calls). - (Sm (Alignment, Uint), + (Sm (Alignment, Unat), Sm (Contract, Node_Id), Sm (Is_Elaboration_Warnings_OK_Id, Flag), Sm (Original_Record_Component, Node_Id), @@ -272,7 +272,7 @@ begin -- Gen_IL.Gen.Gen_Entities Sm (Debug_Renaming_Link, Node_Id), Sm (Discriminal_Link, Node_Id), Sm (Discriminant_Default_Value, Node_Id), - Sm (Discriminant_Number, Uint), + Sm (Discriminant_Number, Upos), Sm (Enclosing_Scope, Node_Id), Sm (Entry_Bodies_Array, Node_Id, Pre => "Has_Entries (N)"), @@ -293,7 +293,6 @@ begin -- Gen_IL.Gen.Gen_Entities Sm (Last_Entity, Node_Id), Sm (Next_Inlined_Subprogram, Node_Id), Sm (Renamed_Or_Alias, Node_Id), -- See Einfo.Utils - Sm (Renaming_Map, Uint), Sm (Return_Applies_To, Node_Id), Sm (Scalar_Range, Node_Id), Sm (Scale_Value, Uint), @@ -334,7 +333,7 @@ begin -- Gen_IL.Gen.Gen_Entities Ab (Allocatable_Kind, Object_Kind, (Sm (Activation_Record_Component, Node_Id), - Sm (Alignment, Uint), + Sm (Alignment, Unat), Sm (Esize, Uint), Sm (Interface_Name, Node_Id), Sm (Is_Finalized_Transient, Flag), @@ -374,7 +373,7 @@ begin -- Gen_IL.Gen.Gen_Entities Sm (CR_Discriminant, Node_Id), Sm (Discriminal, Node_Id), Sm (Discriminant_Default_Value, Node_Id), - Sm (Discriminant_Number, Uint), + Sm (Discriminant_Number, Upos), Sm (Is_Completely_Hidden, Flag))); Cc (E_Loop_Parameter, Allocatable_Kind); @@ -400,7 +399,7 @@ begin -- Gen_IL.Gen.Gen_Entities -- Formal parameters are also objects (Sm (Activation_Record_Component, Node_Id), Sm (Actual_Subtype, Node_Id), - Sm (Alignment, Uint), + Sm (Alignment, Unat), Sm (Default_Expr_Function, Node_Id), Sm (Default_Value, Node_Id), Sm (Entry_Component, Node_Id), @@ -456,7 +455,7 @@ begin -- Gen_IL.Gen.Gen_Entities -- Named numbers created by a number declaration with a real value Ab (Type_Kind, Void_Or_Type_Kind, - (Sm (Alignment, Uint), + (Sm (Alignment, Unat), Sm (Associated_Node_For_Itype, Node_Id), Sm (Can_Use_Internal_Rep, Flag, Base_Type_Only, Pre => "Ekind (Base_Type (N)) in Access_Subprogram_Kind"), @@ -745,7 +744,7 @@ begin -- Gen_IL.Gen.Gen_Entities Cc (E_String_Literal_Subtype, Array_Kind, -- A special string subtype, used only to describe the type of a string -- literal (will always be one dimensional, with literal bounds). - (Sm (String_Literal_Length, Uint), + (Sm (String_Literal_Length, Unat), Sm (String_Literal_Low_Bound, Node_Id))); Ab (Class_Wide_Kind, Aggregate_Kind, @@ -970,11 +969,11 @@ begin -- Gen_IL.Gen.Gen_Entities Cc (E_Enumeration_Literal, Overloadable_Kind, -- An enumeration literal, created by the use of the literal in an -- enumeration type definition. - (Sm (Enumeration_Pos, Uint), - Sm (Enumeration_Rep, Uint), + (Sm (Enumeration_Pos, Unat), + Sm (Enumeration_Rep, Valid_Uint), Sm (Enumeration_Rep_Expr, Node_Id), Sm (Esize, Uint), - Sm (Alignment, Uint), + Sm (Alignment, Unat), Sm (Interface_Name, Node_Id))); Ab (Subprogram_Kind, Overloadable_Kind, @@ -1039,7 +1038,6 @@ begin -- Gen_IL.Gen.Gen_Entities Sm (Protected_Subprogram, Node_Id), Sm (Protection_Object, Node_Id), Sm (Related_Expression, Node_Id), - Sm (Renaming_Map, Uint), Sm (Rewritten_For_C, Flag), Sm (Thunk_Entity, Node_Id, Pre => "Is_Thunk (N)"), @@ -1089,7 +1087,6 @@ begin -- Gen_IL.Gen.Gen_Entities Sm (Protected_Subprogram, Node_Id), Sm (Protection_Object, Node_Id), Sm (Receiving_Entry, Node_Id), - Sm (Renaming_Map, Uint), Sm (Static_Initialization, Node_Id, Pre => "not Is_Dispatching_Operation (N)"), Sm (Thunk_Entity, Node_Id, @@ -1184,7 +1181,7 @@ begin -- Gen_IL.Gen.Gen_Entities -- An exception created by an exception declaration. The exception -- itself uses E_Exception for the Ekind, the implicit type that is -- created to represent its type uses the Ekind E_Exception_Type. - (Sm (Alignment, Uint), + (Sm (Alignment, Unat), Sm (Esize, Uint), Sm (Interface_Name, Node_Id), Sm (Is_Raised, Flag), @@ -1204,7 +1201,6 @@ begin -- Gen_IL.Gen.Gen_Entities Sm (Is_Elaboration_Warnings_OK_Id, Flag), Sm (Last_Entity, Node_Id), Sm (Renamed_Or_Alias, Node_Id), - Sm (Renaming_Map, Uint), Sm (Scope_Depth_Value, Uint), Sm (SPARK_Pragma, Node_Id), Sm (SPARK_Pragma_Inherited, Flag))); @@ -1299,7 +1295,6 @@ begin -- Gen_IL.Gen.Gen_Entities Sm (Related_Instance, Node_Id), Sm (Renamed_In_Spec, Flag), Sm (Renamed_Or_Alias, Node_Id), - Sm (Renaming_Map, Uint), Sm (Scope_Depth_Value, Uint), Sm (SPARK_Aux_Pragma, Node_Id), Sm (SPARK_Aux_Pragma_Inherited, Flag), diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb index 2427a1e..55ba71d 100644 --- a/gcc/ada/gen_il-gen-gen_nodes.adb +++ b/gcc/ada/gen_il-gen-gen_nodes.adb @@ -193,7 +193,7 @@ begin -- Gen_IL.Gen.Gen_Nodes Cc (N_Character_Literal, N_Direct_Name, (Sy (Chars, Name_Id, Default_No_Name), - Sy (Char_Literal_Value, Uint))); + Sy (Char_Literal_Value, Unat))); Ab (N_Op, N_Has_Entity, (Sm (Do_Overflow_Check, Flag), @@ -412,26 +412,26 @@ begin -- Gen_IL.Gen.Gen_Nodes Cc (N_Raise_Constraint_Error, N_Raise_xxx_Error, (Sy (Condition, Node_Id, Default_Empty), - Sy (Reason, Uint))); + Sy (Reason, Unat))); Cc (N_Raise_Program_Error, N_Raise_xxx_Error, (Sy (Condition, Node_Id, Default_Empty), - Sy (Reason, Uint))); + Sy (Reason, Unat))); Cc (N_Raise_Storage_Error, N_Raise_xxx_Error, (Sy (Condition, Node_Id, Default_Empty), - Sy (Reason, Uint))); + Sy (Reason, Unat))); Ab (N_Numeric_Or_String_Literal, N_Subexpr); Cc (N_Integer_Literal, N_Numeric_Or_String_Literal, - (Sy (Intval, Uint), + (Sy (Intval, Valid_Uint), Sm (Original_Entity, Node_Id), Sm (Print_In_Hex, Flag))); Cc (N_Real_Literal, N_Numeric_Or_String_Literal, (Sy (Realval, Ureal), - Sm (Corresponding_Integer_Value, Uint), + Sm (Corresponding_Integer_Value, Valid_Uint), Sm (Is_Machine_Number, Flag), Sm (Original_Entity, Node_Id))); diff --git a/gcc/ada/gen_il-gen.adb b/gcc/ada/gen_il-gen.adb index 94f7c9c..a9c7bd7 100644 --- a/gcc/ada/gen_il-gen.adb +++ b/gcc/ada/gen_il-gen.adb @@ -849,6 +849,7 @@ package body Gen_IL.Gen is | Name_Id | String_Id | Uint + | Uint_Subtype | Ureal | Source_Ptr | Union_Id @@ -1562,22 +1563,25 @@ package body Gen_IL.Gen is (S : in out Sink; T : Type_Enum) is begin - -- Special case for types that have defaults; instantiate - -- Get_32_Bit_Field_With_Default and pass in the Default_Val. + -- Special case for subtypes of Uint that have predicates. Use + -- Get_Valid_32_Bit_Field in that case. - if T in Elist_Id | Uint then + if T in Uint_Subtype then pragma Assert (Field_Size (T) = 32); + Put (S, LF & "function " & Low_Level_Getter_Name (T) & + " is new Get_Valid_32_Bit_Field (" & + Get_Set_Id_Image (T) & + ") with " & Inline & ";" & LF); - declare - Default_Val : constant String := - (if T = Elist_Id then "No_Elist" else "Uint_0"); + -- Special case for types that have special defaults; instantiate + -- Get_32_Bit_Field_With_Default and pass in the Default_Val. - begin - Put (S, LF & "function " & Low_Level_Getter_Name (T) & - " is new Get_32_Bit_Field_With_Default (" & - Get_Set_Id_Image (T) & ", " & Default_Val & - ") with " & Inline & ";" & LF); - end; + elsif Field_Has_Special_Default (T) then + pragma Assert (Field_Size (T) = 32); + Put (S, LF & "function " & Low_Level_Getter_Name (T) & + " is new Get_32_Bit_Field_With_Default (" & + Get_Set_Id_Image (T) & ", " & Special_Default (T) & + ") with " & Inline & ";" & LF); -- Otherwise, instantiate the normal getter for the right size in -- bits. @@ -1588,16 +1592,16 @@ package body Gen_IL.Gen is Get_Set_Id_Image (T) & ") with " & Inline & ";" & LF); end if; - -- No special case for the setter - if T in Node_Kind_Type | Entity_Kind_Type then Put (S, "pragma Warnings (Off);" & LF); -- Set_Node_Kind_Type and Set_Entity_Kind_Type might not be called end if; + -- No special cases for the setter + Put (S, "procedure " & Low_Level_Setter_Name (T) & " is new Set_" & - Image (Field_Size (T)) & "_Bit_Field (" & Get_Set_Id_Image (T) & - ") with " & Inline & ";" & LF); + Image (Field_Size (T)) & "_Bit_Field (" & Get_Set_Id_Image (T) & + ") with " & Inline & ";" & LF); if T in Node_Kind_Type | Entity_Kind_Type then Put (S, "pragma Warnings (On);" & LF); @@ -1689,11 +1693,9 @@ package body Gen_IL.Gen is procedure Put_Getter_Spec (S : in out Sink; F : Field_Enum) is begin - Put (S, "function " & Image (F) & LF); - Increase_Indent (S, 2); - Put (S, "(N : " & N_Type (F) & ") return " & + Put (S, "function " & Image (F)); + Put (S, " (N : " & N_Type (F) & ") return " & Get_Set_Id_Image (Field_Table (F).Field_Type)); - Decrease_Indent (S, 2); end Put_Getter_Spec; --------------------- @@ -1757,11 +1759,9 @@ package body Gen_IL.Gen is Default : constant String := (if Rec.Field_Type = Flag then " := True" else ""); begin - Put (S, "procedure Set_" & Image (F) & LF); - Increase_Indent (S, 2); - Put (S, "(N : " & N_Type (F) & "; Val : " & + Put (S, "procedure Set_" & Image (F)); + Put (S, " (N : " & N_Type (F) & "; Val : " & Get_Set_Id_Image (Rec.Field_Type) & Default & ")"); - Decrease_Indent (S, 2); end Put_Setter_Spec; --------------------- @@ -2776,7 +2776,8 @@ package body Gen_IL.Gen is Put (S, "-- This package is not used by the compiler." & LF); Put (S, "-- The body contains tables that are intended to be used by humans to" & LF); - Put (S, "-- help understand the layout of various data structures." & LF & LF); + Put (S, "-- help understand the layout of various data structures." & LF); + Put (S, "-- Search for ""--"" to find major sections of code." & LF & LF); Put (S, "pragma Elaborate_Body;" & LF); @@ -3001,20 +3002,19 @@ package body Gen_IL.Gen is Increase_Indent (S, 3); - -- Same special case as in Put_Low_Level_Accessor_Instantiations + -- Same special cases for getters as in + -- Put_Low_Level_Accessor_Instantiations. - if T in Elist_Id | Uint then + if T in Uint_Subtype then pragma Assert (Field_Size (T) = 32); + Put (S, "{ return (" & T_Image & + ") Get_Valid_32_Bit_Field(N, Offset); }" & LF & LF); - declare - Default_Val : constant String := - (if T = Elist_Id then "No_Elist" else "Uint_0"); - - begin - Put (S, "{ return (" & T_Image & - ") Get_32_Bit_Field_With_Default(N, Offset, " & - Default_Val & "); }" & LF & LF); - end; + elsif Field_Has_Special_Default (T) then + pragma Assert (Field_Size (T) = 32); + Put (S, "{ return (" & T_Image & + ") Get_32_Bit_Field_With_Default(N, Offset, " & + Special_Default (T) & "); }" & LF & LF); else Put (S, "{ return (" & T_Image & ") Get_" & diff --git a/gcc/ada/gen_il-internals.ads b/gcc/ada/gen_il-internals.ads index b8911ec..ae448de 100644 --- a/gcc/ada/gen_il-internals.ads +++ b/gcc/ada/gen_il-internals.ads @@ -174,6 +174,27 @@ package Gen_IL.Internals is -- Table mapping from enumeration literals representing fields to -- information about the field. + -- Getters for fields of types Elist_Id and Uint need special treatment of + -- defaults. In particular, if the field has its initial 0 value, getters + -- need to return the appropriate default value. Note that these defaults + -- have nothing to do with the defaults mentioned above for Nmake + -- functions. + + function Field_Has_Special_Default + (Field_Type : Type_Enum) return Boolean is + (Field_Type in Elist_Id | Uint); + -- These are the field types that have a default value that is not + -- represented as zero. + + function Special_Default + (Field_Type : Type_Enum) return String is + (if Field_Type = Elist_Id then "No_Elist" else "Uint_0"); + + function Invalid_Val + (Field_Type : Uint_Subtype) return String is + ("No_Uint"); + -- We could generalize this to other than Uint at some point + ---------------- subtype Node_Field is diff --git a/gcc/ada/gen_il-types.ads b/gcc/ada/gen_il-types.ads index 84eb63f..321eec6 100644 --- a/gcc/ada/gen_il-types.ads +++ b/gcc/ada/gen_il-types.ads @@ -55,6 +55,10 @@ package Gen_IL.Types is Name_Id, String_Id, Uint, + Valid_Uint, + Unat, + Upos, + Nonzero_Uint, Ureal, Node_Kind_Type, -- Type of result of Nkind function, i.e. Node_Kind @@ -562,14 +566,17 @@ package Gen_IL.Types is | N_Defining_Operator_Symbol; subtype Opt_Abstract_Type is Opt_Type_Enum with - Predicate => Opt_Abstract_Type = No_Type or - Opt_Abstract_Type in Abstract_Type; + Predicate => Opt_Abstract_Type = No_Type or + Opt_Abstract_Type in Abstract_Type; subtype Type_Boundaries is Type_Enum with - Predicate => Type_Boundaries in - Between_Abstract_Node_And_Abstract_Entity_Types | - Between_Abstract_Entity_And_Concrete_Node_Types | - Between_Concrete_Node_And_Concrete_Entity_Types; + Predicate => Type_Boundaries in + Between_Abstract_Node_And_Abstract_Entity_Types | + Between_Abstract_Entity_And_Concrete_Node_Types | + Between_Concrete_Node_And_Concrete_Entity_Types; -- These are not used, other than to separate the various subranges. + subtype Uint_Subtype is Type_Enum with + Predicate => Uint_Subtype in Valid_Uint | Unat | Upos | Nonzero_Uint; + end Gen_IL.Types; diff --git a/gcc/ada/layout.adb b/gcc/ada/layout.adb index f716488..e69386c 100644 --- a/gcc/ada/layout.adb +++ b/gcc/ada/layout.adb @@ -433,7 +433,7 @@ package body Layout is Set_RM_Size (E, RM_Size (PAT)); end if; - if not Known_Alignment (E) then + if not Known_Alignment (E) and then Known_Alignment (PAT) then Set_Alignment (E, Alignment (PAT)); end if; end; diff --git a/gcc/ada/repinfo.adb b/gcc/ada/repinfo.adb index 25b5237..148de53 100644 --- a/gcc/ada/repinfo.adb +++ b/gcc/ada/repinfo.adb @@ -410,15 +410,23 @@ package body Repinfo is end if; end if; - if List_Representation_Info_To_JSON then - Write_Str (" ""Alignment"": "); - Write_Val (Alignment (Ent)); + if Known_Alignment (Ent) then + if List_Representation_Info_To_JSON then + Write_Str (" ""Alignment"": "); + Write_Val (Alignment (Ent)); + else + Write_Str ("for "); + List_Name (Ent); + Write_Str ("'Alignment use "); + Write_Val (Alignment (Ent)); + Write_Line (";"); + end if; + + -- Alignment is not always set for task and protected types + else - Write_Str ("for "); - List_Name (Ent); - Write_Str ("'Alignment use "); - Write_Val (Alignment (Ent)); - Write_Line (";"); + pragma Assert + (Is_Concurrent_Type (Ent) or else Is_Class_Wide_Type (Ent)); end if; end List_Common_Type_Info; diff --git a/gcc/ada/scans.ads b/gcc/ada/scans.ads index 0e9ccd2..5cbae5a 100644 --- a/gcc/ada/scans.ads +++ b/gcc/ada/scans.ads @@ -441,12 +441,12 @@ package Scans is -- scanned literal. Real_Literal_Value : Ureal; - -- Valid only when Token is Tok_Real_Literal, contains the value of the + -- Valid only when Token is Tok_Real_Literal. Contains the value of the -- scanned literal. Int_Literal_Value : Uint; - -- Valid only when Token = Tok_Integer_Literal, contains the value of the - -- scanned literal. + -- Valid only when Token = Tok_Integer_Literal, and we are not in + -- syntax-only mode. Contains the value of the scanned literal. Based_Literal_Uses_Colon : Boolean; -- Valid only when Token = Tok_Integer_Literal or Tok_Real_Literal. Set diff --git a/gcc/ada/scn.adb b/gcc/ada/scn.adb index 7272ad4..ad53279 100644 --- a/gcc/ada/scn.adb +++ b/gcc/ada/scn.adb @@ -155,7 +155,14 @@ package body Scn is when Tok_Integer_Literal => Token_Node := New_Node (N_Integer_Literal, Token_Ptr); - Set_Intval (Token_Node, Int_Literal_Value); + + -- Int_Literal_Value can be No_Uint in some cases in syntax-only + -- mode (see Scng.Scan.Nlit). + + if Int_Literal_Value /= No_Uint then + Set_Intval (Token_Node, Int_Literal_Value); + end if; + Check_Obsolete_Base_Char; when Tok_String_Literal => diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 91d41b4..76859c5 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -8101,10 +8101,12 @@ package body Sem_Ch13 is elsif Val < Lo or else Hi < Val then Error_Msg_N ("value outside permitted range", Expr); Err := True; + + else + Set_Enumeration_Rep (Elit, Val); + Set_Enumeration_Rep_Expr (Elit, Expr); end if; - Set_Enumeration_Rep (Elit, Val); - Set_Enumeration_Rep_Expr (Elit, Expr); Next (Expr); Next (Elit); end loop; @@ -8178,9 +8180,10 @@ package body Sem_Ch13 is elsif Val < Lo or else Hi < Val then Error_Msg_N ("value outside permitted range", Expr); Err := True; - end if; - Set_Enumeration_Rep (Elit, Val); + else + Set_Enumeration_Rep (Elit, Val); + end if; end if; end if; end if; @@ -8274,9 +8277,10 @@ package body Sem_Ch13 is Set_Enum_Esize (Enumtype); end if; - Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype)); - Set_Esize (Base_Type (Enumtype), Esize (Enumtype)); - Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype)); + Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype)); + Set_Esize (Base_Type (Enumtype), Esize (Enumtype)); + + Copy_Alignment (To => Base_Type (Enumtype), From => Enumtype); end; end if; @@ -16299,9 +16303,13 @@ package body Sem_Ch13 is X_Offs : Uint; begin - -- Skip processing of this entry if warning already posted + -- Skip processing of this entry if warning already posted, or if + -- alignments are not set. - if not Address_Warning_Posted (ACCR.N) then + if not Address_Warning_Posted (ACCR.N) + and then Known_Alignment (ACCR.X) + and then Known_Alignment (ACCR.Y) + then Expr := Original_Node (Expression (ACCR.N)); -- Get alignments, sizes and offset, if any diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index 5705aa7..0ff4e49 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -7562,7 +7562,7 @@ package body Sem_Prag is end if; if not Has_Alignment_Clause (Ent) then - Set_Alignment (Ent, Uint_0); + Init_Alignment (Ent); end if; end Set_Atomic_VFA; diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 5d0aa49..01a4e2b 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -12079,7 +12079,7 @@ package body Sem_Util is -- do it when there is an address clause since we can do more if the -- alignment is known. - if not Known_Alignment (Obj) then + if not Known_Alignment (Obj) and then Known_Alignment (Etype (Obj)) then Set_Alignment (Obj, Alignment (Etype (Obj))); end if; @@ -28366,7 +28366,7 @@ package body Sem_Util is Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2)); end if; - Set_Alignment (T1, Alignment (T2)); + Copy_Alignment (To => T1, From => T2); end Set_Size_Info; ------------------------------ diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads index 71da7fc..20a6125 100644 --- a/gcc/ada/sinfo.ads +++ b/gcc/ada/sinfo.ads @@ -2177,12 +2177,12 @@ package Sinfo is -- Present in an N_Variant node. This has a meaningful value only after -- Gigi has back annotated the tree with representation information. At -- this point, it contains a reference to a gcc expression that depends - -- on the values of one or more discriminants. Give a set of discriminant - -- values, this expression evaluates to False (zero) if variant is not - -- present, and True (non-zero) if it is present. See unit Repinfo for - -- further details on gigi back annotation. This field is used during - -- back-annotation processing (for -gnatR -gnatc) to determine if a field - -- is present or not. + -- on the values of one or more discriminants. Given a set of + -- discriminant values, this expression evaluates to False (zero) if + -- variant is not present, and True (non-zero) if it is present. See + -- unit Repinfo for further details on gigi back annotation. This field + -- is used during back-annotation processing (for -gnatR -gnatc) to + -- determine if a field is present or not. -- Prev_Use_Clause -- Present in both N_Use_Package_Clause and N_Use_Type_Clause. Used in diff --git a/gcc/ada/treepr.adb b/gcc/ada/treepr.adb index ff4ff84..054d06c 100644 --- a/gcc/ada/treepr.adb +++ b/gcc/ada/treepr.adb @@ -721,6 +721,12 @@ package body Treepr is function Get_Uint is new Get_32_Bit_Field_With_Default (Uint, Uint_0) with Inline; + function Get_Valid_Uint is new Get_32_Bit_Field + (Uint) with Inline; + -- Used for both Valid_Uint and other subtypes of Uint. Note that we don't + -- instantiate Get_Valid_32_Bit_Field; we don't want to blow up if the + -- value is wrong. + function Get_Ureal is new Get_32_Bit_Field (Ureal) with Inline; @@ -893,13 +899,36 @@ package body Treepr is Val : constant Uint := Get_Uint (N, FD.Offset); function Cast is new Unchecked_Conversion (Uint, Int); begin - if Val /= No_Uint then - Print_Initial; - UI_Write (Val, Format); - Write_Str (" (Uint = "); - Write_Int (Cast (Val)); - Write_Char (')'); - end if; + -- Do this even if Val = No_Uint, because Uint fields default + -- to Uint_0. + + Print_Initial; + UI_Write (Val, Format); + Write_Str (" (Uint = "); + Write_Int (Cast (Val)); + Write_Char (')'); + end; + + when Valid_Uint_Field | Unat_Field | Upos_Field + | Nonzero_Uint_Field => + declare + Val : constant Uint := Get_Valid_Uint (N, FD.Offset); + function Cast is new Unchecked_Conversion (Uint, Int); + begin + Print_Initial; + UI_Write (Val, Format); + + case FD.Kind is + when Valid_Uint_Field => Write_Str (" v"); + when Unat_Field => Write_Str (" n"); + when Upos_Field => Write_Str (" p"); + when Nonzero_Uint_Field => Write_Str (" nz"); + when others => raise Program_Error; + end case; + + Write_Str (" (Uint = "); + Write_Int (Cast (Val)); + Write_Char (')'); end; when Ureal_Field => diff --git a/gcc/ada/types.h b/gcc/ada/types.h index ac30db3..2806e50 100644 --- a/gcc/ada/types.h +++ b/gcc/ada/types.h @@ -261,6 +261,10 @@ typedef Int String_Id; /* Type used for representation of universal integers. */ typedef Int Uint; +typedef Int Valid_Uint; +typedef Int Unat; +typedef Int Upos; +typedef Int Nonzero_Uint; /* Used to indicate missing Uint value. */ #define No_Uint Uint_Low_Bound diff --git a/gcc/ada/uintp.ads b/gcc/ada/uintp.ads index 607e7ef..b2f2315 100644 --- a/gcc/ada/uintp.ads +++ b/gcc/ada/uintp.ads @@ -90,6 +90,11 @@ package Uintp is Uint_Minus_127 : constant Uint; Uint_Minus_128 : constant Uint; + subtype Valid_Uint is Uint with Predicate => Valid_Uint /= No_Uint; + subtype Unat is Valid_Uint with Predicate => Unat >= Uint_0; + subtype Upos is Valid_Uint with Predicate => Upos >= Uint_0; + subtype Nonzero_Uint is Valid_Uint with Predicate => Nonzero_Uint /= Uint_0; + type UI_Vector is array (Pos range <>) of Int; -- Vector containing the integer values of a Uint value |