summaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authortkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2005-04-22 20:02:44 +0000
committertkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2005-04-22 20:02:44 +0000
commit93c575764ec66bc9ee118261ba0f3ba68fccb519 (patch)
treecc0f19f26285884c6cba161ccbe33d495e898bb9 /libgfortran
parent0be7011340286a593c5c6bbc0c575faff8f12def (diff)
downloadgcc-93c575764ec66bc9ee118261ba0f3ba68fccb519.tar.gz
05-04-22 Thomas Koenig <Thomas.Koenig@online.de>
PR libfortran/20074 PR libfortran/20436 PR libfortran/21108 * gfortran.dg/nested_reshape.f90: new test * gfortran.dg/reshape-alloc.f90: new test * gfortran.dg/reshape.f90: new test 2005-04-22 Thomas Koenig <Thomas.Koenig@online.de> PR libfortran/20074 PR libfortran/20436 PR libfortran/21108 * m4/reshape.m4 (reshape_`'rtype_kind): rs, rex: New variables, to be used in calculation of return array sizes. Populate return array descriptor if ret->data is NULL. Fix condition for early return (it used to test something undefined if order was used). Remove duplicate check wether pad is used. * intrinsics/reshape_generic.c (reshape_generic): Likewise. Fix a few places where the wrong variables were set. * generated/reshape_i4.c: Regenerated. * generated/reshape_i8.c: Regenerated. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@98585 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog16
-rw-r--r--libgfortran/generated/reshape_i4.c32
-rw-r--r--libgfortran/generated/reshape_i8.c32
-rw-r--r--libgfortran/intrinsics/reshape_generic.c39
-rw-r--r--libgfortran/m4/reshape.m432
5 files changed, 124 insertions, 27 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index d0dc7f179e6..66ecfd08c68 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,19 @@
+2005-04-22 Thomas Koenig <Thomas.Koenig@online.de>
+
+ PR libfortran/20074
+ PR libfortran/20436
+ PR libfortran/21108
+ * m4/reshape.m4 (reshape_`'rtype_kind): rs, rex: New
+ variables, to be used in calculation of return array sizes.
+ Populate return array descriptor if ret->data is NULL.
+ Fix condition for early return (it used to test something
+ undefined if order was used).
+ Remove duplicate check wether pad is used.
+ * intrinsics/reshape_generic.c (reshape_generic): Likewise.
+ Fix a few places where the wrong variables were set.
+ * generated/reshape_i4.c: Regenerated.
+ * generated/reshape_i8.c: Regenerated.
+
2005-04-18 Paul Thomas <pault@gcc.gnu.org>
* io/list_read.c (nml_touch_nodes, nml_read_obj,
diff --git a/libgfortran/generated/reshape_i4.c b/libgfortran/generated/reshape_i4.c
index fbe16f293a5..b90e56caf4e 100644
--- a/libgfortran/generated/reshape_i4.c
+++ b/libgfortran/generated/reshape_i4.c
@@ -53,6 +53,8 @@ reshape_4 (gfc_array_i4 * ret, gfc_array_i4 * source, shape_type * shape,
index_type rstride0;
index_type rdim;
index_type rsize;
+ index_type rs;
+ index_type rex;
GFC_INTEGER_4 *rptr;
/* s.* indicates the source array. */
index_type scount[GFC_MAX_DIMENSIONS];
@@ -74,8 +76,6 @@ reshape_4 (gfc_array_i4 * ret, gfc_array_i4 * source, shape_type * shape,
int n;
int dim;
- if (ret->dim[0].stride == 0)
- ret->dim[0].stride = 1;
if (source->dim[0].stride == 0)
source->dim[0].stride = 1;
if (shape->dim[0].stride == 0)
@@ -85,7 +85,29 @@ reshape_4 (gfc_array_i4 * ret, gfc_array_i4 * source, shape_type * shape,
if (order && order->dim[0].stride == 0)
order->dim[0].stride = 1;
- rdim = GFC_DESCRIPTOR_RANK (ret);
+ 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];
+ ret->dim[n].ubound = rex - 1;
+ ret->dim[n].stride = rs;
+ rs *= rex;
+ }
+ ret->base = 0;
+ 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 (ret->dim[0].stride == 0)
+ ret->dim[0].stride = 1;
+ }
+
rsize = 1;
for (n = 0; n < rdim; n++)
{
@@ -105,7 +127,7 @@ reshape_4 (gfc_array_i4 * ret, gfc_array_i4 * source, shape_type * shape,
rsize *= rextent[n];
else
rsize = 0;
- if (rextent[dim] <= 0)
+ if (rextent[n] <= 0)
return;
}
@@ -127,8 +149,6 @@ reshape_4 (gfc_array_i4 * ret, gfc_array_i4 * source, shape_type * shape,
if (pad)
{
- if (pad->dim[0].stride == 0)
- pad->dim[0].stride = 1;
pdim = GFC_DESCRIPTOR_RANK (pad);
psize = 1;
for (n = 0; n < pdim; n++)
diff --git a/libgfortran/generated/reshape_i8.c b/libgfortran/generated/reshape_i8.c
index 6d835ff580b..38532c1aac5 100644
--- a/libgfortran/generated/reshape_i8.c
+++ b/libgfortran/generated/reshape_i8.c
@@ -53,6 +53,8 @@ reshape_8 (gfc_array_i8 * ret, gfc_array_i8 * source, shape_type * shape,
index_type rstride0;
index_type rdim;
index_type rsize;
+ index_type rs;
+ index_type rex;
GFC_INTEGER_8 *rptr;
/* s.* indicates the source array. */
index_type scount[GFC_MAX_DIMENSIONS];
@@ -74,8 +76,6 @@ reshape_8 (gfc_array_i8 * ret, gfc_array_i8 * source, shape_type * shape,
int n;
int dim;
- if (ret->dim[0].stride == 0)
- ret->dim[0].stride = 1;
if (source->dim[0].stride == 0)
source->dim[0].stride = 1;
if (shape->dim[0].stride == 0)
@@ -85,7 +85,29 @@ reshape_8 (gfc_array_i8 * ret, gfc_array_i8 * source, shape_type * shape,
if (order && order->dim[0].stride == 0)
order->dim[0].stride = 1;
- rdim = GFC_DESCRIPTOR_RANK (ret);
+ 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];
+ ret->dim[n].ubound = rex - 1;
+ ret->dim[n].stride = rs;
+ rs *= rex;
+ }
+ ret->base = 0;
+ 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 (ret->dim[0].stride == 0)
+ ret->dim[0].stride = 1;
+ }
+
rsize = 1;
for (n = 0; n < rdim; n++)
{
@@ -105,7 +127,7 @@ reshape_8 (gfc_array_i8 * ret, gfc_array_i8 * source, shape_type * shape,
rsize *= rextent[n];
else
rsize = 0;
- if (rextent[dim] <= 0)
+ if (rextent[n] <= 0)
return;
}
@@ -127,8 +149,6 @@ reshape_8 (gfc_array_i8 * ret, gfc_array_i8 * source, shape_type * shape,
if (pad)
{
- if (pad->dim[0].stride == 0)
- pad->dim[0].stride = 1;
pdim = GFC_DESCRIPTOR_RANK (pad);
psize = 1;
for (n = 0; n < pdim; n++)
diff --git a/libgfortran/intrinsics/reshape_generic.c b/libgfortran/intrinsics/reshape_generic.c
index c0339cad633..75db5eafd24 100644
--- a/libgfortran/intrinsics/reshape_generic.c
+++ b/libgfortran/intrinsics/reshape_generic.c
@@ -54,6 +54,8 @@ reshape (parray *ret, parray *source, shape_type *shape,
index_type rstride0;
index_type rdim;
index_type rsize;
+ index_type rs;
+ index_type rex;
char *rptr;
/* s.* indicates the source array. */
index_type scount[GFC_MAX_DIMENSIONS];
@@ -76,9 +78,6 @@ reshape (parray *ret, parray *source, shape_type *shape,
int dim;
int size;
- size = GFC_DESCRIPTOR_SIZE (ret);
- if (ret->dim[0].stride == 0)
- ret->dim[0].stride = 1;
if (source->dim[0].stride == 0)
source->dim[0].stride = 1;
if (shape->dim[0].stride == 0)
@@ -88,7 +87,31 @@ reshape (parray *ret, parray *source, shape_type *shape,
if (order && order->dim[0].stride == 0)
order->dim[0].stride = 1;
- rdim = GFC_DESCRIPTOR_RANK (ret);
+ if (ret->data == NULL)
+ {
+ size = GFC_DESCRIPTOR_SIZE (ret);
+ 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];
+ ret->dim[n].ubound = rex - 1;
+ ret->dim[n].stride = rs;
+ rs *= rex;
+ }
+ ret->base = 0;
+ ret->data = internal_malloc_size ( rs * size );
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+ else
+ {
+ size = GFC_DESCRIPTOR_SIZE (ret);
+ rdim = GFC_DESCRIPTOR_RANK (ret);
+ if (ret->dim[0].stride == 0)
+ ret->dim[0].stride = 1;
+ }
+
rsize = 1;
for (n = 0; n < rdim; n++)
{
@@ -108,7 +131,7 @@ reshape (parray *ret, parray *source, shape_type *shape,
rsize *= rextent[n];
else
rsize = 0;
- if (rextent[dim] <= 0)
+ if (rextent[n] <= 0)
return;
}
@@ -122,7 +145,7 @@ reshape (parray *ret, parray *source, shape_type *shape,
if (sextent[n] <= 0)
abort ();
- if (rsize == sstride[n])
+ if (ssize == sstride[n])
ssize *= sextent[n];
else
ssize = 0;
@@ -130,8 +153,6 @@ reshape (parray *ret, parray *source, shape_type *shape,
if (pad)
{
- if (pad->dim[0].stride == 0)
- pad->dim[0].stride = 1;
pdim = GFC_DESCRIPTOR_RANK (pad);
psize = 1;
for (n = 0; n < pdim; n++)
@@ -144,7 +165,7 @@ reshape (parray *ret, parray *source, shape_type *shape,
if (psize == pstride[n])
psize *= pextent[n];
else
- rsize = 0;
+ psize = 0;
}
pptr = pad->data;
}
diff --git a/libgfortran/m4/reshape.m4 b/libgfortran/m4/reshape.m4
index 22e2536ecb7..541377f01c5 100644
--- a/libgfortran/m4/reshape.m4
+++ b/libgfortran/m4/reshape.m4
@@ -55,6 +55,8 @@ reshape_`'rtype_kind (rtype * ret, rtype * source, shape_type * shape,
index_type rstride0;
index_type rdim;
index_type rsize;
+ index_type rs;
+ index_type rex;
rtype_name *rptr;
/* s.* indicates the source array. */
index_type scount[GFC_MAX_DIMENSIONS];
@@ -76,8 +78,6 @@ reshape_`'rtype_kind (rtype * ret, rtype * source, shape_type * shape,
int n;
int dim;
- if (ret->dim[0].stride == 0)
- ret->dim[0].stride = 1;
if (source->dim[0].stride == 0)
source->dim[0].stride = 1;
if (shape->dim[0].stride == 0)
@@ -87,7 +87,29 @@ reshape_`'rtype_kind (rtype * ret, rtype * source, shape_type * shape,
if (order && order->dim[0].stride == 0)
order->dim[0].stride = 1;
- rdim = GFC_DESCRIPTOR_RANK (ret);
+ 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];
+ ret->dim[n].ubound = rex - 1;
+ ret->dim[n].stride = rs;
+ rs *= rex;
+ }
+ ret->base = 0;
+ 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 (ret->dim[0].stride == 0)
+ ret->dim[0].stride = 1;
+ }
+
rsize = 1;
for (n = 0; n < rdim; n++)
{
@@ -107,7 +129,7 @@ reshape_`'rtype_kind (rtype * ret, rtype * source, shape_type * shape,
rsize *= rextent[n];
else
rsize = 0;
- if (rextent[dim] <= 0)
+ if (rextent[n] <= 0)
return;
}
@@ -129,8 +151,6 @@ reshape_`'rtype_kind (rtype * ret, rtype * source, shape_type * shape,
if (pad)
{
- if (pad->dim[0].stride == 0)
- pad->dim[0].stride = 1;
pdim = GFC_DESCRIPTOR_RANK (pad);
psize = 1;
for (n = 0; n < pdim; n++)