]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Clean up Uint fields
authorBob Duff <duff@adacore.com>
Tue, 15 Jun 2021 13:12:36 +0000 (09:12 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 12 Jul 2021 12:50:57 +0000 (12:50 +0000)
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.

28 files changed:
gcc/ada/atree.adb
gcc/ada/atree.ads
gcc/ada/atree.h
gcc/ada/einfo-utils.adb
gcc/ada/einfo-utils.ads
gcc/ada/einfo.ads
gcc/ada/exp_pakd.adb
gcc/ada/fe.h
gcc/ada/freeze.adb
gcc/ada/gcc-interface/decl.c
gcc/ada/gcc-interface/trans.c
gcc/ada/gen_il-fields.ads
gcc/ada/gen_il-gen-gen_entities.adb
gcc/ada/gen_il-gen-gen_nodes.adb
gcc/ada/gen_il-gen.adb
gcc/ada/gen_il-internals.ads
gcc/ada/gen_il-types.ads
gcc/ada/layout.adb
gcc/ada/repinfo.adb
gcc/ada/scans.ads
gcc/ada/scn.adb
gcc/ada/sem_ch13.adb
gcc/ada/sem_prag.adb
gcc/ada/sem_util.adb
gcc/ada/sinfo.ads
gcc/ada/treepr.adb
gcc/ada/types.h
gcc/ada/uintp.ads

index 33cde5ad0b3abdf7a3b92e5ded5adb1be7a0edde..c7e295bc8f7bc42b1aede1a9b5852c8b907c62e5 100644 (file)
@@ -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
index 42df9505438b9afc341ed1030dde516e68c86a7d..6fb5aa6c2b6fb24d920ea0ed28e2f051c1c08f5b 100644 (file)
@@ -762,6 +762,14 @@ package Atree is
          with Inline;
       --  If the field has not yet been set, return Default_Val
 
+      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
index e4750e13ab389d22fbb241ded553ed7f399b8640..08b791cae7c3afd4bc7ca8ca2224899fc6f5e754 100644 (file)
@@ -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
index 21d7bfb504e5fd66eae87ea0fce0932d149497fe..4690c8f349033905cfa1dcd986ebfa5a922af61c 100644 (file)
@@ -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
index dbf3ad6eb329f150104f26ee7db19871e5ff3aad..a6517b99b88abcdff5be50b09c2770d971d3f44d 100644 (file)
@@ -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);
index 6a8d49352b8b8a154e2cd0cd053aa8e8b8b62ecc..e87ce4c8ba29ae11d31aa8b0ad825fe05d412bcc 100644 (file)
@@ -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
index 47919fc6e791bb002b395fc6bd83b4b647bcabcc..88f86f4b79ab3f60b4609c124a5b4953aa0c8580 100644 (file)
@@ -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);
index d7ab361b715193751ac641063ef9fb37dd7f4ee4..4517c5943e3782db5ba3e079e807f79d90b43a27 100644 (file)
@@ -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);
 
index 12d10ee82bfce61f8c07584c2d4b5aebe9c0963a..84502d879e7f8ac2de9d5ee44ad11f24c4cc8ea8 100644 (file)
@@ -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;
 
index b09e20dc06e98c2f427f9a44c635e832b1e2739d..83ca31acba5cc0a21ce073fb787d629780eaa475 100644 (file)
@@ -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))
index 8f8bc700f91e46762e0d77a7731741173c31a57c..f61183de8091c6d2874d5d363545fa5799be7c2f 100644 (file)
@@ -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));
index e2592eedcc9d28f8ec0bb702e008f0296bb579ba..0a3046eb52032048a73729a2770978d78f43ddd7 100644 (file)
@@ -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,
index d5977ad2834b4cfaf047abb6a3dacacf5b74bb1b..41dd2327332a7fab80dbd19287f2a8d57ba22aaa 100644 (file)
@@ -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),
index 2427a1e8e891f2d096050faa797b3e01cd4968e0..55ba71d7efb13e2a20a5ed927d39675926795eeb 100644 (file)
@@ -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)));
 
index 94f7c9cb2d8d7420b73a8280d6ced69904e9a373..a9c7bd7cfff9de062a41ae387b35cca1836fbf87 100644 (file)
@@ -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_" &
index b8911ec3c0afb7a632d76ff4e06e09dae853b16b..ae448de0e7c6a17fc6ed456fba0509a97cdb1129 100644 (file)
@@ -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
index 84eb63f322a7bbd4753a4f507cdb26a95f75471a..321eec6504c635394f5f2fc90a407237fc731bf0 100644 (file)
@@ -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;
index f716488a59c53819dd8b67ff7722707dbf0f64f3..e69386c81faf93e9571e0245702ea9415936b7ce 100644 (file)
@@ -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;
index 25b52376905209436b242b8f463a67051330cdab..148de536f96cc0f2011dfef8c588ce5558e0372b 100644 (file)
@@ -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;
 
index 0e9ccd2f905af9ed25388be7fec3ae33132a2e60..5cbae5adb801b1e56a15ec2e6ace0b7390aaf664 100644 (file)
@@ -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
index 7272ad40815a40236896ec09270135d8aacfbf05..ad5327911957d04e3a03ed87fbca4bca0bf1dfb3 100644 (file)
@@ -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 =>
index 91d41b4a63bae599f44a72955a9ab70c01fe4fcf..76859c5463fb0ac2e33e6608fbe3a1a927ec3680 100644 (file)
@@ -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
index 5705aa7bbf4262f6f44bc7936001e0a7747c968e..0ff4e49e5b9496cb93624f70f6e4b4a57ae50e81 100644 (file)
@@ -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;
 
index 5d0aa49a2db685bf7c13cde119702df4ce9e8de5..01a4e2bc8af494ff57dc1ad32680558e610a48e7 100644 (file)
@@ -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;
 
    ------------------------------
index 71da7fc583e1aa028ea41cd961172be3f024b5c7..20a61251a9d6c3656cdcbc19ed15189c62211fcf 100644 (file)
@@ -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
index ff4ff846f9f6ce92223c1bb8f2d2f5b217088a4b..054d06ca76f6bd657ce99d2d73713601ca0b311f 100644 (file)
@@ -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 =>
index ac30db346eb8b0543bc60372384378eacdd6507f..2806e50ddd7785713a9d245e4f43b23482b98a8f 100644 (file)
@@ -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
index 607e7ef95fa3056ad59027582f3738e336e1e97d..b2f2315effe2b9b06a21e7abae7070f1aaa21b93 100644 (file)
@@ -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