re PR fortran/35960 (run time abort with assignment of RESHAPEd zero sized array)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 20 Apr 2008 19:56:07 +0000 (19:56 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 20 Apr 2008 19:56:07 +0000 (19:56 +0000)
2008-04-20  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR libfortran/35960
* intrinsics/reshape_generic.c (reshape_internal): If the size
of the resized array is zero, as determined by the SHAPE
argument, return early.
* m4/reshape.m4:  Likewise.
* generated/reshape_i4.c:  Regererated.
* generated/reshape_i8.c:  Regenerated.
* generated/reshape_i16.c:  Regenerated.
* generated/reshape_r4.c:  Regenerated.
* generated/reshape_r8.c:  Regenerated.
* generated/reshape_r10.c:  Regenerated.
* generated/reshape_r16.c:  Regenerated.
* generated/reshape_c4.c:  Regenerated.
* generated/reshape_c8.c:  Regenerated.
* generated/reshape_c10.c:  Regenerated.
* generated/reshape_c16.c:  Regenerated.

2008-04-20  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR libfortran/35960
* gfortran.dg/reshape_zerosize_1.f90:  New file.

From-SVN: r134490

16 files changed:
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/reshape_zerosize_1.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 d200785acb6a1d363c871d4480fd4e3006b6f84b..d2435caaa72cb25d947845b7d5e293a4f9f16eac 100644 (file)
@@ -1,3 +1,8 @@
+2008-04-20  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR libfortran/35960
+       * gfortran.dg/reshape_zerosize_1.f90:  New file.
+
 2008-04-20  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/alignment6.adb: New test.
diff --git a/gcc/testsuite/gfortran.dg/reshape_zerosize_1.f90 b/gcc/testsuite/gfortran.dg/reshape_zerosize_1.f90
new file mode 100644 (file)
index 0000000..61896ab
--- /dev/null
@@ -0,0 +1,39 @@
+!  { dg-do run }
+!  PR 35960 - there was a run-time abort when the SHAPE argument to
+!  RESHAPE was zero-sized.
+!  Test case contributed by Dick Henderson.
+      program try_gf1065
+
+
+! fails on Windows XP
+! gcc version 4.4.0 20080312 (experimental) [trunk revision 133139]
+
+
+      call       gf1065(1,  2,  3,  4,  7,  8,  9)
+      end
+
+      SUBROUTINE GF1065(nf1,nf2,nf3,nf4,nf7,nf8,nf9)
+
+      REAL RDA(10,9)
+      REAL RCA1(90)
+      integer ila(2)
+      RDA(NF9:NF8, NF7:NF3) = RESHAPE(RCA1,(/0,0/), (/1.0/),(/2,1/))
+
+      rDA(NF9:NF8, NF7:NF3) = RESHAPE(rCA1,(/0,0/),ORDER=(/2,1/))
+
+      ILA(1) = 5
+      ILA(2) = 0
+      rDA(NF4:NF8, NF7:NF3) = RESHAPE(rcA1,ILA)
+
+      RdA(NF4:NF8, NF7:NF3) = RESHAPE(RcA1,ILA,PAD=(/-1.0/))
+
+      ILA(1) = 0
+      ILA(2) = 5
+      RdA(NF9:NF8,NF4:NF8)=RESHAPE(RcA1,ILA,(/-1.0/),(/NF2,NF1/))
+
+      ILA(1) = 5
+      ILA(2) = 0
+      RdA(NF4:NF8, NF7:NF3) = RESHAPE(RcA1,ILA,ORDER=(/NF1,NF2/))
+
+
+      END SUBROUTINE
index 5c11a3d626b4a25d7798eecdd2c3d48e77fd68d3..922eef795d25a8b3bc2efab291dfba6f78f4e01c 100644 (file)
@@ -1,3 +1,22 @@
+2008-04-20  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR libfortran/35960
+       * intrinsics/reshape_generic.c (reshape_internal): If the size
+       of the resized array is zero, as determined by the SHAPE
+       argument, return early.
+       * m4/reshape.m4:  Likewise.
+       * generated/reshape_i4.c:  Regererated.
+       * generated/reshape_i8.c:  Regenerated.
+       * generated/reshape_i16.c:  Regenerated.
+       * generated/reshape_r4.c:  Regenerated.
+       * generated/reshape_r8.c:  Regenerated.
+       * generated/reshape_r10.c:  Regenerated.
+       * generated/reshape_r16.c:  Regenerated.
+       * generated/reshape_c4.c:  Regenerated.
+       * generated/reshape_c8.c:  Regenerated.
+       * generated/reshape_c10.c:  Regenerated.
+       * generated/reshape_c16.c:  Regenerated.
+
 2008-04-18  Paolo Bonzini  <bonzini@gnu.org>
 
        PR bootstrap/35457
index b9eb754481a17148c0cb056a3fbfeaf65caa26e7..28cad4a0b6ed368eea8cc3ef20a9201aa39f5fa7 100644 (file)
@@ -81,16 +81,32 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
   const GFC_COMPLEX_10 *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+      {
+        shape_data[n] = 0;
+       shape_empty = 1;
+      }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -99,10 +115,9 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof (GFC_COMPLEX_10));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -115,8 +130,10 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index c9cdaa931a9ed44ee5dcdc7ce32f3423ac587153..ce658dae66870d83004a4815f4d38adaf0460441 100644 (file)
@@ -81,16 +81,32 @@ reshape_c16 (gfc_array_c16 * const restrict ret,
   const GFC_COMPLEX_16 *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+      {
+        shape_data[n] = 0;
+       shape_empty = 1;
+      }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -99,10 +115,9 @@ reshape_c16 (gfc_array_c16 * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof (GFC_COMPLEX_16));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -115,8 +130,10 @@ reshape_c16 (gfc_array_c16 * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index 3d1eac248240c69efe19ee2e11e47c317d87f8ac..fd33a954a06b8599eed2c0dd7d0551e4870e18de 100644 (file)
@@ -81,16 +81,32 @@ reshape_c4 (gfc_array_c4 * const restrict ret,
   const GFC_COMPLEX_4 *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+      {
+        shape_data[n] = 0;
+       shape_empty = 1;
+      }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -99,10 +115,9 @@ reshape_c4 (gfc_array_c4 * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof (GFC_COMPLEX_4));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -115,8 +130,10 @@ reshape_c4 (gfc_array_c4 * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index 4a4a3e681617111f2626446c26ccf22b3b35cb3b..d23cf88c0a34b2011f769ed81a912c9f5b2a6cf4 100644 (file)
@@ -81,16 +81,32 @@ reshape_c8 (gfc_array_c8 * const restrict ret,
   const GFC_COMPLEX_8 *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+      {
+        shape_data[n] = 0;
+       shape_empty = 1;
+      }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -99,10 +115,9 @@ reshape_c8 (gfc_array_c8 * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof (GFC_COMPLEX_8));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -115,8 +130,10 @@ reshape_c8 (gfc_array_c8 * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index 9e58dcc3d5a9895dd3f3fe110f83065d4c7feda2..c9b3694c5deb83ac4d05b44e48d3df6c1c38cc2d 100644 (file)
@@ -81,16 +81,32 @@ reshape_16 (gfc_array_i16 * const restrict ret,
   const GFC_INTEGER_16 *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+      {
+        shape_data[n] = 0;
+       shape_empty = 1;
+      }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -99,10 +115,9 @@ reshape_16 (gfc_array_i16 * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof (GFC_INTEGER_16));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -115,8 +130,10 @@ reshape_16 (gfc_array_i16 * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index b8114123a8a6ca184e90e507429f367412b76eda..4a55b68fed6957fe3013921b0b5518a48c2bb29d 100644 (file)
@@ -81,16 +81,32 @@ reshape_4 (gfc_array_i4 * const restrict ret,
   const GFC_INTEGER_4 *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+       {
+          shape_data[n] = 0;
+         shape_empty = 1;
+        }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -99,10 +115,9 @@ reshape_4 (gfc_array_i4 * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof (GFC_INTEGER_4));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -115,8 +130,10 @@ reshape_4 (gfc_array_i4 * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index ffec9bb8d6e9d0dc838b540d7106bc3e43d9c3c9..d496ca9d7efc23afd806e70977140162e6ad4cc1 100644 (file)
@@ -81,16 +81,32 @@ reshape_8 (gfc_array_i8 * const restrict ret,
   const GFC_INTEGER_8 *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+      {
+        shape_data[n] = 0;
+       shape_empty = 1;
+      }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -99,10 +115,9 @@ reshape_8 (gfc_array_i8 * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof (GFC_INTEGER_8));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -115,8 +130,10 @@ reshape_8 (gfc_array_i8 * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index 8bca529b7c9ac1609515dd92948ab450d8f30d06..61e367c96ce78769bf0c809c6d381297f65cdbfd 100644 (file)
@@ -81,16 +81,32 @@ reshape_r10 (gfc_array_r10 * const restrict ret,
   const GFC_REAL_10 *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+      {
+        shape_data[n] = 0;
+       shape_empty = 1;
+      }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -99,10 +115,9 @@ reshape_r10 (gfc_array_r10 * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof (GFC_REAL_10));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -115,8 +130,10 @@ reshape_r10 (gfc_array_r10 * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index cd5527297f847d6a6f02a399cc3c44876ccec5db..f04fe32c6a82a391b111734fed94c674d47b801c 100644 (file)
@@ -81,16 +81,32 @@ reshape_r16 (gfc_array_r16 * const restrict ret,
   const GFC_REAL_16 *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+      {
+        shape_data[n] = 0;
+       shape_empty = 1;
+      }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -99,10 +115,9 @@ reshape_r16 (gfc_array_r16 * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof (GFC_REAL_16));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -115,8 +130,10 @@ reshape_r16 (gfc_array_r16 * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index ace0f4e7728f258ab04c3425b63bb94087e6db0c..0323a7246242d884a227b5b15fa83a7072bfdcc0 100644 (file)
@@ -81,16 +81,32 @@ reshape_r4 (gfc_array_r4 * const restrict ret,
   const GFC_REAL_4 *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+      {
+        shape_data[n] = 0;
+       shape_empty = 1;
+      }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -99,10 +115,9 @@ reshape_r4 (gfc_array_r4 * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof (GFC_REAL_4));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -115,8 +130,10 @@ reshape_r4 (gfc_array_r4 * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index 8d0fd6619c5f0ee874647df688f669f630dd9fb4..e6be1ef03be4b0b0258ba91f0f6b1f9bd534c766 100644 (file)
@@ -81,16 +81,32 @@ reshape_r8 (gfc_array_r8 * const restrict ret,
   const GFC_REAL_8 *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+      {
+        shape_data[n] = 0;
+       shape_empty = 1;
+      }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -99,10 +115,9 @@ reshape_r8 (gfc_array_r8 * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof (GFC_REAL_8));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -115,8 +130,10 @@ reshape_r8 (gfc_array_r8 * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index 333f99d2610fa3395302168d952475e1a856ec9b..e28ed69feba9a4ef521977b90cd5aa9a5151f14a 100644 (file)
@@ -69,7 +69,24 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
   const char *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+       {
+         shape_data[n] = 0;
+         shape_empty = 1;
+       }
+    }
 
   if (ret->data == NULL)
     {
@@ -78,7 +95,7 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -87,10 +104,9 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
       ret->data = internal_malloc_size ( rs * size );
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -104,7 +120,7 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])
index de936f0191a45f097656eaacd9e0548c95db6e23..ed060ecb9ff155787379a13d19d38bdeea2058bd 100644 (file)
@@ -85,16 +85,32 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
   const 'rtype_name` *src;
   int n;
   int dim;
-  int sempty, pempty;
+  int sempty, pempty, shape_empty;
+  index_type shape_data[GFC_MAX_DIMENSIONS];
+
+  rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
+  if (rdim != GFC_DESCRIPTOR_RANK(ret))
+    runtime_error("rank of return array incorrect in RESHAPE intrinsic");
+
+  shape_empty = 0;
+
+  for (n = 0; n < rdim; n++)
+    {
+      shape_data[n] = shape->data[n * shape->dim[0].stride];
+      if (shape_data[n] <= 0)
+      {
+        shape_data[n] = 0;
+       shape_empty = 1;
+      }
+    }
 
   if (ret->data == NULL)
     {
-      rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
       for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
-         rex = shape->data[n * shape->dim[0].stride];
+         rex = shape_data[n];
          ret->dim[n].ubound =  rex - 1;
          ret->dim[n].stride = rs;
          rs *= rex;
@@ -103,10 +119,9 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
       ret->data = internal_malloc_size ( rs * sizeof ('rtype_name`));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
-  else
-    {
-      rdim = GFC_DESCRIPTOR_RANK (ret);
-    }
+
+  if (shape_empty)
+    return;
 
   rsize = 1;
   for (n = 0; n < rdim; n++)
@@ -119,8 +134,10 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
       rcount[n] = 0;
       rstride[n] = ret->dim[dim].stride;
       rextent[n] = ret->dim[dim].ubound + 1 - ret->dim[dim].lbound;
+      if (rextent[n] < 0)
+        rextent[n] == 0;
 
-      if (rextent[n] != shape->data[dim * shape->dim[0].stride])
+      if (rextent[n] != shape_data[dim])
         runtime_error ("shape and target do not conform");
 
       if (rsize == rstride[n])