From 0e6d033bc892f6f79683dcbbda0e6a1987685bf4 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Sat, 25 Jun 2005 09:56:37 +0000 Subject: [PATCH] [multiple changes] 2005-06-25 Thomas Koenig PR libfortran/22144 * m4/cshift1.m4: Remove const from argument ret. Populate return array descriptor if ret->data is NULL. * m4/eoshift1.m4: Likewise. * m4/eoshift3.m4: Likewise. * generated/cshift1_4.c: Regenerated. * generated/cshift1_8.c: Regenerated. * generated/eoshift1_4.c: Regenerated. * generated/eoshift1_8.c: Regenerated. * generated/eoshift3_4.c: Regenerated. * generated/eoshift3_8.c: Regenerated. 2005-06-25 Thomas Koenig PR libfortran/21144 * gfortran.dg/shift-alloc.f90: New testcase. From-SVN: r101318 --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/shift-alloc.f90 | 18 +++++++++++++++++ libgfortran/ChangeLog | 14 +++++++++++++ libgfortran/generated/cshift1_4.c | 23 ++++++++++++++++++++-- libgfortran/generated/cshift1_8.c | 23 ++++++++++++++++++++-- libgfortran/generated/eoshift1_4.c | 24 +++++++++++++++++++++-- libgfortran/generated/eoshift1_8.c | 24 +++++++++++++++++++++-- libgfortran/generated/eoshift3_4.c | 19 ++++++++++++++++++ libgfortran/generated/eoshift3_8.c | 19 ++++++++++++++++++ libgfortran/m4/cshift1.m4 | 23 ++++++++++++++++++++-- libgfortran/m4/eoshift1.m4 | 24 +++++++++++++++++++++-- libgfortran/m4/eoshift3.m4 | 19 ++++++++++++++++++ 12 files changed, 223 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/shift-alloc.f90 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 70b830b087a..419e012bd44 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-06-25 Thomas Koenig + + PR libfortran/21144 + * gfortran.dg/shift-alloc.f90: New testcase. + 2005-06-25 Kelley Cook * all files: Update FSF address in copyright headers. diff --git a/gcc/testsuite/gfortran.dg/shift-alloc.f90 b/gcc/testsuite/gfortran.dg/shift-alloc.f90 new file mode 100644 index 00000000000..2d660317235 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/shift-alloc.f90 @@ -0,0 +1,18 @@ +! { dg do-run } +! PR 22144: eoshift1, eoshift3 and cshift1 used to lack memory +! allocation, which caused the writes to segfault. +program main + implicit none + integer, dimension (:,:),allocatable :: a + integer, dimension (3) :: sh, bo + character(len=80) line1, line2 + integer :: i + + allocate (a(3,3)) + a = reshape((/(i,i=1,9)/),shape(a)) + sh = (/ 2, -1, -2 /) + bo = (/ -3, -2, -1 /) + write(unit=line1,fmt='(10I5)') cshift(a, shift=sh) + write(unit=line1,fmt='(10I5)') eoshift(a, shift=sh) + write(unit=line1,fmt='(10I5)') eoshift(a, shift=sh, boundary=bo) +end program main diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 06c3e4b3669..9b2ddec62d2 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,17 @@ +2005-06-25 Thomas Koenig + + PR libfortran/22144 + * m4/cshift1.m4: Remove const from argument ret. + Populate return array descriptor if ret->data is NULL. + * m4/eoshift1.m4: Likewise. + * m4/eoshift3.m4: Likewise. + * generated/cshift1_4.c: Regenerated. + * generated/cshift1_8.c: Regenerated. + * generated/eoshift1_4.c: Regenerated. + * generated/eoshift1_8.c: Regenerated. + * generated/eoshift3_4.c: Regenerated. + * generated/eoshift3_8.c: Regenerated. + 2005-06-24 Jerry DeLisle PR libfortran/21915 diff --git a/libgfortran/generated/cshift1_4.c b/libgfortran/generated/cshift1_4.c index 683ce703ff2..b86f9e51c7e 100644 --- a/libgfortran/generated/cshift1_4.c +++ b/libgfortran/generated/cshift1_4.c @@ -34,13 +34,13 @@ Boston, MA 02111-1307, USA. */ #include #include "libgfortran.h" -void cshift1_4 (const gfc_array_char * ret, +void cshift1_4 (gfc_array_char * ret, const gfc_array_char * array, const gfc_array_i4 * h, const GFC_INTEGER_4 * pwhich); export_proto(cshift1_4); void -cshift1_4 (const gfc_array_char * ret, +cshift1_4 (gfc_array_char * ret, const gfc_array_char * array, const gfc_array_i4 * h, const GFC_INTEGER_4 * pwhich) { @@ -80,6 +80,25 @@ cshift1_4 (const gfc_array_char * ret, size = GFC_DESCRIPTOR_SIZE (ret); + if (ret->data == NULL) + { + int i; + + ret->data = internal_malloc_size (size * size0 ((array_t *)array)); + ret->base = 0; + ret->dtype = array->dtype; + for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) + { + ret->dim[i].lbound = 0; + ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound; + + if (i == 0) + ret->dim[i].stride = 1; + else + ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride; + } + } + extent[0] = 1; count[0] = 0; size = GFC_DESCRIPTOR_SIZE (array); diff --git a/libgfortran/generated/cshift1_8.c b/libgfortran/generated/cshift1_8.c index 6513b910304..24c1b6e89e3 100644 --- a/libgfortran/generated/cshift1_8.c +++ b/libgfortran/generated/cshift1_8.c @@ -34,13 +34,13 @@ Boston, MA 02111-1307, USA. */ #include #include "libgfortran.h" -void cshift1_8 (const gfc_array_char * ret, +void cshift1_8 (gfc_array_char * ret, const gfc_array_char * array, const gfc_array_i8 * h, const GFC_INTEGER_8 * pwhich); export_proto(cshift1_8); void -cshift1_8 (const gfc_array_char * ret, +cshift1_8 (gfc_array_char * ret, const gfc_array_char * array, const gfc_array_i8 * h, const GFC_INTEGER_8 * pwhich) { @@ -80,6 +80,25 @@ cshift1_8 (const gfc_array_char * ret, size = GFC_DESCRIPTOR_SIZE (ret); + if (ret->data == NULL) + { + int i; + + ret->data = internal_malloc_size (size * size0 ((array_t *)array)); + ret->base = 0; + ret->dtype = array->dtype; + for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) + { + ret->dim[i].lbound = 0; + ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound; + + if (i == 0) + ret->dim[i].stride = 1; + else + ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride; + } + } + extent[0] = 1; count[0] = 0; size = GFC_DESCRIPTOR_SIZE (array); diff --git a/libgfortran/generated/eoshift1_4.c b/libgfortran/generated/eoshift1_4.c index 3503f825c6a..833efa2ae00 100644 --- a/libgfortran/generated/eoshift1_4.c +++ b/libgfortran/generated/eoshift1_4.c @@ -37,14 +37,14 @@ Boston, MA 02111-1307, USA. */ static const char zeros[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -extern void eoshift1_4 (const gfc_array_char *, +extern void eoshift1_4 (gfc_array_char *, const gfc_array_char *, const gfc_array_i4 *, const char *, const GFC_INTEGER_4 *); export_proto(eoshift1_4); void -eoshift1_4 (const gfc_array_char *ret, +eoshift1_4 (gfc_array_char *ret, const gfc_array_char *array, const gfc_array_i4 *h, const char *pbound, const GFC_INTEGER_4 *pwhich) @@ -95,6 +95,26 @@ eoshift1_4 (const gfc_array_char *ret, extent[0] = 1; count[0] = 0; size = GFC_DESCRIPTOR_SIZE (array); + + if (ret->data == NULL) + { + int i; + + ret->data = internal_malloc_size (size * size0 ((array_t *)array)); + ret->base = 0; + ret->dtype = array->dtype; + for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) + { + ret->dim[i].lbound = 0; + ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound; + + if (i == 0) + ret->dim[i].stride = 1; + else + ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride; + } + } + n = 0; for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++) { diff --git a/libgfortran/generated/eoshift1_8.c b/libgfortran/generated/eoshift1_8.c index bfa608814ff..75d0f1e1e3d 100644 --- a/libgfortran/generated/eoshift1_8.c +++ b/libgfortran/generated/eoshift1_8.c @@ -37,14 +37,14 @@ Boston, MA 02111-1307, USA. */ static const char zeros[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -extern void eoshift1_8 (const gfc_array_char *, +extern void eoshift1_8 (gfc_array_char *, const gfc_array_char *, const gfc_array_i8 *, const char *, const GFC_INTEGER_8 *); export_proto(eoshift1_8); void -eoshift1_8 (const gfc_array_char *ret, +eoshift1_8 (gfc_array_char *ret, const gfc_array_char *array, const gfc_array_i8 *h, const char *pbound, const GFC_INTEGER_8 *pwhich) @@ -95,6 +95,26 @@ eoshift1_8 (const gfc_array_char *ret, extent[0] = 1; count[0] = 0; size = GFC_DESCRIPTOR_SIZE (array); + + if (ret->data == NULL) + { + int i; + + ret->data = internal_malloc_size (size * size0 ((array_t *)array)); + ret->base = 0; + ret->dtype = array->dtype; + for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) + { + ret->dim[i].lbound = 0; + ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound; + + if (i == 0) + ret->dim[i].stride = 1; + else + ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride; + } + } + n = 0; for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++) { diff --git a/libgfortran/generated/eoshift3_4.c b/libgfortran/generated/eoshift3_4.c index 964d98b55ed..14c38b7bd6a 100644 --- a/libgfortran/generated/eoshift3_4.c +++ b/libgfortran/generated/eoshift3_4.c @@ -90,6 +90,25 @@ eoshift3_4 (gfc_array_char *ret, gfc_array_char *array, which = 0; size = GFC_DESCRIPTOR_SIZE (ret); + if (ret->data == NULL) + { + int i; + + ret->data = internal_malloc_size (size * size0 ((array_t *)array)); + ret->base = 0; + ret->dtype = array->dtype; + for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) + { + ret->dim[i].lbound = 0; + ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound; + + if (i == 0) + ret->dim[i].stride = 1; + else + ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride; + } + } + extent[0] = 1; count[0] = 0; diff --git a/libgfortran/generated/eoshift3_8.c b/libgfortran/generated/eoshift3_8.c index c17b5885e28..77617b07417 100644 --- a/libgfortran/generated/eoshift3_8.c +++ b/libgfortran/generated/eoshift3_8.c @@ -90,6 +90,25 @@ eoshift3_8 (gfc_array_char *ret, gfc_array_char *array, which = 0; size = GFC_DESCRIPTOR_SIZE (ret); + if (ret->data == NULL) + { + int i; + + ret->data = internal_malloc_size (size * size0 ((array_t *)array)); + ret->base = 0; + ret->dtype = array->dtype; + for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) + { + ret->dim[i].lbound = 0; + ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound; + + if (i == 0) + ret->dim[i].stride = 1; + else + ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride; + } + } + extent[0] = 1; count[0] = 0; diff --git a/libgfortran/m4/cshift1.m4 b/libgfortran/m4/cshift1.m4 index 308c3dc40f8..dd7653ab517 100644 --- a/libgfortran/m4/cshift1.m4 +++ b/libgfortran/m4/cshift1.m4 @@ -35,13 +35,13 @@ Boston, MA 02111-1307, USA. */ #include "libgfortran.h"' include(iparm.m4)dnl -void cshift1_`'atype_kind (const gfc_array_char * ret, +void cshift1_`'atype_kind (gfc_array_char * ret, const gfc_array_char * array, const atype * h, const atype_name * pwhich); export_proto(cshift1_`'atype_kind); void -cshift1_`'atype_kind (const gfc_array_char * ret, +cshift1_`'atype_kind (gfc_array_char * ret, const gfc_array_char * array, const atype * h, const atype_name * pwhich) { @@ -81,6 +81,25 @@ cshift1_`'atype_kind (const gfc_array_char * ret, size = GFC_DESCRIPTOR_SIZE (ret); + if (ret->data == NULL) + { + int i; + + ret->data = internal_malloc_size (size * size0 ((array_t *)array)); + ret->base = 0; + ret->dtype = array->dtype; + for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) + { + ret->dim[i].lbound = 0; + ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound; + + if (i == 0) + ret->dim[i].stride = 1; + else + ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride; + } + } + extent[0] = 1; count[0] = 0; size = GFC_DESCRIPTOR_SIZE (array); diff --git a/libgfortran/m4/eoshift1.m4 b/libgfortran/m4/eoshift1.m4 index b21c6d34732..1d13f482081 100644 --- a/libgfortran/m4/eoshift1.m4 +++ b/libgfortran/m4/eoshift1.m4 @@ -38,14 +38,14 @@ include(iparm.m4)dnl static const char zeros[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -extern void eoshift1_`'atype_kind (const gfc_array_char *, +extern void eoshift1_`'atype_kind (gfc_array_char *, const gfc_array_char *, const atype *, const char *, const atype_name *); export_proto(eoshift1_`'atype_kind); void -eoshift1_`'atype_kind (const gfc_array_char *ret, +eoshift1_`'atype_kind (gfc_array_char *ret, const gfc_array_char *array, const atype *h, const char *pbound, const atype_name *pwhich) @@ -96,6 +96,26 @@ eoshift1_`'atype_kind (const gfc_array_char *ret, extent[0] = 1; count[0] = 0; size = GFC_DESCRIPTOR_SIZE (array); + + if (ret->data == NULL) + { + int i; + + ret->data = internal_malloc_size (size * size0 ((array_t *)array)); + ret->base = 0; + ret->dtype = array->dtype; + for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) + { + ret->dim[i].lbound = 0; + ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound; + + if (i == 0) + ret->dim[i].stride = 1; + else + ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride; + } + } + n = 0; for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++) { diff --git a/libgfortran/m4/eoshift3.m4 b/libgfortran/m4/eoshift3.m4 index 6cbb87cfb84..5001756df0c 100644 --- a/libgfortran/m4/eoshift3.m4 +++ b/libgfortran/m4/eoshift3.m4 @@ -91,6 +91,25 @@ eoshift3_`'atype_kind (gfc_array_char *ret, gfc_array_char *array, which = 0; size = GFC_DESCRIPTOR_SIZE (ret); + if (ret->data == NULL) + { + int i; + + ret->data = internal_malloc_size (size * size0 ((array_t *)array)); + ret->base = 0; + ret->dtype = array->dtype; + for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) + { + ret->dim[i].lbound = 0; + ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound; + + if (i == 0) + ret->dim[i].stride = 1; + else + ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride; + } + } + extent[0] = 1; count[0] = 0; -- 2.30.2