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 problem in assigning global variables with address clauses


The code for array assignment assumed that two library level objects
cannot overlap, but that's wrong if either of them has an address
clause.

Consider the following example:

with System.Storage_Elements;
procedure ACopy (Source, Target : System.Address;
                  Byte_Count : Natural) is

     package Sse renames System.Storage_Elements;

     Count : constant Sse.Storage_Count
               := Sse.Storage_Count (Byte_Count);

     subtype Chunk is Sse.Storage_Array (1 .. Count);

     Source_Chunk : Chunk;
     pragma Import (Ada, Source_Chunk);
     for Source_Chunk'Address use Source;

     Target_Chunk : Chunk;
     pragma Import (Ada, Target_Chunk);
     for Target_Chunk'Address use Target;

     use type System.Address;
     use type System.Storage_Elements.Storage_Offset;

     -- It is assumed that address wrapping is not an issue.
     -- We are not copying bytes either from or to
     -- a region that includes (or even abuts) address 0.

begin
        Target_Chunk := Source_Chunk;
end ACopy;

If this is compiled with -S -gnatdt -O2, the tree output should not
have Forwards_OK or Backwards_OK referenced anywhere and the asm file
should show that a memmove is being generated rather than a memcpy.

Tested on x86_64-pc-linux-gnu, committed on trunk

2009-04-17  Robert Dewar  <dewar@adacore.com>

	* exp_ch5.adb (Expand_Assign_Array): Do not set Forwards_OK and
	Backwards_OK if either operand has an address clause.

Attachment: difs
Description: Text document


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