2008-09-07 Thomas Koenig <tkoenig@gcc.gnu.org>
authortkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 7 Sep 2008 13:33:18 +0000 (13:33 +0000)
committertkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 7 Sep 2008 13:33:18 +0000 (13:33 +0000)
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-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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@140086 138bc75d-0d04-0410-961f-82ee72b054a4

19 files changed:
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/reshape_order_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/reshape_order_2.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/reshape_order_3.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/reshape_order_4.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/generated/reshape_c10.c
libgfortran/generated/reshape_c16.c
libgfortran/generated/reshape_c4.c
libgfortran/generated/reshape_c8.c
libgfortran/generated/reshape_i16.c
libgfortran/generated/reshape_i4.c
libgfortran/generated/reshape_i8.c
libgfortran/generated/reshape_r10.c
libgfortran/generated/reshape_r16.c
libgfortran/generated/reshape_r4.c
libgfortran/generated/reshape_r8.c
libgfortran/intrinsics/reshape_generic.c
libgfortran/m4/reshape.m4

index b05e0c7..1855575 100644 (file)
@@ -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 (file)
index 0000000..3909bfd
--- /dev/null
@@ -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 (file)
index 0000000..3c8ef41
--- /dev/null
@@ -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 (file)
index 0000000..2634880
--- /dev/null
@@ -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 (file)
index 0000000..bd0536d
--- /dev/null
@@ -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" }
index 30b91d1..3a0b248 100644 (file)
@@ -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.
index 732d947..ed54f1b 100644 (file)
@@ -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++)
     {
index 71532c9..6361509 100644 (file)
@@ -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++)
     {
index 4253b06..869d623 100644 (file)
@@ -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++)
     {
index add90f2..24ec469 100644 (file)
@@ -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++)
     {
index e2d5a27..e857b6b 100644 (file)
@@ -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++)
     {
index 3e0c9d6..517d25d 100644 (file)
@@ -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++)
     {
index bf3185e..75ba319 100644 (file)
@@ -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++)
     {
index 9f6159a..2987ef7 100644 (file)
@@ -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++)
     {
index 69578f0..2d84b2b 100644 (file)
@@ -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++)
     {
index 112dbf2..fa68f82 100644 (file)
@@ -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++)
     {
index 015546f..8af5739 100644 (file)
@@ -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++)
     {
index de1e942..5abae82 100644 (file)
@@ -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++)
     {
index a10ad71..400e82c 100644 (file)
@@ -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++)
     {