diff mbox

[Ada] Bad bounds checks on slice of explicit dereference

Message ID 20100622084940.GA3712@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet June 22, 2010, 8:49 a.m. UTC
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);
      Y := X.all (1 .. 3); --  RAISE Constraint_Error;
      Put_Line ("FAIL");
      when Constraint_Error =>
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.
diff mbox


Index: sem_res.adb
--- sem_res.adb	(revision 161147)
+++ sem_res.adb	(working copy)
@@ -8105,6 +8105,7 @@  package body Sem_Res is
          end if;
       elsif Is_Entity_Name (Name)
+        or else Nkind (Name) = N_Explicit_Dereference
         or else (Nkind (Name) = N_Function_Call
                   and then not Is_Constrained (Etype (Name)))