diff mbox series

[COMMITTED,07/30] ada: Use System.Address for address computation in System.Pool_Global

Message ID 20240520074858.222435-7-poulhies@adacore.com
State New
Headers show
Series [COMMITTED,01/30] ada: Rework and augment documentation on strict aliasing | expand

Commit Message

Marc Poulhiès May 20, 2024, 7:48 a.m. UTC
From: Sebastian Poeplau <poeplau@adacore.com>

Some architectures don't let us convert
System.Storage_Elements.Integer_Address back to a valid System.Address.
Using the arithmetic operations on System.Address from
System.Storage_Elements prevents the problem while leaving semantics
unchanged.

gcc/ada/

	* libgnat/s-pooglo.adb (Allocate): Use arithmetic on
	System.Address to compute the aligned address.

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

---
 gcc/ada/libgnat/s-pooglo.adb | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/gcc/ada/libgnat/s-pooglo.adb b/gcc/ada/libgnat/s-pooglo.adb
index dea3de15cc5..9ce21c8fd0d 100644
--- a/gcc/ada/libgnat/s-pooglo.adb
+++ b/gcc/ada/libgnat/s-pooglo.adb
@@ -75,9 +75,10 @@  package body System.Pool_Global is
 
          --  Realign the returned address
 
-         Aligned_Address := To_Address
-           (To_Integer (Allocated) + Integer_Address (Alignment)
-              - (To_Integer (Allocated) mod Integer_Address (Alignment)));
+         Aligned_Address :=
+           Allocated + Alignment
+           - Storage_Offset (To_Integer (Allocated)
+                             mod Integer_Address (Alignment));
 
          --  Save the block address