From patchwork Thu May 25 08:06:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 98863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp201251vqr; Thu, 25 May 2023 01:22:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7VkfjyVRcuiczsQwEATtN2kpZ+X8+Yn5QIbAygGUTKaeBo/U5F7y67cQrKc2G8MVrQfO5a X-Received: by 2002:a17:907:2da8:b0:965:aa65:233f with SMTP id gt40-20020a1709072da800b00965aa65233fmr911724ejc.2.1685002958298; Thu, 25 May 2023 01:22:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685002958; cv=none; d=google.com; s=arc-20160816; b=Y1vHBkfixKHM1GqGsgY3eXmiXYYM6fhm5OUjlwI3dUBKJSeB1VYQfaccNQ63Wsqh0b pfbHs3gpYAlqerofe6efNQ+d7UEsxzFS/zkm6coWMvt32y1MiJxJkp+9QJ2tH+trZvLx pigKfIPtGGnhqqgBFvCWzW3BYrJyaL8Eh24YDtKS3ihRcm92loe1jo+vQpwjR0CYoUS7 fYXDR/yx8okSs2cJez9LTPMb9M0KQ4rK6lvNXPEW69XXmoYyJ1OP613W77US2Qhc5en0 +oGZ2G9JTuQy9H8MiLqjw2VcxuEVr0nszeoa1x160EpVb4JGfHcv5jwJQI8V/+ICig0d MkFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=IOSE9u5bCIU8efXxygrMM4IliVE5tkl2xFlgVzipqtw=; b=Z9ng5QJVbYQcMenn9Zz+k2387uSgmSoABHYA48ZzKlVYrsfcR1yu6xMbAj21OQLS9i 5ld9l7ktP7alBfthLItTGZROQl8/21XDMM+zZY95XYPXVhMu088G0j5ZF153C/SvkrXl ucZ0AcM3KgPARxnEdwqnd8qMa7pe3rlXAX3nQANKw5Xh6gsbu6e37Ivalb6JEt2T66V7 0eEQvyCRaCXULh+NpGl8IWKePtiTG5LPdpCKYpIgeN9NBDD5jcnAxEe5MEHYgXXn3Kvq WVIy6YcZUy2nhQm3U1/meuwKFaXt+6GULxceGQ37or0XyTDj9LQux3v4bBfhiT6eOLcW CedQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yAbd5D62; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gz13-20020a170907a04d00b0097374e3e16fsi766027ejc.238.2023.05.25.01.22.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 01:22:38 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yAbd5D62; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D9F9395BC68 for ; Thu, 25 May 2023 08:14:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D9F9395BC68 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685002487; bh=IOSE9u5bCIU8efXxygrMM4IliVE5tkl2xFlgVzipqtw=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=yAbd5D625XTjnjVUgq7R89BPe5G9N1yIDfe68VSPdM4Zci+E00PygYx/7Rp9hpxUs tVgNCsCcW/DngDELZZ9TnnxVNwTOt6G7vaj+BEBjRe7M6zMjjdP+YcU1V+0tOszJom 2CdL9KW7mdAihwi0SBktEUXUBFgmmDoRsq0Sa7Kc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id CDD083836E85 for ; Thu, 25 May 2023 08:06:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CDD083836E85 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-309d3e8777cso496844f8f.0 for ; Thu, 25 May 2023 01:06:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685001969; x=1687593969; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IOSE9u5bCIU8efXxygrMM4IliVE5tkl2xFlgVzipqtw=; b=YPKkBKM5GXrmGDLOJa+prA36BWShWIs51pPWt0TPGpfv/aKCGtOfv8LkIIImhylZpt wW1kTfHeH324oa0v8Do0H6z5v//pWXSZv5/dpQpjHHrt1rutjB5RTacXKV/U+lmiu550 S9ftRfKJ9eUxOybq5GKvQT11NJJ/20BSqn0GXGCO8CRX+eJJsNn3Lmk+5yQxPaxcsuzs r4/p15+m8DXH78LultT0Id8f4qxudqwvi2wmuO48irrESj1FOKME5XIaHW8n8RICwJ2C shT2Czo4iAKzuqwGZ0joD06lrWizFyxx5s6DtFFYRG9FtuOI1juXwygthMonOh7g+Rk6 Tcpw== X-Gm-Message-State: AC+VfDzex4GWeXhxij0c9QgOtTRC6K4Jk0ZdOM3ilvTRSFsQBeRKmUbt iWM1ltWpG7CVkLpnZMr3EvWGDxmDlzFgQTejddPklA== X-Received: by 2002:a05:6000:181:b0:303:daff:f1a3 with SMTP id p1-20020a056000018100b00303dafff1a3mr1384265wrx.1.1685001969674; Thu, 25 May 2023 01:06:09 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id k25-20020a05600c1c9900b003f1738d0d13sm11716786wms.1.2023.05.25.01.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 01:06:09 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Decouple size of addresses and pointers from size of memory space Date: Thu, 25 May 2023 10:06:08 +0200 Message-Id: <20230525080608.1957177-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766853661576746903?= X-GMAIL-MSGID: =?utf-8?q?1766853661576746903?= From: Eric Botcazou 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;