This is the mail archive of the 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]

[gfortran,patch] Correct bounds-checking for FORALL, WHERE and other intrinsics

:ADDPATCH fortran:

Attached patch fixes PR fortran/27874. We currently generate incorrect
checks for FORALL and WHERE intrinsics, e.g. in the following case:

 type t
   integer :: p(1)
 end type
 type (t), dimension (1) :: v
 integer i

 forall (i=1:1,.false.)
   v(i)%p = v(i+1)%p
 end forall

We're first generating a loop to count how many of the mask elements
will be true. During this loop, we were performing bounds-checking on
v(i) and v(i+1) while there really is not reason to do so, because
they're not really used (as the mask isn't true).

The attached patch simply sets the bounds-checking flag to FALSE
before generating this counting loop, and sets it back to its initial
value after. It's crude and I could have added one more argument to
gfc_conv_ss_startstride and a few helper routines in trans-array.c,
but that didn't seem worth it.

Bootstrapped and regtested on i686-linux. With this patch, we're
finally able to execute all the gfortran testsuite with -fbounds-check

OK for mainline and 4.1?

Index: trans-stmt.c
--- trans-stmt.c	(revision 115174)
+++ trans-stmt.c	(working copy)
@@ -1957,6 +1957,7 @@
   gfc_loopinfo loop;
   tree size;
   int i;
+  int save_flag;
   tree tmp;
   *lss = gfc_walk_expr (expr1);
@@ -1989,7 +1990,10 @@
       loop.array_parameter = 1;
       /* Calculate the bounds of the scalarization.  */
+      save_flag = flag_bounds_check;
+      flag_bounds_check = 0;
       gfc_conv_ss_startstride (&loop);
+      flag_bounds_check = save_flag;
       gfc_conv_loop_setup (&loop);
       /* Figure out how many elements we need.  */

Attachment: pr27874.ChangeLog
Description: Binary data

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