aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/generated
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2008-04-20 19:56:07 +0000
committerThomas Koenig <tkoenig@gcc.gnu.org>2008-04-20 19:56:07 +0000
commit8c154b65579602aad087eff7229a460412b9ed8c (patch)
treea0f091b6d4e9ffd907ca682662f415fcb11b9fd8 /libgfortran/generated
parenteea05d39c799880df753e9b74d2d96e86215c46e (diff)
downloadgcc-8c154b65579602aad087eff7229a460412b9ed8c.zip
gcc-8c154b65579602aad087eff7229a460412b9ed8c.tar.gz
gcc-8c154b65579602aad087eff7229a460412b9ed8c.tar.bz2
re PR fortran/35960 (run time abort with assignment of RESHAPEd zero sized array)
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
Diffstat (limited to 'libgfortran/generated')
-rw-r--r--libgfortran/generated/reshape_c10.c33
-rw-r--r--libgfortran/generated/reshape_c16.c33
-rw-r--r--libgfortran/generated/reshape_c4.c33
-rw-r--r--libgfortran/generated/reshape_c8.c33
-rw-r--r--libgfortran/generated/reshape_i16.c33
-rw-r--r--libgfortran/generated/reshape_i4.c33
-rw-r--r--libgfortran/generated/reshape_i8.c33
-rw-r--r--libgfortran/generated/reshape_r10.c33
-rw-r--r--libgfortran/generated/reshape_r16.c33
-rw-r--r--libgfortran/generated/reshape_r4.c33
-rw-r--r--libgfortran/generated/reshape_r8.c33
11 files changed, 275 insertions, 88 deletions
diff --git a/libgfortran/generated/reshape_c10.c b/libgfortran/generated/reshape_c10.c
index b9eb754..28cad4a 100644
--- a/libgfortran/generated/reshape_c10.c
+++ b/libgfortran/generated/reshape_c10.c
@@ -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])
diff --git a/libgfortran/generated/reshape_c16.c b/libgfortran/generated/reshape_c16.c
index c9cdaa9..ce658da 100644
--- a/libgfortran/generated/reshape_c16.c
+++ b/libgfortran/generated/reshape_c16.c
@@ -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])
diff --git a/libgfortran/generated/reshape_c4.c b/libgfortran/generated/reshape_c4.c
index 3d1eac2..fd33a95 100644
--- a/libgfortran/generated/reshape_c4.c
+++ b/libgfortran/generated/reshape_c4.c
@@ -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])
diff --git a/libgfortran/generated/reshape_c8.c b/libgfortran/generated/reshape_c8.c
index 4a4a3e6..d23cf88 100644
--- a/libgfortran/generated/reshape_c8.c
+++ b/libgfortran/generated/reshape_c8.c
@@ -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])
diff --git a/libgfortran/generated/reshape_i16.c b/libgfortran/generated/reshape_i16.c
index 9e58dcc..c9b3694 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])
diff --git a/libgfortran/generated/reshape_i4.c b/libgfortran/generated/reshape_i4.c
index b811412..4a55b68 100644
--- a/libgfortran/generated/reshape_i4.c
+++ b/libgfortran/generated/reshape_i4.c
@@ -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])
diff --git a/libgfortran/generated/reshape_i8.c b/libgfortran/generated/reshape_i8.c
index ffec9bb..d496ca9 100644
--- a/libgfortran/generated/reshape_i8.c
+++ b/libgfortran/generated/reshape_i8.c
@@ -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])
diff --git a/libgfortran/generated/reshape_r10.c b/libgfortran/generated/reshape_r10.c
index 8bca529..61e367c 100644
--- a/libgfortran/generated/reshape_r10.c
+++ b/libgfortran/generated/reshape_r10.c
@@ -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])
diff --git a/libgfortran/generated/reshape_r16.c b/libgfortran/generated/reshape_r16.c
index cd55272..f04fe32 100644
--- a/libgfortran/generated/reshape_r16.c
+++ b/libgfortran/generated/reshape_r16.c
@@ -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])
diff --git a/libgfortran/generated/reshape_r4.c b/libgfortran/generated/reshape_r4.c
index ace0f4e..0323a72 100644
--- a/libgfortran/generated/reshape_r4.c
+++ b/libgfortran/generated/reshape_r4.c
@@ -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])
diff --git a/libgfortran/generated/reshape_r8.c b/libgfortran/generated/reshape_r8.c
index 8d0fd66..e6be1ef 100644
--- a/libgfortran/generated/reshape_r8.c
+++ b/libgfortran/generated/reshape_r8.c
@@ -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])