This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] fix System.Address_To_Access_Conversions wrt strict aliasing


Tested on i686-linux, committed on mainline.

The System.Address_To_Access_Conversions package violates type-based
aliasing rules by virtue of its existence, since it is equivalent to
an implicit Unchecked Conversion between an address and a pointer.
A pragma No_Strict_Aliasing is therefore necessary on the access type
in order to advertise the violation.
Test case:
with Ada.Integer_Text_IO;
with Interfaces;
with System.Address_To_Access_Conversions;
with Text_IO;

procedure Ptr_Pkg_Prob is

   type Byte_Array_Type is
      array (1..4) of Interfaces.Unsigned_8;
   for Byte_Array_Type'Component_Size use 8;
   for Byte_Array_Type'Size use 32;

   package Bytes_Ptr_Pkg is new
      System.Address_To_Access_Conversions(
         Byte_Array_Type );

   LW1 : Interfaces.Unsigned_32;
   pragma Volatile( LW1 );
   LW2 : Interfaces.Unsigned_32 := 16#10101010#;
   pragma Volatile( LW2 );

begin
   LW1 := 16#11223344#;
   Bytes_Ptr_Pkg.To_Pointer(LW2'Address)(1..4) :=
      Bytes_Ptr_Pkg.To_Pointer(LW1'Address)(1..4);
   Ada.Integer_Text_IO.Put( Integer(LW2), Base => 16 );
   Text_IO.New_Line;
end Ptr_Pkg_Prob;
--
gnatmake -O2 ptr_pkg_prob
ptr_pkg_prob should output:
16#11223344#

2005-06-14  Eric Botcazou  <ebotcazou@adacore.com>

	* s-atacco.ads: Put a pragma No_Strict_Aliasing on Object_Pointer.

Attachment: difs.44
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]