]> gcc.gnu.org Git - gcc.git/commitdiff
ada: Fix conversions between addresses and integers
authorDaniel King <dmking@adacore.com>
Wed, 23 Aug 2023 12:00:57 +0000 (13:00 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 26 Sep 2023 11:43:17 +0000 (13:43 +0200)
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.

gcc/ada/libgnat/a-tags.adb
gcc/ada/libgnat/s-putima.adb

index 3590785aa448ef3e267acebca6fcc73c73199228..1ffc78ed1e8b9891fb56824a766c6efb54c64853 100644 (file)
@@ -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);
index 1d6e6085928dd7c9b18c8fa30a4ccb396993bfe5..bcc7af2ebf544f4a69b4d9bd20fd6f1e5da6e34c 100644 (file)
@@ -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;
This page took 0.067649 seconds and 5 git commands to generate.