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] Bad bounds checks on slice of explicit dereference


For a slice whose prefix is an explicit dereference of an access to
unconstrained array, the bounds of the slice must be checked against the
actual bounds of the designated object, not the bounds of the index subtype,
as was the case prior to this change.

The following test must compile and execute silently (i.e. Constraint_Error
must be raised at the indicated line):

with Ada.Text_IO; use Ada.Text_IO;
procedure Bounds_Check_Slice_Of_Deref is
   type A is array (Positive range <>) of Integer;
   type AA is access all A;
   X  : AA := new A'(1 .. 2 => 0);
   Y : A (1 .. 3);
begin
   begin
      Y := X.all (1 .. 3); --  RAISE Constraint_Error;
      Put_Line ("FAIL");
   exception
      when Constraint_Error =>
         null;
   end;
end Bounds_Check_Slice_Of_Deref;

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

2010-06-22  Thomas Quinot  <quinot@adacore.com>

	* sem_res.adb (Resolve_Slice): When the prefix is an explicit
	dereference, construct actual subtype of designated object to generate
	proper bounds checks.

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]