diff mbox

[Ada] Optimize out index check for dynamic arrays in indirect case

Message ID 20110906103546.GA27774@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Sept. 6, 2011, 10:35 a.m. UTC
This small change brings the indirect case on par with the direct case when it
comes to eliminating an index check for dynamic arrays.  No index check will
be generated for the following procedure in default mode:

   type Darray is array (1 .. Q.N) of Long_Float;

   procedure Add (X, Y : access Darray; R : access Darray) is
   begin
      for I in Darray'Range loop
         R(I) := X(I) + Y(I);
      end loop;
   end;

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

2011-09-06  Eric Botcazou  <ebotcazou@adacore.com>

	* checks.adb (Apply_Scalar_Range_Check): Deal with access
	type prefix.
diff mbox

Patch

Index: checks.adb
===================================================================
--- checks.adb	(revision 178565)
+++ checks.adb	(working copy)
@@ -1877,6 +1877,9 @@ 
       if Is_Subscr_Ref then
          Arr := Prefix (Parnt);
          Arr_Typ := Get_Actual_Subtype_If_Available (Arr);
+         if Is_Access_Type (Arr_Typ) then
+            Arr_Typ := Directly_Designated_Type (Arr_Typ);
+         end if;
       end if;
 
       if not Do_Range_Check (Expr) then