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]

Ping^2! Patch for pr35732/39872 "Bounds check off by one"


See http://gcc.gnu.org/ml/fortran/2009-04/msg00283.html.

2009-05-23  Dominique d'Humieres  <dominiq@lps.ens.fr>

	PR fortran/35732
	* trans-array.c (gfc_conv_ss_startstride): Add 1 to get the correct
	size of the sections.

	* gfortran.dg/bound_4.f90: Corrected invalid test case.
	* gfortran.dg/bounds_check_14.f90: Likewise.
	* gfortran.dg/bounds_check_fail_3.f90: New test.
	* gfortran.dg/bounds_check_fail_4.f90: Likewise.


--- ../_gcc_clean/gcc/fortran/trans-array.c	2009-05-14 07:31:18.000000000 +0200
+++ gcc/fortran/trans-array.c	2009-05-23 12:36:17.000000000 +0200
@@ -3256,6 +3256,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-14 23:39:13.000000000 +0200
+++ gcc/testsuite/gfortran.dg/bound_4.f90	2009-05-23 12:36:25.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-14 23:39:13.000000000 +0200
+++ gcc/testsuite/gfortran.dg/bounds_check_14.f90	2009-05-23 12:36:33.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-05-23 12:36:33.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-05-23 12:36:33.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]