diff options
author | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-04-20 19:56:07 +0000 |
---|---|---|
committer | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-04-20 19:56:07 +0000 |
commit | c808637ebd40215efaffc70b76d51cdda632bf57 (patch) | |
tree | a0f091b6d4e9ffd907ca682662f415fcb11b9fd8 | |
parent | 5749b7fb756700f8174502613572f4e111471025 (diff) | |
download | gcc-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
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/reshape_zerosize_1.f90 | 39 | ||||
-rw-r--r-- | libgfortran/ChangeLog | 19 | ||||
-rw-r--r-- | libgfortran/generated/reshape_c10.c | 33 | ||||
-rw-r--r-- | libgfortran/generated/reshape_c16.c | 33 | ||||
-rw-r--r-- | libgfortran/generated/reshape_c4.c | 33 | ||||
-rw-r--r-- | libgfortran/generated/reshape_c8.c | 33 | ||||
-rw-r--r-- | libgfortran/generated/reshape_i16.c | 33 | ||||
-rw-r--r-- | libgfortran/generated/reshape_i4.c | 33 | ||||
-rw-r--r-- | libgfortran/generated/reshape_i8.c | 33 | ||||
-rw-r--r-- | libgfortran/generated/reshape_r10.c | 33 | ||||
-rw-r--r-- | libgfortran/generated/reshape_r16.c | 33 | ||||
-rw-r--r-- | libgfortran/generated/reshape_r4.c | 33 | ||||
-rw-r--r-- | libgfortran/generated/reshape_r8.c | 33 | ||||
-rw-r--r-- | libgfortran/intrinsics/reshape_generic.c | 30 | ||||
-rw-r--r-- | libgfortran/m4/reshape.m4 | 33 |
16 files changed, 386 insertions, 103 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d200785acb6..d2435caaa72 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 00000000000..61896ab97b4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/reshape_zerosize_1.f90 @@ -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 diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 5c11a3d626b..922eef795d2 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -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 diff --git a/libgfortran/generated/reshape_c10.c b/libgfortran/generated/reshape_c10.c index b9eb754481a..28cad4a0b6e 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 c9cdaa931a9..ce658dae668 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 3d1eac24824..fd33a954a06 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 4a4a3e68161..d23cf88c0a3 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 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]) diff --git a/libgfortran/generated/reshape_i4.c b/libgfortran/generated/reshape_i4.c index b8114123a8a..4a55b68fed6 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 ffec9bb8d6e..d496ca9d7ef 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 8bca529b7c9..61e367c96ce 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 cd5527297f8..f04fe32c6a8 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 ace0f4e7728..0323a724624 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 8d0fd6619c5..e6be1ef03be 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]) 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]) diff --git a/libgfortran/m4/reshape.m4 b/libgfortran/m4/reshape.m4 index de936f0191a..ed060ecb9ff 100644 --- a/libgfortran/m4/reshape.m4 +++ b/libgfortran/m4/reshape.m4 @@ -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]) |