]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libfortran/27895 (problem with RESHAPE and zero-sized arrays)
authorFrancois-Xavier Coudert <coudert@clipper.ens.fr>
Fri, 3 Nov 2006 11:51:09 +0000 (12:51 +0100)
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Fri, 3 Nov 2006 11:51:09 +0000 (11:51 +0000)
PR libfortran/27895

* intrinsics/reshape_generic.c (reshape_internal): Fix so that it
works correctly for zero-sized arrays.
* m4/reshape.m4: Likewise.
* generated/reshape_r16.c: Regenerate.
* generated/reshape_c4.c: Regenerate.
* generated/reshape_i4.c: Regenerate.
* generated/reshape_c16.c: Regenerate.
* generated/reshape_r10.c: Regenerate.
* generated/reshape_r8.c: Regenerate.
* generated/reshape_c10.c: Regenerate.
* generated/reshape_c8.c: Regenerate.
* generated/reshape_i8.c: Regenerate.
* generated/reshape_i16.c: Regenerate.
* generated/reshape_r4.c: Regenerate.

* gcc/testsuite/gfortran.dg/zero_sized_1.f90: Uncomment checks
for RESHAPE.

From-SVN: r118455

16 files changed:
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/zero_sized_1.f90
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 51bceea576c01db3b99ede93b59e7fe267fc1ffc..7a20460353036285e9ddf095dfa5bcf20fffe759 100644 (file)
@@ -1,3 +1,9 @@
+2006-11-03  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR libfortran/27895
+       * gcc/testsuite/gfortran.dg/zero_sized_1.f90: Uncomment checks
+       for RESHAPE.
+
 2006-11-02  Brooks Moses  <brooks.moses@codesourcery.com>
 
        * lib/gfortran-dg.exp (gfortran-dg-test): Remove expected "In file"
index c70bdddd6d79673bd62909fa677ea353e7df330d..224b2c007d3074447e11709534572667363b1460 100644 (file)
@@ -193,5 +193,5 @@ program test
   call test_unpack
   call test_spread
   call test_pack
-!  call test_reshape
+  call test_reshape
 end
index 54849e08c9365d1dee700e53c651edf6aa7d9042..8b5eddff4ec221afbe57dbb8273815087712b3a5 100644 (file)
@@ -1,3 +1,21 @@
+2006-11-03  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR libfortran/27895
+       * intrinsics/reshape_generic.c (reshape_internal): Fix so that it
+       works correctly for zero-sized arrays.
+       * m4/reshape.m4: Likewise.
+       * generated/reshape_r16.c: Regenerate.
+       * generated/reshape_c4.c: Regenerate.
+       * generated/reshape_i4.c: Regenerate.
+       * generated/reshape_c16.c: Regenerate.
+       * generated/reshape_r10.c: Regenerate.
+       * generated/reshape_r8.c: Regenerate.
+       * generated/reshape_c10.c: Regenerate.
+       * generated/reshape_c8.c: Regenerate.
+       * generated/reshape_i8.c: Regenerate.
+       * generated/reshape_i16.c: Regenerate.
+       * generated/reshape_r4.c: Regenerate.
+
 2006-10-31  Thomas Koenig  <Thomas.Koenig@online.de>
 
        PR libfortran/29627
