diff options
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/reshape_order_1.f90 | 18 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/reshape_order_2.f90 | 16 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/reshape_order_3.f90 | 16 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/reshape_order_4.f90 | 16 | ||||
-rw-r--r-- | libgfortran/ChangeLog | 18 | ||||
-rw-r--r-- | libgfortran/generated/reshape_c10.c | 27 | ||||
-rw-r--r-- | libgfortran/generated/reshape_c16.c | 27 | ||||
-rw-r--r-- | libgfortran/generated/reshape_c4.c | 27 | ||||
-rw-r--r-- | libgfortran/generated/reshape_c8.c | 27 | ||||
-rw-r--r-- | libgfortran/generated/reshape_i16.c | 27 | ||||
-rw-r--r-- | libgfortran/generated/reshape_i4.c | 27 | ||||
-rw-r--r-- | libgfortran/generated/reshape_i8.c | 27 | ||||
-rw-r--r-- | libgfortran/generated/reshape_r10.c | 27 | ||||
-rw-r--r-- | libgfortran/generated/reshape_r16.c | 27 | ||||
-rw-r--r-- | libgfortran/generated/reshape_r4.c | 27 | ||||
-rw-r--r-- | libgfortran/generated/reshape_r8.c | 27 | ||||
-rw-r--r-- | libgfortran/intrinsics/reshape_generic.c | 27 | ||||
-rw-r--r-- | libgfortran/m4/reshape.m4 | 27 |
19 files changed, 443 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b05e0c77c2f..18555753d09 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2008-09-07 Thomas Koenig <tkoenig@gcc.gnu.org> + + PR fortran/37203 + * gfortran.d/reshape_order_1.f90: New test case. + * gfortran.d/reshape_order_2.f90: New test case. + * gfortran.d/reshape_order_3.f90: New test case. + * gfortran.d/reshape_order_4.f90: New test case. + 2008-09-07 Richard Guenther <rguenther@suse.de> Ira Rosen <irar@il.ibm.com> diff --git a/gcc/testsuite/gfortran.dg/reshape_order_1.f90 b/gcc/testsuite/gfortran.dg/reshape_order_1.f90 new file mode 100644 index 00000000000..3909bfde22b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/reshape_order_1.f90 @@ -0,0 +1,18 @@ +! { dg-do run } +! { dg-options "-fbounds-check" } +! { dg-shouldfail "Duplicate value 2 in ORDER argument to RESHAPE intrinsic" } +program main + implicit none + integer(kind=1), dimension(6) :: source1 = (/ 1, 2, 3, 4, 5, 6 /) + integer, dimension(2) :: shape1 = (/ 2, 5/) + integer(kind=1), dimension(2) :: pad1 = (/ 0, 0/) + character(len=200) :: l1, l2 + integer :: i1, i2 + + l1 = "2 2" + read(unit=l1,fmt=*) i1, i2 + write (unit=l2,fmt=*) reshape(source1, shape1, pad1, (/i1, i2/)) ! Invalid +end program main +! { dg-output "Fortran runtime error: Duplicate value 2 in ORDER argument to RESHAPE intrinsic" } + + diff --git a/gcc/testsuite/gfortran.dg/reshape_order_2.f90 b/gcc/testsuite/gfortran.dg/reshape_order_2.f90 new file mode 100644 index 00000000000..3c8ef411370 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/reshape_order_2.f90 @@ -0,0 +1,16 @@ +! { dg-do run } +! { dg-options "-fbounds-check" } +! { dg-shouldfail "Value 3 out of range in ORDER argument to RESHAPE intrinsic" } +program main + implicit none + integer(kind=1), dimension(6) :: source1 = (/ 1, 2, 3, 4, 5, 6 /) + integer, dimension(2) :: shape1 = (/ 2, 5/) + integer(kind=1), dimension(2) :: pad1 = (/ 0, 0/) + character(len=200) :: l1, l2 + integer :: i1, i2 + + l1 = "3 2" + read(unit=l1,fmt=*) i1, i2 + write (unit=l2,fmt=*) reshape(source1, shape1, pad1, (/i1, i2/)) ! Invalid +end program main +! { dg-output "Fortran runtime error: Value 3 out of range in ORDER argument to RESHAPE intrinsic" } diff --git a/gcc/testsuite/gfortran.dg/reshape_order_3.f90 b/gcc/testsuite/gfortran.dg/reshape_order_3.f90 new file mode 100644 index 00000000000..263488025d8 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/reshape_order_3.f90 @@ -0,0 +1,16 @@ +! { dg-do run } +! { dg-options "-fbounds-check" } +! { dg-shouldfail "Duplicate value 2 in ORDER argument to RESHAPE intrinsic" } +program main + implicit none + integer(kind=4), dimension(6) :: source1 = (/ 1, 2, 3, 4, 5, 6 /) + integer, dimension(2) :: shape1 = (/ 2, 5/) + integer(kind=4), dimension(2) :: pad1 = (/ 0, 0/) + character(len=200) :: l1, l2 + integer :: i1, i2 + + l1 = "2 2" + read(unit=l1,fmt=*) i1, i2 + write (unit=l2,fmt=*) reshape(source1, shape1, pad1, (/i1, i2/)) ! Invalid +end program main +! { dg-output "Fortran runtime error: Duplicate value 2 in ORDER argument to RESHAPE intrinsic" } diff --git a/gcc/testsuite/gfortran.dg/reshape_order_4.f90 b/gcc/testsuite/gfortran.dg/reshape_order_4.f90 new file mode 100644 index 00000000000..bd0536d844a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/reshape_order_4.f90 @@ -0,0 +1,16 @@ +! { dg-do run } +! { dg-options "-fbounds-check" } +! { dg-shouldfail "Value 0 out of range in ORDER argument to RESHAPE intrinsic" } +program main + implicit none + integer(kind=4), dimension(6) :: source1 = (/ 1, 2, 3, 4, 5, 6 /) + integer, dimension(2) :: shape1 = (/ 2, 5/) + integer(kind=4), dimension(2) :: pad1 = (/ 0, 0/) + character(len=200) :: l1, l2 + integer :: i1, i2 + + l1 = "0 2" + read(unit=l1,fmt=*) i1, i2 + write (unit=l2,fmt=*) reshape(source1, shape1, pad1, (/i1, i2/)) ! Invalid +end program main +! { dg-output "Fortran runtime error: Value 0 out of range in ORDER argument to RESHAPE intrinsic" } diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 30b91d10f90..3a0b2483532 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,21 @@ +2008-09-07 Thomas Koenig <tkoenig@gcc.gnu.org> + + PR fortran/37203 + * intrinsics/reshape_generic.c: Add checking on + out-of-bounds and duplicate values of order argument. + * m4/reshape.m4: Likewise. + * generated/reshape_c10.c: Regenerated. + * generated/reshape_c16.c: Regenerated. + * generated/reshape_c4.c: Regenerated. + * generated/reshape_c8.c: Regenerated. + * generated/reshape_i16.c: Regenerated. + * generated/reshape_i4.c: Regenerated. + * generated/reshape_i8.c: Regenerated. + * generated/reshape_r10.c: Regenerated. + * generated/reshape_r16.c: Regenerated. + * generated/reshape_r4.c: Regenerated. + * generated/reshape_r8.c: Regenerated. + 2008-09-06 Tobias Burnus <burnus@net-b.de> * libgfortran.h (likely,unlikely): New makros. diff --git a/libgfortran/generated/reshape_c10.c b/libgfortran/generated/reshape_c10.c index 732d947a8da..ed54f1b637e 100644 --- a/libgfortran/generated/reshape_c10.c +++ b/libgfortran/generated/reshape_c10.c @@ -119,6 +119,33 @@ reshape_c10 (gfc_array_c10 * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/generated/reshape_c16.c b/libgfortran/generated/reshape_c16.c index 71532c929ef..636150933a0 100644 --- a/libgfortran/generated/reshape_c16.c +++ b/libgfortran/generated/reshape_c16.c @@ -119,6 +119,33 @@ reshape_c16 (gfc_array_c16 * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/generated/reshape_c4.c b/libgfortran/generated/reshape_c4.c index 4253b066815..869d6231239 100644 --- a/libgfortran/generated/reshape_c4.c +++ b/libgfortran/generated/reshape_c4.c @@ -119,6 +119,33 @@ reshape_c4 (gfc_array_c4 * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/generated/reshape_c8.c b/libgfortran/generated/reshape_c8.c index add90f2f205..24ec469bcab 100644 --- a/libgfortran/generated/reshape_c8.c +++ b/libgfortran/generated/reshape_c8.c @@ -119,6 +119,33 @@ reshape_c8 (gfc_array_c8 * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/generated/reshape_i16.c b/libgfortran/generated/reshape_i16.c index e2d5a275842..e857b6b6a24 100644 --- a/libgfortran/generated/reshape_i16.c +++ b/libgfortran/generated/reshape_i16.c @@ -119,6 +119,33 @@ reshape_16 (gfc_array_i16 * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/generated/reshape_i4.c b/libgfortran/generated/reshape_i4.c index 3e0c9d68542..517d25d8703 100644 --- a/libgfortran/generated/reshape_i4.c +++ b/libgfortran/generated/reshape_i4.c @@ -119,6 +119,33 @@ reshape_4 (gfc_array_i4 * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/generated/reshape_i8.c b/libgfortran/generated/reshape_i8.c index bf3185e1c2c..75ba3197f34 100644 --- a/libgfortran/generated/reshape_i8.c +++ b/libgfortran/generated/reshape_i8.c @@ -119,6 +119,33 @@ reshape_8 (gfc_array_i8 * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/generated/reshape_r10.c b/libgfortran/generated/reshape_r10.c index 9f6159aeafb..2987ef7a58c 100644 --- a/libgfortran/generated/reshape_r10.c +++ b/libgfortran/generated/reshape_r10.c @@ -119,6 +119,33 @@ reshape_r10 (gfc_array_r10 * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/generated/reshape_r16.c b/libgfortran/generated/reshape_r16.c index 69578f033a5..2d84b2b8672 100644 --- a/libgfortran/generated/reshape_r16.c +++ b/libgfortran/generated/reshape_r16.c @@ -119,6 +119,33 @@ reshape_r16 (gfc_array_r16 * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/generated/reshape_r4.c b/libgfortran/generated/reshape_r4.c index 112dbf2955d..fa68f826dac 100644 --- a/libgfortran/generated/reshape_r4.c +++ b/libgfortran/generated/reshape_r4.c @@ -119,6 +119,33 @@ reshape_r4 (gfc_array_r4 * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/generated/reshape_r8.c b/libgfortran/generated/reshape_r8.c index 015546ffe1a..8af57393439 100644 --- a/libgfortran/generated/reshape_r8.c +++ b/libgfortran/generated/reshape_r8.c @@ -119,6 +119,33 @@ reshape_r8 (gfc_array_r8 * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/intrinsics/reshape_generic.c b/libgfortran/intrinsics/reshape_generic.c index de1e9426756..5abae82ca03 100644 --- a/libgfortran/intrinsics/reshape_generic.c +++ b/libgfortran/intrinsics/reshape_generic.c @@ -108,6 +108,33 @@ reshape_internal (parray *ret, parray *source, shape_type *shape, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { diff --git a/libgfortran/m4/reshape.m4 b/libgfortran/m4/reshape.m4 index a10ad715584..400e82cde69 100644 --- a/libgfortran/m4/reshape.m4 +++ b/libgfortran/m4/reshape.m4 @@ -123,6 +123,33 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret, if (shape_empty) return; + if (unlikely (compile_options.bounds_check)) + { + if (order) + { + int seen[GFC_MAX_DIMENSIONS]; + index_type v; + + for (n = 0; n < rdim; n++) + seen[n] = 0; + + for (n = 0; n < rdim; n++) + { + v = order->data[n * order->dim[0].stride] - 1; + + if (v < 0 || v >= rdim) + runtime_error("Value %ld out of range in ORDER argument" + " to RESHAPE intrinsic", (long int) v + 1); + + if (seen[v] != 0) + runtime_error("Duplicate value %ld in ORDER argument to" + " RESHAPE intrinsic", (long int) v + 1); + + seen[v] = 1; + } + } + } + rsize = 1; for (n = 0; n < rdim; n++) { |