This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

Patch for pr35732/39872 "Bounds check off by one"


Here is a patch* for pr35732/39872 "Bounds check off by one". The patch 
itself is obvious: add one to the number of intervals to get the number of 
elements.

However it uncovered invalid codes for gfortran.dg/bound_4.f90 and
bounds_check_14.f90 (in case of doubts, please do the tests with the
following changes:

16c16
<   integer xca(1), xda(1), mf3
---
>   integer xca(2), xda(2), mf3
21c21
<   xca(1:1) = xda(1:2:mf3)
---
>   xca(1:2) = xda(1:2:mf3)

which make both test to fails, at least if the memory before XDA does not 
contains a -1).

I think the proposed changes in the tests keep the idea of the original 
post in pr35682 while making the codes valid (Steve do you agree with 
that?).

I have also added two new tests. I am not sure about the second one since 
the error is a bit misleading (should I add it to an already opened PR, if 
any, or open a new one, if not?).

The modified and new tests have been regtested on powerpc-apple-darwin9 and
the patch in trans-array.c have been regtested without other regression
than gfortran.dg/bounds_check_14.f90 on i686-apple-darwin9 (I am planning a
full regtest tonight on both platforms)

Cheers

Dominique

* The patch in comment #6 of pr35732 does not apply, probably due to
tab/space problems.  If someone can give me hints on how I can avoid them,
he will be welcomed.

** Once I get an agreement about the patch, I'll do the packaging and
formal submission.  However someone will have to commit it for me.  I think
the patch falls in the obvious category and does not require FSF paperwork.

--- ../_gcc_clean/gcc/fortran/trans-array.c	2009-04-20 14:58:50.000000000 +0200
+++ gcc/fortran/trans-array.c	2009-04-28 10:42:10.000000000 +0200
@@ -3253,6 +3253,8 @@ gfc_conv_ss_startstride (gfc_loopinfo * 
				 info->start[n]);
	      tmp = fold_build2 (FLOOR_DIV_EXPR, gfc_array_index_type, tmp,
				 info->stride[n]);
+	      tmp = fold_build2 (PLUS_EXPR, gfc_array_index_type,
+				 gfc_index_one_node, tmp);
	      tmp = fold_build2 (MAX_EXPR, gfc_array_index_type, tmp,
				 build_int_cst (gfc_array_index_type, 0));
	      /* We remember the size of the first section, and check all the
--- ../_gcc_clean/gcc/testsuite/gfortran.dg/bound_4.f90	2008-05-15 07:40:18.000000000 +0200
+++ gcc/testsuite/gfortran.dg/bound_4.f90	2009-04-28 13:13:20.000000000 +0200
@@ -12,14 +12,14 @@ end program test
 
 subroutine ha0020(mf3)
   implicit none
-  integer xca(1), xda(1), mf3
+  integer xca(2), xda(2), mf3
 
   xca = 1
   xda = -1
 
-  xca(1:1) = xda(1:2:mf3)
+  xca(1:2:-1) = xda(1:2:mf3)
 
-  if (any (xca /= -1)) call abort
+  if (any (xca /= 1)) call abort
   if (any(xda(1:2:mf3) /= xda(1:0))) call abort
   if (size(xda(1:2:mf3)) /= 0) call abort
   if (any(shape(xda(1:2:mf3)) /= 0)) call abort
--- ../_gcc_clean/gcc/testsuite/gfortran.dg/bounds_check_14.f90	2008-05-15 07:40:18.000000000 +0200
+++ gcc/testsuite/gfortran.dg/bounds_check_14.f90	2009-04-28 13:11:28.000000000 +0200
@@ -13,14 +13,14 @@ end program test
 
 subroutine ha0020(mf3)
   implicit none
-  integer xca(1), xda(1), mf3
+  integer xca(2), xda(2), mf3
 
   xca = 1
   xda = -1
 
-  xca(1:1) = xda(1:2:mf3)
+  xca(1:2:-1) = xda(1:2:mf3)
 
-  if (any (xca /= -1)) call abort
+  if (any (xca /= 1)) call abort
   if (any(xda(1:2:mf3) /= xda(1:0))) call abort
   if (size(xda(1:2:mf3)) /= 0) call abort
   if (any(shape(xda(1:2:mf3)) /= 0)) call abort
--- ../_gcc_clean/gcc/testsuite/gfortran.dg/bounds_check_fail_3.f90	1970-01-01 01:00:00.000000000 +0100
+++ gcc/testsuite/gfortran.dg/bounds_check_fail_3.f90	2009-04-28 13:09:05.000000000 +0200
@@ -0,0 +1,12 @@
+! { dg-do run }
+! { dg-options "-fbounds-check" }
+! { dg-shouldfail "foo" }
+  integer x(10), m, n
+  x = (/ (i, i = 1, 10) /)
+  m = -3
+  n = -2
+  x(7:1:m) = x(6:2:n) 
+  if (any(x /= (/ 2, 2, 3, 4, 5, 6, 6, 8, 9, 10 /))) call abort()
+  x(8:1:m) = x(5:2:n) 
+  end
+! { dg-output "line 10 .* bound mismatch, .* dimension 1 .* array \'x\' \\\(3/2\\\)" }
--- ../_gcc_clean/gcc/testsuite/gfortran.dg/bounds_check_fail_4.f90	1970-01-01 01:00:00.000000000 +0100
+++ gcc/testsuite/gfortran.dg/bounds_check_fail_4.f90	2009-04-28 14:31:15.000000000 +0200
@@ -0,0 +1,12 @@
+! { dg-do run }
+! { dg-options "-fbounds-check" }
+! { dg-shouldfail "foo" }
+  integer x(10), m, n
+  x = (/ (i, i = 1, 10) /)
+  m = -3
+  n = -2
+  x(7:1:m) = x(1:3) + x(6:2:n) 
+  if (any(x /= (/ 5, 2, 3, 6, 5, 6, 7, 8, 9, 10 /))) call abort()
+  x(8:1:m) = x(1:3) + x(5:2:n) 
+  end
+! { dg-output "line 10 .* bound mismatch, .* dimension 1 .* array \'x\' \\\(2/3\\\)" }


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