index 7aa7f43eef61925e19aa944ab408a48235dec165..1440e75b116a9ce243fff6fda0a96760af0a67e7 100644 (file)
@@ -37,8 +37,6 @@ Boston, MA 02110-1301, USA.  */
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
 
 extern void reshape_c10 (gfc_array_c10 * const restrict, 
        gfc_array_c10 * const restrict, 
@@ -83,12 +81,13 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
   const GFC_COMPLEX_10 *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -130,13 +129,17 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -148,13 +151,18 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -166,6 +174,7 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -183,6 +192,24 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (GFC_COMPLEX_10);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -192,6 +219,7 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
index cc1fd0dec5b28391584850b5c94b870047d2928f..2ab6111cf3c55a94efafca3aa7a4dc590e068939 100644 (file)
@@ -37,8 +37,6 @@ Boston, MA 02110-1301, USA.  */
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
 
 extern void reshape_c16 (gfc_array_c16 * const restrict, 
        gfc_array_c16 * const restrict, 
@@ -83,12 +81,13 @@ reshape_c16 (gfc_array_c16 * const restrict ret,
   const GFC_COMPLEX_16 *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -130,13 +129,17 @@ reshape_c16 (gfc_array_c16 * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -148,13 +151,18 @@ reshape_c16 (gfc_array_c16 * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -166,6 +174,7 @@ reshape_c16 (gfc_array_c16 * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -183,6 +192,24 @@ reshape_c16 (gfc_array_c16 * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (GFC_COMPLEX_16);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -192,6 +219,7 @@ reshape_c16 (gfc_array_c16 * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
index 5e7d855be845bf1c3c9fa8d993620ba067742f06..66b162218f64e52475c6e44e93ec813a99995e79 100644 (file)
@@ -37,8 +37,6 @@ Boston, MA 02110-1301, USA.  */
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
 
 extern void reshape_c4 (gfc_array_c4 * const restrict, 
        gfc_array_c4 * const restrict, 
@@ -83,12 +81,13 @@ reshape_c4 (gfc_array_c4 * const restrict ret,
   const GFC_COMPLEX_4 *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -130,13 +129,17 @@ reshape_c4 (gfc_array_c4 * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -148,13 +151,18 @@ reshape_c4 (gfc_array_c4 * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -166,6 +174,7 @@ reshape_c4 (gfc_array_c4 * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -183,6 +192,24 @@ reshape_c4 (gfc_array_c4 * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (GFC_COMPLEX_4);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -192,6 +219,7 @@ reshape_c4 (gfc_array_c4 * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
index aecacac9d16cefcfab68ddff9ba7a3c0e2cd2aac..89316539443139a92ccbf5aa22bbf7a0f4e3c97b 100644 (file)
@@ -37,8 +37,6 @@ Boston, MA 02110-1301, USA.  */
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
 
 extern void reshape_c8 (gfc_array_c8 * const restrict, 
        gfc_array_c8 * const restrict, 
@@ -83,12 +81,13 @@ reshape_c8 (gfc_array_c8 * const restrict ret,
   const GFC_COMPLEX_8 *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -130,13 +129,17 @@ reshape_c8 (gfc_array_c8 * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -148,13 +151,18 @@ reshape_c8 (gfc_array_c8 * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -166,6 +174,7 @@ reshape_c8 (gfc_array_c8 * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -183,6 +192,24 @@ reshape_c8 (gfc_array_c8 * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (GFC_COMPLEX_8);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -192,6 +219,7 @@ reshape_c8 (gfc_array_c8 * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
index 0b4da5c957fa97d93f6e6832d7426590337c9f35..c8777cfc09bcb13b798314c13dbb438e41a58a9c 100644 (file)
@@ -37,8 +37,6 @@ Boston, MA 02110-1301, USA.  */
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
 
 extern void reshape_16 (gfc_array_i16 * const restrict, 
        gfc_array_i16 * const restrict, 
@@ -83,12 +81,13 @@ reshape_16 (gfc_array_i16 * const restrict ret,
   const GFC_INTEGER_16 *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -130,13 +129,17 @@ reshape_16 (gfc_array_i16 * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -148,13 +151,18 @@ reshape_16 (gfc_array_i16 * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -166,6 +174,7 @@ reshape_16 (gfc_array_i16 * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -183,6 +192,24 @@ reshape_16 (gfc_array_i16 * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (GFC_INTEGER_16);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -192,6 +219,7 @@ reshape_16 (gfc_array_i16 * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
index 413762e60430886e7f67e11069c3e9827ce2e779..f51b73096d8931b95cbc1c9d82d0cb911995ae89 100644 (file)
@@ -37,8 +37,6 @@ Boston, MA 02110-1301, USA.  */
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
 
 extern void reshape_4 (gfc_array_i4 * const restrict, 
        gfc_array_i4 * const restrict, 
@@ -83,12 +81,13 @@ reshape_4 (gfc_array_i4 * const restrict ret,
   const GFC_INTEGER_4 *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -130,13 +129,17 @@ reshape_4 (gfc_array_i4 * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -148,13 +151,18 @@ reshape_4 (gfc_array_i4 * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -166,6 +174,7 @@ reshape_4 (gfc_array_i4 * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -183,6 +192,24 @@ reshape_4 (gfc_array_i4 * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (GFC_INTEGER_4);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -192,6 +219,7 @@ reshape_4 (gfc_array_i4 * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
index 0cd861a506013087608fe0fdb3f53928f255736f..463919db1883eebaeea62b01d3e87c21c6966ea4 100644 (file)
@@ -37,8 +37,6 @@ Boston, MA 02110-1301, USA.  */
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
 
 extern void reshape_8 (gfc_array_i8 * const restrict, 
        gfc_array_i8 * const restrict, 
@@ -83,12 +81,13 @@ reshape_8 (gfc_array_i8 * const restrict ret,
   const GFC_INTEGER_8 *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -130,13 +129,17 @@ reshape_8 (gfc_array_i8 * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -148,13 +151,18 @@ reshape_8 (gfc_array_i8 * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -166,6 +174,7 @@ reshape_8 (gfc_array_i8 * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -183,6 +192,24 @@ reshape_8 (gfc_array_i8 * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (GFC_INTEGER_8);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -192,6 +219,7 @@ reshape_8 (gfc_array_i8 * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
index 5069e45cdb1d477031437950e205536d1adf427a..c3d414320ade3a1c1d8c36db62ce2f728009e48e 100644 (file)
@@ -37,8 +37,6 @@ Boston, MA 02110-1301, USA.  */
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
 
 extern void reshape_r10 (gfc_array_r10 * const restrict, 
        gfc_array_r10 * const restrict, 
@@ -83,12 +81,13 @@ reshape_r10 (gfc_array_r10 * const restrict ret,
   const GFC_REAL_10 *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -130,13 +129,17 @@ reshape_r10 (gfc_array_r10 * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -148,13 +151,18 @@ reshape_r10 (gfc_array_r10 * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -166,6 +174,7 @@ reshape_r10 (gfc_array_r10 * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -183,6 +192,24 @@ reshape_r10 (gfc_array_r10 * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (GFC_REAL_10);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -192,6 +219,7 @@ reshape_r10 (gfc_array_r10 * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
index d954c43e1c7a27225ea418f68ae5d03015fa61ac..a8ba40b421bea6e9e7c40e49494b2d10f6b04f58 100644 (file)
@@ -37,8 +37,6 @@ Boston, MA 02110-1301, USA.  */
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
 
 extern void reshape_r16 (gfc_array_r16 * const restrict, 
        gfc_array_r16 * const restrict, 
@@ -83,12 +81,13 @@ reshape_r16 (gfc_array_r16 * const restrict ret,
   const GFC_REAL_16 *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -130,13 +129,17 @@ reshape_r16 (gfc_array_r16 * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -148,13 +151,18 @@ reshape_r16 (gfc_array_r16 * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -166,6 +174,7 @@ reshape_r16 (gfc_array_r16 * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -183,6 +192,24 @@ reshape_r16 (gfc_array_r16 * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (GFC_REAL_16);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -192,6 +219,7 @@ reshape_r16 (gfc_array_r16 * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
index 72eb06e9af14655c7c8e32e562c1cc9293570bb2..b03900ae29f8a4b8da05fee182a9a89887247661 100644 (file)
@@ -37,8 +37,6 @@ Boston, MA 02110-1301, USA.  */
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
 
 extern void reshape_r4 (gfc_array_r4 * const restrict, 
        gfc_array_r4 * const restrict, 
@@ -83,12 +81,13 @@ reshape_r4 (gfc_array_r4 * const restrict ret,
   const GFC_REAL_4 *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -130,13 +129,17 @@ reshape_r4 (gfc_array_r4 * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -148,13 +151,18 @@ reshape_r4 (gfc_array_r4 * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -166,6 +174,7 @@ reshape_r4 (gfc_array_r4 * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -183,6 +192,24 @@ reshape_r4 (gfc_array_r4 * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (GFC_REAL_4);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -192,6 +219,7 @@ reshape_r4 (gfc_array_r4 * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
index 065fb3d351d6ce9fdb5e423cb450071f82aedda0..2a3e73380188b8444f18e9ff2fae18fc2232e391 100644 (file)
@@ -37,8 +37,6 @@ Boston, MA 02110-1301, USA.  */
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
 
 extern void reshape_r8 (gfc_array_r8 * const restrict, 
        gfc_array_r8 * const restrict, 
@@ -83,12 +81,13 @@ reshape_r8 (gfc_array_r8 * const restrict ret,
   const GFC_REAL_8 *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -130,13 +129,17 @@ reshape_r8 (gfc_array_r8 * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -148,13 +151,18 @@ reshape_r8 (gfc_array_r8 * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -166,6 +174,7 @@ reshape_r8 (gfc_array_r8 * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -183,6 +192,24 @@ reshape_r8 (gfc_array_r8 * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (GFC_REAL_8);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -192,6 +219,7 @@ reshape_r8 (gfc_array_r8 * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
index 97860b66299e8ccbad8c8be6f6bfd5fc90a56a1e..c58fab017953bc09bdcb459632d3c1115ce3f887 100644 (file)
@@ -37,9 +37,6 @@ Boston, MA 02110-1301, USA.  */
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 typedef GFC_ARRAY_DESCRIPTOR(GFC_MAX_DIMENSIONS, char) parray;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
-
 static void
 reshape_internal (parray *ret, parray *source, shape_type *shape,
                  parray *pad, shape_type *order, index_type size)
@@ -73,12 +70,13 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
   const char *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -120,13 +118,17 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -138,13 +140,18 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+              pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -156,6 +163,7 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -173,6 +181,24 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
   rstride0 = rstride[0] * size;
   sstride0 = sstride[0] * size;
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * size;
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -182,6 +208,7 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])
@@ -204,7 +231,8 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
               rcount[n]++;
               rptr += rstride[n] * size;
             }
-        }
+       }
+
       /* Advance to the next source element.  */
       n = 0;
       while (scount[n] == sextent[n])
index ed594fbfa6884ce5389f59c8102aadaadda4ae21..345837a32cc39219721ed750635c0ebe539a0fa3 100644 (file)
@@ -38,9 +38,9 @@ include(iparm.m4)dnl
 
 typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
 
-/* The shape parameter is ignored. We can currently deduce the shape from the
-   return array.  */
-dnl Only the kind (ie size) is used to name the function.
+dnl For integer routines, only the kind (ie size) is used to name the
+dnl function.  The same function will be used for integer and logical
+dnl arrays of the same kind.
 
 extern void reshape_`'rtype_ccode (rtype * const restrict, 
        rtype * const restrict, 
@@ -85,12 +85,13 @@ reshape_`'rtype_ccode (rtype * const restrict ret,
   const rtype_name *src;
   int n;
   int dim;
+  int sempty, pempty;
 
   if (ret->data == NULL)
     {
       rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
       rs = 1;
-      for (n=0; n < rdim; n++)
+      for (n = 0; n < rdim; n++)
        {
          ret->dim[n].lbound = 0;
          rex = shape->data[n * shape->dim[0].stride];
@@ -132,13 +133,17 @@ reshape_`'rtype_ccode (rtype * const restrict ret,
 
   sdim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
+  sempty = 0;
   for (n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = source->dim[n].stride;
       sextent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
       if (sextent[n] <= 0)
-        abort ();
+       {
+         sempty = 1;
+         sextent[n] = 0;
+       }
 
       if (ssize == sstride[n])
         ssize *= sextent[n];
@@ -150,13 +155,18 @@ reshape_`'rtype_ccode (rtype * const restrict ret,
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
+      pempty = 0;
       for (n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = pad->dim[n].stride;
           pextent[n] = pad->dim[n].ubound + 1 - pad->dim[n].lbound;
           if (pextent[n] <= 0)
-            abort ();
+           {
+             pempty = 1;
+             pextent[n] = 0;
+           }
+
           if (psize == pstride[n])
             psize *= pextent[n];
           else
@@ -168,6 +178,7 @@ reshape_`'rtype_ccode (rtype * const restrict ret,
     {
       pdim = 0;
       psize = 1;
+      pempty = 1;
       pptr = NULL;
     }
 
@@ -185,6 +196,24 @@ reshape_`'rtype_ccode (rtype * const restrict ret,
   rstride0 = rstride[0];
   sstride0 = sstride[0];
 
+  if (sempty && pempty)
+    abort ();
+
+  if (sempty)
+    {
+      /* Switch immediately to the pad array.  */
+      src = pptr;
+      sptr = NULL;
+      sdim = pdim;
+      for (dim = 0; dim < pdim; dim++)
+       {
+         scount[dim] = pcount[dim];
+         sextent[dim] = pextent[dim];
+         sstride[dim] = pstride[dim];
+         sstride0 = sstride[0] * sizeof (rtype_name);
+       }
+    }
+
   while (rptr)
     {
       /* Select between the source and pad arrays.  */
@@ -194,6 +223,7 @@ reshape_`'rtype_ccode (rtype * const restrict ret,
       src += sstride0;
       rcount[0]++;
       scount[0]++;
+
       /* Advance to the next destination element.  */
       n = 0;
       while (rcount[n] == rextent[n])