summaryrefslogtreecommitdiff
path: root/libgfortran/intrinsics/reshape_generic.c
diff options
context:
space:
mode:
authortkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2008-04-20 19:56:07 +0000
committertkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2008-04-20 19:56:07 +0000
commitc808637ebd40215efaffc70b76d51cdda632bf57 (patch)
treea0f091b6d4e9ffd907ca682662f415fcb11b9fd8 /libgfortran/intrinsics/reshape_generic.c
parent5749b7fb756700f8174502613572f4e111471025 (diff)
downloadgcc-c808637ebd40215efaffc70b76d51cdda632bf57.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@134490 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/intrinsics/reshape_generic.c')
-rw-r--r--libgfortran/intrinsics/reshape_generic.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/libgfortran/intrinsics/reshape_generic.c b/libgfortran/intrinsics/reshape_generic.c
index 333f99d2610..e28ed69feba 100644
--- a/libgfortran/intrinsics/reshape_generic.c
+++ b/libgfortran/intrinsics/reshape_generic.c
@@ -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])