summaryrefslogtreecommitdiff
path: root/libgfortran/generated/reshape_i16.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgfortran/generated/reshape_i16.c')
-rw-r--r--libgfortran/generated/reshape_i16.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/libgfortran/generated/reshape_i16.c b/libgfortran/generated/reshape_i16.c
index 9e58dcc3d5a..c9b3694c5de 100644
--- a/libgfortran/generated/reshape_i16.c
+++ b/libgfortran/generated/reshape_i16.c
@@ -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])