]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Decouple size of addresses and pointers from size of memory space
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 8 Mar 2023 14:12:27 +0000 (15:12 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 25 May 2023 07:44:18 +0000 (09:44 +0200)
This decouples the size of the types representing addresses and pointers,
which is Standard'Address_Size, from the size of the memory space, which
is System.Memory_Size (more precisely log2 of it).  They are tied through
the definition of System.Address:

  type Address is mod Memory_Size;

so Standard'Address_Size >= log2 (System.Memory_Size) necessarily, but the
equality does not hold on platforms where addresses and pointers contain
additional bits of metadata.

gcc/ada/

* libgnat/a-ststio.adb (Set_Mode): Test System.Memory_Size.
* libgnat/g-debuti.ads (Address_64): Likewise.
* libgnat/i-c.ads: Add with clause for System.
(ptrdiff_t): Define based on the size of memory space.
(size_t): Likewise.
* libgnat/s-crtl.ads (size_t): Likewise.
(ssize_t): Likewise.
* libgnat/s-memory.ads (size_t): Likewise.
* libgnat/s-parame.ads (Size_Type): Likewise.
* libgnat/s-parame__hpux.ads (Size_Type): Likewise.
* libgnat/s-parame__posix2008.ads (Size_Type): Likewise.
* libgnat/s-parame__vxworks.ads (Size_Type): Likewise.
* libgnat/s-putima.adb (Signed_Address): Likewise.
(Unsigned_Address): Likewise.
* libgnat/s-stoele.ads (Storage_Offset): Likewise.

gcc/ada/libgnat/a-ststio.adb
gcc/ada/libgnat/g-debuti.ads
gcc/ada/libgnat/i-c.ads
gcc/ada/libgnat/s-crtl.ads
gcc/ada/libgnat/s-memory.ads
gcc/ada/libgnat/s-parame.ads
gcc/ada/libgnat/s-parame__hpux.ads
gcc/ada/libgnat/s-parame__posix2008.ads
gcc/ada/libgnat/s-parame__vxworks.ads
gcc/ada/libgnat/s-putima.adb
gcc/ada/libgnat/s-stoele.ads

index 2cb9d974bbdd766dff1fdfd3ce6755f0520a8c39..ab46f483b0e55e60ae64fcd25f10b50f50bb2d47 100644 (file)
@@ -367,11 +367,13 @@ package body Ada.Streams.Stream_IO is
       FIO.Append_Set (AP (File));
 
       if File.Mode = FCB.Append_File then
-         if Standard'Address_Size = 64 then
+         pragma Warnings (Off, "condition is always *");
+         if Memory_Size = 2**64 then
             File.Index := Count (ftell64 (File.Stream)) + 1;
          else
             File.Index := Count (ftell (File.Stream)) + 1;
          end if;
+         pragma Warnings (On);
       end if;
 
       File.Last_Op := Op_Other;
index b989cd4bdfb91d41125aadf4d3d215f14782bb89..51a1b7708e648a9ea378eabc1fdfd1a111c12bbd 100644 (file)
@@ -39,8 +39,8 @@ with System;
 package GNAT.Debug_Utilities is
    pragma Pure;
 
-   Address_64 : constant Boolean := Standard'Address_Size = 64;
-   --  Set true if 64 bit addresses (assumes only 32 and 64 are possible)
+   Address_64 : constant Boolean := System.Memory_Size = 2**64;
+   --  Set true if 64-bit addresses (assumes only 32 and 64 are possible)
 
    Address_Image_Length : constant := 13 + 10 * Boolean'Pos (Address_64);
    --  Length of string returned by Image function for an address
index 70139023dc3251f032a55b3bcc8039d3081dd355..70af56a783655274d53e7234e5bfd953d457ea1c 100644 (file)
@@ -24,6 +24,7 @@ pragma Assertion_Policy (Pre            => Ignore,
                          Contract_Cases => Ignore,
                          Ghost          => Ignore);
 
+with System;
 with System.Parameters;
 
 package Interfaces.C
@@ -82,10 +83,9 @@ is
    --  a non-private system.address type.
 
    type ptrdiff_t is
-     range -(2 ** (System.Parameters.ptr_bits - Integer'(1))) ..
-           +(2 ** (System.Parameters.ptr_bits - Integer'(1)) - 1);
+     range -System.Memory_Size / 2 .. System.Memory_Size / 2 - 1;
 
-   type size_t is mod 2 ** System.Parameters.ptr_bits;
+   type size_t is mod System.Memory_Size;
 
    --  Boolean type
 
index 4b6fc769afaf968b25002f554d140914f4de1921..c3a3b6481dbce078625915ff5e5057b7b8ee5089 100644 (file)
@@ -55,10 +55,9 @@ package System.CRTL is
 
    subtype off_t is Long_Integer;
 
-   type size_t is mod 2 ** Standard'Address_Size;
+   type size_t is mod System.Memory_Size;
 
-   type ssize_t is range -(2 ** (Standard'Address_Size - 1))
-                      .. +(2 ** (Standard'Address_Size - 1)) - 1;
+   type ssize_t is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
 
    type int64 is new Long_Long_Integer;
    --  Note: we use Long_Long_Integer'First instead of -2 ** 63 to allow this
index dc431b766f84084dd415eb06ae978c447c303974..4f6dd3d285627aefccd9e2c0fff4d8cf112891bd 100644 (file)
@@ -43,7 +43,7 @@
 package System.Memory is
    pragma Elaborate_Body;
 
-   type size_t is mod 2 ** Standard'Address_Size;
+   type size_t is mod Memory_Size;
    --  Note: the reason we redefine this here instead of using the
    --  definition in Interfaces.C is that we do not want to drag in
    --  all of Interfaces.C just because System.Memory is used.
index 3d6e345a1ba9409e6845cabb7d87dc76963c3edb..72e72381ffcbea732a71660afed3d10c6a578578 100644 (file)
@@ -53,9 +53,7 @@ package System.Parameters is
    -- Task And Stack Allocation Control --
    ---------------------------------------
 
-   type Size_Type is range
-     -(2 ** (Integer'(Standard'Address_Size) - 1)) ..
-     +(2 ** (Integer'(Standard'Address_Size) - 1)) - 1;
+   type Size_Type is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
    --  Type used to provide task stack sizes to the runtime. Sized to permit
    --  stack sizes of up to half the total addressable memory space. This may
    --  seem excessively large (even for 32-bit systems), however there are many
index 542131fa73ffab93800245e678062e81e73704c8..243f8c3386e583e464be439c0986b780010085b1 100644 (file)
@@ -53,9 +53,7 @@ package System.Parameters is
    -- Task And Stack Allocation Control --
    ---------------------------------------
 
-   type Size_Type is range
-     -(2 ** (Integer'(Standard'Address_Size) - 1)) ..
-     +(2 ** (Integer'(Standard'Address_Size) - 1)) - 1;
+   type Size_Type is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
    --  Type used to provide task stack sizes to the runtime. Sized to permit
    --  stack sizes of up to half the total addressable memory space. This may
    --  seem excessively large (even for 32-bit systems), however there are many
index 4f5d47a2245286a84cc89ab95a1ed375979be5b8..16555e18059181cee1fd0c1148e378a96224eb2f 100644 (file)
@@ -53,9 +53,7 @@ package System.Parameters is
    -- Task And Stack Allocation Control --
    ---------------------------------------
 
-   type Size_Type is range
-     -(2 ** (Integer'(Standard'Address_Size) - 1)) ..
-     +(2 ** (Integer'(Standard'Address_Size) - 1)) - 1;
+   type Size_Type is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
    --  Type used to provide task stack sizes to the runtime. Sized to permit
    --  stack sizes of up to half the total addressable memory space. This may
    --  seem excessively large (even for 32-bit systems), however there are many
index adae27deac8daf9fa4a4dc7c85fb8b6ec05144f1..6cf32ca98ec2a813ec3aff12d2f28fd7f45f62da 100644 (file)
@@ -53,9 +53,7 @@ package System.Parameters is
    -- Task And Stack Allocation Control --
    ---------------------------------------
 
-   type Size_Type is range
-     -(2 ** (Integer'(Standard'Address_Size) - 1)) ..
-     +(2 ** (Integer'(Standard'Address_Size) - 1)) - 1;
+   type Size_Type is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
    --  Type used to provide task stack sizes to the runtime. Sized to permit
    --  stack sizes of up to half the total addressable memory space. This may
    --  seem excessively large (even for 32-bit systems), however there are many
index 34d5a0362f5a6b3ed777828ce54f80c71332e1c6..1d6e6085928dd7c9b18c8fa30a4ccb396993bfe5 100644 (file)
@@ -118,9 +118,8 @@ package body System.Put_Images is
      (S : in out Sink'Class; X : Long_Long_Long_Unsigned)
      renames LLL_Integer_Images.Put_Image;
 
-   type Signed_Address is range
-     -2**(Standard'Address_Size - 1) .. 2**(Standard'Address_Size - 1) - 1;
-   type Unsigned_Address is mod 2**Standard'Address_Size;
+   type Signed_Address is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
+   type Unsigned_Address is mod Memory_Size;
    package Hex is new Generic_Integer_Images
      (Signed_Address, Unsigned_Address, Base => 16);
 
index 99a195a13389aa6f808a861b9bffd779da53b2df..3262d0329c349bb48e6940d2e6e7941be91c06f6 100644 (file)
@@ -45,12 +45,7 @@ package System.Storage_Elements is
 
    pragma Annotate (GNATprove, Always_Return, Storage_Elements);
 
-   type Storage_Offset is range
-     -(2 ** (Integer'(Standard'Address_Size) - 1)) ..
-     +(2 ** (Integer'(Standard'Address_Size) - 1)) - Long_Long_Integer'(1);
-   --  Note: the reason for the Long_Long_Integer qualification here is to
-   --  avoid a bogus ambiguity when this unit is analyzed in an rtsfind
-   --  context.
+   type Storage_Offset is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
 
    subtype Storage_Count is Storage_Offset range 0 .. Storage_Offset'Last;