public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Decouple size of addresses and pointers from size of memory space
@ 2023-05-25  8:06 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-05-25  8:06 UTC (permalink / raw)
  To: gcc-patches; +Cc: Eric Botcazou

From: Eric Botcazou <ebotcazou@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/a-ststio.adb            | 4 +++-
 gcc/ada/libgnat/g-debuti.ads            | 4 ++--
 gcc/ada/libgnat/i-c.ads                 | 6 +++---
 gcc/ada/libgnat/s-crtl.ads              | 5 ++---
 gcc/ada/libgnat/s-memory.ads            | 2 +-
 gcc/ada/libgnat/s-parame.ads            | 4 +---
 gcc/ada/libgnat/s-parame__hpux.ads      | 4 +---
 gcc/ada/libgnat/s-parame__posix2008.ads | 4 +---
 gcc/ada/libgnat/s-parame__vxworks.ads   | 4 +---
 gcc/ada/libgnat/s-putima.adb            | 5 ++---
 gcc/ada/libgnat/s-stoele.ads            | 7 +------
 11 files changed, 18 insertions(+), 31 deletions(-)

diff --git a/gcc/ada/libgnat/a-ststio.adb b/gcc/ada/libgnat/a-ststio.adb
index 2cb9d974bbd..ab46f483b0e 100644
--- a/gcc/ada/libgnat/a-ststio.adb
+++ b/gcc/ada/libgnat/a-ststio.adb
@@ -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;
diff --git a/gcc/ada/libgnat/g-debuti.ads b/gcc/ada/libgnat/g-debuti.ads
index b989cd4bdfb..51a1b7708e6 100644
--- a/gcc/ada/libgnat/g-debuti.ads
+++ b/gcc/ada/libgnat/g-debuti.ads
@@ -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
diff --git a/gcc/ada/libgnat/i-c.ads b/gcc/ada/libgnat/i-c.ads
index 70139023dc3..70af56a7836 100644
--- a/gcc/ada/libgnat/i-c.ads
+++ b/gcc/ada/libgnat/i-c.ads
@@ -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
 
diff --git a/gcc/ada/libgnat/s-crtl.ads b/gcc/ada/libgnat/s-crtl.ads
index 4b6fc769afa..c3a3b6481db 100644
--- a/gcc/ada/libgnat/s-crtl.ads
+++ b/gcc/ada/libgnat/s-crtl.ads
@@ -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
diff --git a/gcc/ada/libgnat/s-memory.ads b/gcc/ada/libgnat/s-memory.ads
index dc431b766f8..4f6dd3d2856 100644
--- a/gcc/ada/libgnat/s-memory.ads
+++ b/gcc/ada/libgnat/s-memory.ads
@@ -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.
diff --git a/gcc/ada/libgnat/s-parame.ads b/gcc/ada/libgnat/s-parame.ads
index 3d6e345a1ba..72e72381ffc 100644
--- a/gcc/ada/libgnat/s-parame.ads
+++ b/gcc/ada/libgnat/s-parame.ads
@@ -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
diff --git a/gcc/ada/libgnat/s-parame__hpux.ads b/gcc/ada/libgnat/s-parame__hpux.ads
index 542131fa73f..243f8c3386e 100644
--- a/gcc/ada/libgnat/s-parame__hpux.ads
+++ b/gcc/ada/libgnat/s-parame__hpux.ads
@@ -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
diff --git a/gcc/ada/libgnat/s-parame__posix2008.ads b/gcc/ada/libgnat/s-parame__posix2008.ads
index 4f5d47a2245..16555e18059 100644
--- a/gcc/ada/libgnat/s-parame__posix2008.ads
+++ b/gcc/ada/libgnat/s-parame__posix2008.ads
@@ -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
diff --git a/gcc/ada/libgnat/s-parame__vxworks.ads b/gcc/ada/libgnat/s-parame__vxworks.ads
index adae27deac8..6cf32ca98ec 100644
--- a/gcc/ada/libgnat/s-parame__vxworks.ads
+++ b/gcc/ada/libgnat/s-parame__vxworks.ads
@@ -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
diff --git a/gcc/ada/libgnat/s-putima.adb b/gcc/ada/libgnat/s-putima.adb
index 34d5a0362f5..1d6e6085928 100644
--- a/gcc/ada/libgnat/s-putima.adb
+++ b/gcc/ada/libgnat/s-putima.adb
@@ -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);
 
diff --git a/gcc/ada/libgnat/s-stoele.ads b/gcc/ada/libgnat/s-stoele.ads
index 99a195a1338..3262d0329c3 100644
--- a/gcc/ada/libgnat/s-stoele.ads
+++ b/gcc/ada/libgnat/s-stoele.ads
@@ -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;
 
-- 
2.40.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-25  8:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-25  8:06 [COMMITTED] ada: Decouple size of addresses and pointers from size of memory space Marc Poulhiès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).