public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Marc Poulhi?s <dkm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-4270] ada: Fix conversions between addresses and integers
Date: Tue, 26 Sep 2023 11:45:51 +0000 (GMT)	[thread overview]
Message-ID: <20230926114551.914F13861808@sourceware.org> (raw)

https://gcc.gnu.org/g:0787c56c48750156783bd5d3280579e9c68a8aa5

commit r14-4270-g0787c56c48750156783bd5d3280579e9c68a8aa5
Author: Daniel King <dmking@adacore.com>
Date:   Wed Aug 23 13:00:57 2023 +0100

    ada: Fix conversions between addresses and integers
    
    On CHERI targets the size of System.Address and Integer_Address
    (or similar) are not the same. The operations in System.Storage_Elements
    should be used to convert between integers and addresses.
    
    gcc/ada/
    
            * libgnat/a-tags.adb (To_Tag): Use System.Storage_Elements for
            integer to address conversion.
            * libgnat/s-putima.adb (Put_Image_Pointer): Likewise.

Diff:
---
 gcc/ada/libgnat/a-tags.adb   | 5 ++++-
 gcc/ada/libgnat/s-putima.adb | 6 ++----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/libgnat/a-tags.adb b/gcc/ada/libgnat/a-tags.adb
index 3590785aa44..1ffc78ed1e8 100644
--- a/gcc/ada/libgnat/a-tags.adb
+++ b/gcc/ada/libgnat/a-tags.adb
@@ -93,7 +93,10 @@ package body Ada.Tags is
    --  Disable warnings on possible aliasing problem
 
    function To_Tag is
-     new Unchecked_Conversion (Integer_Address, Tag);
+     new Unchecked_Conversion (System.Address, Tag);
+
+   function To_Tag (S : Integer_Address) return Tag is
+     (To_Tag (To_Address (S)));
 
    function To_Dispatch_Table_Ptr is
       new Ada.Unchecked_Conversion (Tag, Dispatch_Table_Ptr);
diff --git a/gcc/ada/libgnat/s-putima.adb b/gcc/ada/libgnat/s-putima.adb
index 1d6e6085928..bcc7af2ebf5 100644
--- a/gcc/ada/libgnat/s-putima.adb
+++ b/gcc/ada/libgnat/s-putima.adb
@@ -32,7 +32,7 @@
 with Ada.Strings.Text_Buffers.Utils;
 use Ada.Strings.Text_Buffers;
 use Ada.Strings.Text_Buffers.Utils;
-with Ada.Unchecked_Conversion;
+with System.Storage_Elements; use System.Storage_Elements;
 
 package body System.Put_Images is
 
@@ -132,15 +132,13 @@ package body System.Put_Images is
    procedure Put_Image_Pointer
      (S : in out Sink'Class; X : Pointer; Type_Kind : String)
    is
-      function Cast is new Ada.Unchecked_Conversion
-        (System.Address, Unsigned_Address);
    begin
       if X = null then
          Put_UTF_8 (S, "null");
       else
          Put_UTF_8 (S, "(");
          Put_UTF_8 (S, Type_Kind);
-         Hex.Put_Image (S, Cast (X.all'Address));
+         Hex.Put_Image (S, Unsigned_Address (To_Integer (X.all'Address)));
          Put_UTF_8 (S, ")");
       end if;
    end Put_Image_Pointer;

                 reply	other threads:[~2023-09-26 11:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230926114551.914F13861808@sourceware.org \
    --to=dkm@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).