[COMMITTED,05/30] ada: One more adjustment coming from aliasing considerations

Message ID 20240520074858.222435-5-poulhies@adacore.com
State Committed
Commit eef3025547ce55cbf6a9018b495ef5c9a562047a
Series [COMMITTED,01/30] ada: Rework and augment documentation on strict aliasing |

Commit Message

Marc Poulhiès May 20, 2024, 7:48 a.m. UTC
  From: Eric Botcazou <ebotcazou@adacore.com>

It is needed on PowerPC platforms because of specific calling conventions.


	* libgnat/g-sothco.ads (In_Addr): Add aspect Universal_Aliasing.

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

 gcc/ada/libgnat/g-sothco.ads | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)


diff --git a/gcc/ada/libgnat/g-sothco.ads b/gcc/ada/libgnat/g-sothco.ads
index 8c219333649..da1e6f5bcdd 100644
--- a/gcc/ada/libgnat/g-sothco.ads
+++ b/gcc/ada/libgnat/g-sothco.ads
@@ -123,10 +123,13 @@  package GNAT.Sockets.Thin_Common is
    type In_Addr is record
       S_B1, S_B2, S_B3, S_B4 : C.unsigned_char;
-   end record with Convention => C, Alignment => C.int'Alignment;
+   end record
+     with Convention => C, Alignment  => C.int'Alignment, Universal_Aliasing;
    --  IPv4 address, represented as a network-order C.int. Note that the
    --  underlying operating system may assume that values of this type have
-   --  C.int alignment, so we need to provide a suitable alignment clause here.
+   --  C.int's alignment, so we need to provide a suitable alignment clause.
+   --  We also need to inhibit strict type-based aliasing optimizations in
+   --  order to implement the following unchecked conversions efficiently.
    function To_In_Addr is new Ada.Unchecked_Conversion (C.int, In_Addr);
    function To_Int     is new Ada.Unchecked_Conversion (In_Addr, C.int);