diff options
author | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-12-30 13:16:36 +0000 |
---|---|---|
committer | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-12-30 13:16:36 +0000 |
commit | a14c06e97aeeb4b6c164edf6d00fab4e82642d84 (patch) | |
tree | c4d838dbc27d49cca645bfaba8a83f2b0ebddd53 | |
parent | 6ec458b2d6b10716933c312cbcf36effc0d15603 (diff) | |
download | gcc-a14c06e97aeeb4b6c164edf6d00fab4e82642d84.tar.gz |
2006-12-30 Thomas Koenig <Thomas.Koenig@online.de>
PR libfortran/30321
* m4/ifunction.m4 (name`'rtype_qual`_'atype_code):
Check for extents < 0 for zero-sized arrays. If
no retarray has been specified and the size is zero,
return early.
(`m'name`'rtype_qual`_'atype_code): Likewise.
* generated/all_l16.c: Regenerated.
* generated/all_l4.c: Regenerated.
* generated/all_l8.c: Regenerated.
* generated/any_l16.c: Regenerated.
* generated/any_l4.c: Regenerated.
* generated/any_l8.c: Regenerated.
* generated/count_16_l16.c: Regenerated.
* generated/count_16_l4.c: Regenerated.
* generated/count_16_l8.c: Regenerated.
* generated/count_4_l16.c: Regenerated.
* generated/count_4_l4.c: Regenerated.
* generated/count_4_l8.c: Regenerated.
* generated/count_8_l16.c: Regenerated.
* generated/count_8_l4.c: Regenerated.
* generated/count_8_l8.c: Regenerated.
* generated/cshift1_16.c: Regenerated.
* generated/cshift1_4.c: Regenerated.
* generated/cshift1_8.c: Regenerated.
* generated/maxloc1_16_i16.c: Regenerated.
* generated/maxloc1_16_i4.c: Regenerated.
* generated/maxloc1_16_i8.c: Regenerated.
* generated/maxloc1_16_r10.c: Regenerated.
* generated/maxloc1_16_r16.c: Regenerated.
* generated/maxloc1_16_r4.c: Regenerated.
* generated/maxloc1_16_r8.c: Regenerated.
* generated/maxloc1_4_i16.c: Regenerated.
* generated/maxloc1_4_i4.c: Regenerated.
* generated/maxloc1_4_i8.c: Regenerated.
* generated/maxloc1_4_r10.c: Regenerated.
* generated/maxloc1_4_r16.c: Regenerated.
* generated/maxloc1_4_r4.c: Regenerated.
* generated/maxloc1_4_r8.c: Regenerated.
* generated/maxloc1_8_i16.c: Regenerated.
* generated/maxloc1_8_i4.c: Regenerated.
* generated/maxloc1_8_i8.c: Regenerated.
* generated/maxloc1_8_r10.c: Regenerated.
* generated/maxloc1_8_r16.c: Regenerated.
* generated/maxloc1_8_r4.c: Regenerated.
* generated/maxloc1_8_r8.c: Regenerated.
* generated/maxval_i16.c: Regenerated.
* generated/maxval_i4.c: Regenerated.
* generated/maxval_i8.c: Regenerated.
* generated/maxval_r10.c: Regenerated.
* generated/maxval_r16.c: Regenerated.
* generated/maxval_r4.c: Regenerated.
* generated/maxval_r8.c: Regenerated.
* generated/minloc1_16_i16.c: Regenerated.
* generated/minloc1_16_i4.c: Regenerated.
* generated/minloc1_16_i8.c: Regenerated.
* generated/minloc1_16_r10.c: Regenerated.
* generated/minloc1_16_r16.c: Regenerated.
* generated/minloc1_16_r4.c: Regenerated.
* generated/minloc1_16_r8.c: Regenerated.
* generated/minloc1_4_i16.c: Regenerated.
* generated/minloc1_4_i4.c: Regenerated.
* generated/minloc1_4_i8.c: Regenerated.
* generated/minloc1_4_r10.c: Regenerated.
* generated/minloc1_4_r16.c: Regenerated.
* generated/minloc1_4_r4.c: Regenerated.
* generated/minloc1_4_r8.c: Regenerated.
* generated/minloc1_8_i16.c: Regenerated.
* generated/minloc1_8_i4.c: Regenerated.
* generated/minloc1_8_i8.c: Regenerated.
* generated/minloc1_8_r10.c: Regenerated.
* generated/minloc1_8_r16.c: Regenerated.
* generated/minloc1_8_r4.c: Regenerated.
* generated/minloc1_8_r8.c: Regenerated.
* generated/minval_i16.c: Regenerated.
* generated/minval_i4.c: Regenerated.
* generated/minval_i8.c: Regenerated.
* generated/minval_r10.c: Regenerated.
* generated/minval_r16.c: Regenerated.
* generated/minval_r4.c: Regenerated.
* generated/minval_r8.c: Regenerated.
* generated/product_c10.c: Regenerated.
* generated/product_c16.c: Regenerated.
* generated/product_c4.c: Regenerated.
* generated/product_c8.c: Regenerated.
* generated/product_i16.c: Regenerated.
* generated/product_i4.c: Regenerated.
* generated/product_i8.c: Regenerated.
* generated/product_r10.c: Regenerated.
* generated/product_r16.c: Regenerated.
* generated/product_r4.c: Regenerated.
* generated/product_r8.c: Regenerated.
* generated/sum_c10.c: Regenerated.
* generated/sum_c16.c: Regenerated.
* generated/sum_c4.c: Regenerated.
* generated/sum_c8.c: Regenerated.
* generated/sum_i16.c: Regenerated.
* generated/sum_i4.c: Regenerated.
* generated/sum_i8.c: Regenerated.
* generated/sum_r10.c: Regenerated.
* generated/sum_r16.c: Regenerated.
* generated/sum_r4.c: Regenerated.
* generated/sum_r8.c: Regenerated.
2006-12-30 Thomas Koenig <Thomas.Koenig@online.de>
PR libfortran/30321
* gfortran.dg/sum_zero_array_1.f90: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@120287 138bc75d-0d04-0410-961f-82ee72b054a4
100 files changed, 3920 insertions, 698 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8c072e2c6c4..4874ec7a39c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-12-30 Thomas Koenig <Thomas.Koenig@online.de> + + PR libfortran/30321 + * gfortran.dg/sum_zero_array_1.f90: New test. + 2006-12-29 Jakub Jelinek <jakub@redhat.com> PR preprocessor/29612 diff --git a/gcc/testsuite/gfortran.dg/sum_zero_array_1.f90 b/gcc/testsuite/gfortran.dg/sum_zero_array_1.f90 new file mode 100644 index 00000000000..b864bbf71a0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/sum_zero_array_1.f90 @@ -0,0 +1,13 @@ +! { dg-do run } +! PR 30321: This used to segfault. +program xzero + implicit none + integer :: ii(1,0) + logical :: ll(1,0) + character (len=80) line + ll = .true. + write (unit=line, fmt="(I6)") sum(ii,dim=1) + if (line /= " ") call abort + write (unit=line, fmt="(I6)") sum(ii,dim=1,mask=ll) + if (line /= " ") call abort +end program xzero diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 568049c6d22..2096806c6bd 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,108 @@ +2006-12-30 Thomas Koenig <Thomas.Koenig@online.de> + + PR libfortran/30321 + * m4/ifunction.m4 (name`'rtype_qual`_'atype_code): + Check for extents < 0 for zero-sized arrays. If + no retarray has been specified and the size is zero, + return early. + (`m'name`'rtype_qual`_'atype_code): Likewise. + * generated/all_l16.c: Regenerated. + * generated/all_l4.c: Regenerated. + * generated/all_l8.c: Regenerated. + * generated/any_l16.c: Regenerated. + * generated/any_l4.c: Regenerated. + * generated/any_l8.c: Regenerated. + * generated/count_16_l16.c: Regenerated. + * generated/count_16_l4.c: Regenerated. + * generated/count_16_l8.c: Regenerated. + * generated/count_4_l16.c: Regenerated. + * generated/count_4_l4.c: Regenerated. + * generated/count_4_l8.c: Regenerated. + * generated/count_8_l16.c: Regenerated. + * generated/count_8_l4.c: Regenerated. + * generated/count_8_l8.c: Regenerated. + * generated/cshift1_16.c: Regenerated. + * generated/cshift1_4.c: Regenerated. + * generated/cshift1_8.c: Regenerated. + * generated/maxloc1_16_i16.c: Regenerated. + * generated/maxloc1_16_i4.c: Regenerated. + * generated/maxloc1_16_i8.c: Regenerated. + * generated/maxloc1_16_r10.c: Regenerated. + * generated/maxloc1_16_r16.c: Regenerated. + * generated/maxloc1_16_r4.c: Regenerated. + * generated/maxloc1_16_r8.c: Regenerated. + * generated/maxloc1_4_i16.c: Regenerated. + * generated/maxloc1_4_i4.c: Regenerated. + * generated/maxloc1_4_i8.c: Regenerated. + * generated/maxloc1_4_r10.c: Regenerated. + * generated/maxloc1_4_r16.c: Regenerated. + * generated/maxloc1_4_r4.c: Regenerated. + * generated/maxloc1_4_r8.c: Regenerated. + * generated/maxloc1_8_i16.c: Regenerated. + * generated/maxloc1_8_i4.c: Regenerated. + * generated/maxloc1_8_i8.c: Regenerated. + * generated/maxloc1_8_r10.c: Regenerated. + * generated/maxloc1_8_r16.c: Regenerated. + * generated/maxloc1_8_r4.c: Regenerated. + * generated/maxloc1_8_r8.c: Regenerated. + * generated/maxval_i16.c: Regenerated. + * generated/maxval_i4.c: Regenerated. + * generated/maxval_i8.c: Regenerated. + * generated/maxval_r10.c: Regenerated. + * generated/maxval_r16.c: Regenerated. + * generated/maxval_r4.c: Regenerated. + * generated/maxval_r8.c: Regenerated. + * generated/minloc1_16_i16.c: Regenerated. + * generated/minloc1_16_i4.c: Regenerated. + * generated/minloc1_16_i8.c: Regenerated. + * generated/minloc1_16_r10.c: Regenerated. + * generated/minloc1_16_r16.c: Regenerated. + * generated/minloc1_16_r4.c: Regenerated. + * generated/minloc1_16_r8.c: Regenerated. + * generated/minloc1_4_i16.c: Regenerated. + * generated/minloc1_4_i4.c: Regenerated. + * generated/minloc1_4_i8.c: Regenerated. + * generated/minloc1_4_r10.c: Regenerated. + * generated/minloc1_4_r16.c: Regenerated. + * generated/minloc1_4_r4.c: Regenerated. + * generated/minloc1_4_r8.c: Regenerated. + * generated/minloc1_8_i16.c: Regenerated. + * generated/minloc1_8_i4.c: Regenerated. + * generated/minloc1_8_i8.c: Regenerated. + * generated/minloc1_8_r10.c: Regenerated. + * generated/minloc1_8_r16.c: Regenerated. + * generated/minloc1_8_r4.c: Regenerated. + * generated/minloc1_8_r8.c: Regenerated. + * generated/minval_i16.c: Regenerated. + * generated/minval_i4.c: Regenerated. + * generated/minval_i8.c: Regenerated. + * generated/minval_r10.c: Regenerated. + * generated/minval_r16.c: Regenerated. + * generated/minval_r4.c: Regenerated. + * generated/minval_r8.c: Regenerated. + * generated/product_c10.c: Regenerated. + * generated/product_c16.c: Regenerated. + * generated/product_c4.c: Regenerated. + * generated/product_c8.c: Regenerated. + * generated/product_i16.c: Regenerated. + * generated/product_i4.c: Regenerated. + * generated/product_i8.c: Regenerated. + * generated/product_r10.c: Regenerated. + * generated/product_r16.c: Regenerated. + * generated/product_r4.c: Regenerated. + * generated/product_r8.c: Regenerated. + * generated/sum_c10.c: Regenerated. + * generated/sum_c16.c: Regenerated. + * generated/sum_c4.c: Regenerated. + * generated/sum_c8.c: Regenerated. + * generated/sum_i16.c: Regenerated. + * generated/sum_i4.c: Regenerated. + * generated/sum_i8.c: Regenerated. + * generated/sum_r10.c: Regenerated. + * generated/sum_r16.c: Regenerated. + * generated/sum_r4.c: Regenerated. + * generated/sum_r8.c: Regenerated. + 2006-12-27 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libgfortran/30014 diff --git a/libgfortran/generated/all_l16.c b/libgfortran/generated/all_l16.c index 4ad871d306a..24aa4d71278 100644 --- a/libgfortran/generated/all_l16.c +++ b/libgfortran/generated/all_l16.c @@ -69,16 +69,24 @@ all_l16 (gfc_array_l16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ all_l16 (gfc_array_l16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_LOGICAL_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_LOGICAL_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/all_l4.c b/libgfortran/generated/all_l4.c index fbfcd8bd65b..be4fece74e3 100644 --- a/libgfortran/generated/all_l4.c +++ b/libgfortran/generated/all_l4.c @@ -69,16 +69,24 @@ all_l4 (gfc_array_l4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ all_l4 (gfc_array_l4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_LOGICAL_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_LOGICAL_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/all_l8.c b/libgfortran/generated/all_l8.c index b41c4c2b22b..684510c5f20 100644 --- a/libgfortran/generated/all_l8.c +++ b/libgfortran/generated/all_l8.c @@ -69,16 +69,24 @@ all_l8 (gfc_array_l8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ all_l8 (gfc_array_l8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_LOGICAL_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_LOGICAL_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/any_l16.c b/libgfortran/generated/any_l16.c index ad4516c123a..d351f222717 100644 --- a/libgfortran/generated/any_l16.c +++ b/libgfortran/generated/any_l16.c @@ -69,16 +69,24 @@ any_l16 (gfc_array_l16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ any_l16 (gfc_array_l16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_LOGICAL_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_LOGICAL_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/any_l4.c b/libgfortran/generated/any_l4.c index 6f922fdac17..316d9e25231 100644 --- a/libgfortran/generated/any_l4.c +++ b/libgfortran/generated/any_l4.c @@ -69,16 +69,24 @@ any_l4 (gfc_array_l4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ any_l4 (gfc_array_l4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_LOGICAL_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_LOGICAL_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/any_l8.c b/libgfortran/generated/any_l8.c index 2a379d3d519..6efe431da40 100644 --- a/libgfortran/generated/any_l8.c +++ b/libgfortran/generated/any_l8.c @@ -69,16 +69,24 @@ any_l8 (gfc_array_l8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ any_l8 (gfc_array_l8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_LOGICAL_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_LOGICAL_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/count_16_l16.c b/libgfortran/generated/count_16_l16.c index 92b2247f3bd..c396650eff1 100644 --- a/libgfortran/generated/count_16_l16.c +++ b/libgfortran/generated/count_16_l16.c @@ -69,16 +69,24 @@ count_16_l16 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ count_16_l16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/count_16_l4.c b/libgfortran/generated/count_16_l4.c index 91811530cdd..0f417ac96f3 100644 --- a/libgfortran/generated/count_16_l4.c +++ b/libgfortran/generated/count_16_l4.c @@ -69,16 +69,24 @@ count_16_l4 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ count_16_l4 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/count_16_l8.c b/libgfortran/generated/count_16_l8.c index de41758ced3..2e4ea41b693 100644 --- a/libgfortran/generated/count_16_l8.c +++ b/libgfortran/generated/count_16_l8.c @@ -69,16 +69,24 @@ count_16_l8 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ count_16_l8 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/count_4_l16.c b/libgfortran/generated/count_4_l16.c index ad9b9016c2c..0c13dd48222 100644 --- a/libgfortran/generated/count_4_l16.c +++ b/libgfortran/generated/count_4_l16.c @@ -69,16 +69,24 @@ count_4_l16 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ count_4_l16 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/count_4_l4.c b/libgfortran/generated/count_4_l4.c index f5a46bf1a47..6a8fde0b4b9 100644 --- a/libgfortran/generated/count_4_l4.c +++ b/libgfortran/generated/count_4_l4.c @@ -69,16 +69,24 @@ count_4_l4 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ count_4_l4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/count_4_l8.c b/libgfortran/generated/count_4_l8.c index 5ec58bf4f60..f1fd30296b3 100644 --- a/libgfortran/generated/count_4_l8.c +++ b/libgfortran/generated/count_4_l8.c @@ -69,16 +69,24 @@ count_4_l8 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ count_4_l8 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/count_8_l16.c b/libgfortran/generated/count_8_l16.c index 87c291eeba7..2c75d93e000 100644 --- a/libgfortran/generated/count_8_l16.c +++ b/libgfortran/generated/count_8_l16.c @@ -69,16 +69,24 @@ count_8_l16 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ count_8_l16 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/count_8_l4.c b/libgfortran/generated/count_8_l4.c index 1a5451bf3e2..9ecddbd10b1 100644 --- a/libgfortran/generated/count_8_l4.c +++ b/libgfortran/generated/count_8_l4.c @@ -69,16 +69,24 @@ count_8_l4 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ count_8_l4 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/count_8_l8.c b/libgfortran/generated/count_8_l8.c index b255d9d36ab..8ba9ed41d55 100644 --- a/libgfortran/generated/count_8_l8.c +++ b/libgfortran/generated/count_8_l8.c @@ -69,16 +69,24 @@ count_8_l8 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ count_8_l8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { diff --git a/libgfortran/generated/cshift1_16.c b/libgfortran/generated/cshift1_16.c index bf7845b7ac7..9bbe482dd71 100644 --- a/libgfortran/generated/cshift1_16.c +++ b/libgfortran/generated/cshift1_16.c @@ -55,7 +55,7 @@ cshift1 (gfc_array_char * const restrict ret, index_type soffset; const char *sptr; const char *src; - /* h.* indicates the array. */ + /* h.* indicates the shift array. */ index_type hstride[GFC_MAX_DIMENSIONS]; index_type hstride0; const GFC_INTEGER_16 *hptr; @@ -144,7 +144,7 @@ cshift1 (gfc_array_char * const restrict ret, while (rptr) { - /* Do the for this dimension. */ + /* Do the shift for this dimension. */ sh = *hptr; sh = (div (sh, len)).rem; if (sh < 0) diff --git a/libgfortran/generated/cshift1_4.c b/libgfortran/generated/cshift1_4.c index 1b3d07f2942..f4a357e6220 100644 --- a/libgfortran/generated/cshift1_4.c +++ b/libgfortran/generated/cshift1_4.c @@ -55,7 +55,7 @@ cshift1 (gfc_array_char * const restrict ret, index_type soffset; const char *sptr; const char *src; - /* h.* indicates the array. */ + /* h.* indicates the shift array. */ index_type hstride[GFC_MAX_DIMENSIONS]; index_type hstride0; const GFC_INTEGER_4 *hptr; @@ -144,7 +144,7 @@ cshift1 (gfc_array_char * const restrict ret, while (rptr) { - /* Do the for this dimension. */ + /* Do the shift for this dimension. */ sh = *hptr; sh = (div (sh, len)).rem; if (sh < 0) diff --git a/libgfortran/generated/cshift1_8.c b/libgfortran/generated/cshift1_8.c index 58fc0361362..9e9a8a0c696 100644 --- a/libgfortran/generated/cshift1_8.c +++ b/libgfortran/generated/cshift1_8.c @@ -55,7 +55,7 @@ cshift1 (gfc_array_char * const restrict ret, index_type soffset; const char *sptr; const char *src; - /* h.* indicates the array. */ + /* h.* indicates the shift array. */ index_type hstride[GFC_MAX_DIMENSIONS]; index_type hstride0; const GFC_INTEGER_8 *hptr; @@ -144,7 +144,7 @@ cshift1 (gfc_array_char * const restrict ret, while (rptr) { - /* Do the for this dimension. */ + /* Do the shift for this dimension. */ sh = *hptr; sh = (div (sh, len)).rem; if (sh < 0) diff --git a/libgfortran/generated/maxloc1_16_i16.c b/libgfortran/generated/maxloc1_16_i16.c index 3964c3fd865..c01a006f8ea 100644 --- a/libgfortran/generated/maxloc1_16_i16.c +++ b/libgfortran/generated/maxloc1_16_i16.c @@ -71,16 +71,24 @@ maxloc1_16_i16 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_16_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_16_i16 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_16_i16 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_16_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_16_i4.c b/libgfortran/generated/maxloc1_16_i4.c index 3516f22e5e2..dd0739c5915 100644 --- a/libgfortran/generated/maxloc1_16_i4.c +++ b/libgfortran/generated/maxloc1_16_i4.c @@ -71,16 +71,24 @@ maxloc1_16_i4 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_16_i4 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_16_i4 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_16_i4 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_16_i4 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_16_i8.c b/libgfortran/generated/maxloc1_16_i8.c index 2887eb7c7b2..c18a8e5a791 100644 --- a/libgfortran/generated/maxloc1_16_i8.c +++ b/libgfortran/generated/maxloc1_16_i8.c @@ -71,16 +71,24 @@ maxloc1_16_i8 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_16_i8 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_16_i8 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_16_i8 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_16_i8 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_16_r10.c b/libgfortran/generated/maxloc1_16_r10.c index 826fd2e17cc..1d4a4cb8609 100644 --- a/libgfortran/generated/maxloc1_16_r10.c +++ b/libgfortran/generated/maxloc1_16_r10.c @@ -71,16 +71,24 @@ maxloc1_16_r10 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_16_r10 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_16_r10 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_16_r10 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_16_r10 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_16_r16.c b/libgfortran/generated/maxloc1_16_r16.c index 61c10773cf2..18e0a5542e6 100644 --- a/libgfortran/generated/maxloc1_16_r16.c +++ b/libgfortran/generated/maxloc1_16_r16.c @@ -71,16 +71,24 @@ maxloc1_16_r16 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_16_r16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_16_r16 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_16_r16 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_16_r16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_16_r4.c b/libgfortran/generated/maxloc1_16_r4.c index 7e0d84e04b0..10715a041b6 100644 --- a/libgfortran/generated/maxloc1_16_r4.c +++ b/libgfortran/generated/maxloc1_16_r4.c @@ -71,16 +71,24 @@ maxloc1_16_r4 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_16_r4 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_16_r4 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_16_r4 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_16_r4 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_16_r8.c b/libgfortran/generated/maxloc1_16_r8.c index 3b56f4c1d9b..a2b6f310ef6 100644 --- a/libgfortran/generated/maxloc1_16_r8.c +++ b/libgfortran/generated/maxloc1_16_r8.c @@ -71,16 +71,24 @@ maxloc1_16_r8 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_16_r8 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_16_r8 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_16_r8 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_16_r8 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_4_i16.c b/libgfortran/generated/maxloc1_4_i16.c index 016580373d1..0c8a0cc33c6 100644 --- a/libgfortran/generated/maxloc1_4_i16.c +++ b/libgfortran/generated/maxloc1_4_i16.c @@ -71,16 +71,24 @@ maxloc1_4_i16 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_4_i16 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_4_i16 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_4_i16 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_4_i16 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_4_i4.c b/libgfortran/generated/maxloc1_4_i4.c index 1109eb7c022..83131ffd33b 100644 --- a/libgfortran/generated/maxloc1_4_i4.c +++ b/libgfortran/generated/maxloc1_4_i4.c @@ -71,16 +71,24 @@ maxloc1_4_i4 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_4_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_4_i4 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_4_i4 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_4_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_4_i8.c b/libgfortran/generated/maxloc1_4_i8.c index a530c57ed01..bb553eb884e 100644 --- a/libgfortran/generated/maxloc1_4_i8.c +++ b/libgfortran/generated/maxloc1_4_i8.c @@ -71,16 +71,24 @@ maxloc1_4_i8 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_4_i8 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_4_i8 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_4_i8 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_4_i8 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_4_r10.c b/libgfortran/generated/maxloc1_4_r10.c index 77e9fec6889..0fb88545c04 100644 --- a/libgfortran/generated/maxloc1_4_r10.c +++ b/libgfortran/generated/maxloc1_4_r10.c @@ -71,16 +71,24 @@ maxloc1_4_r10 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_4_r10 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_4_r10 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_4_r10 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_4_r10 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_4_r16.c b/libgfortran/generated/maxloc1_4_r16.c index ccdfbbb8b2f..140731aa615 100644 --- a/libgfortran/generated/maxloc1_4_r16.c +++ b/libgfortran/generated/maxloc1_4_r16.c @@ -71,16 +71,24 @@ maxloc1_4_r16 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_4_r16 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_4_r16 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_4_r16 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_4_r16 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_4_r4.c b/libgfortran/generated/maxloc1_4_r4.c index 431a051023d..1daf4fee971 100644 --- a/libgfortran/generated/maxloc1_4_r4.c +++ b/libgfortran/generated/maxloc1_4_r4.c @@ -71,16 +71,24 @@ maxloc1_4_r4 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_4_r4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_4_r4 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_4_r4 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_4_r4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_4_r8.c b/libgfortran/generated/maxloc1_4_r8.c index 10e181f341d..90c169afabb 100644 --- a/libgfortran/generated/maxloc1_4_r8.c +++ b/libgfortran/generated/maxloc1_4_r8.c @@ -71,16 +71,24 @@ maxloc1_4_r8 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_4_r8 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_4_r8 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_4_r8 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_4_r8 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_8_i16.c b/libgfortran/generated/maxloc1_8_i16.c index b28dab49742..d4bff32de4e 100644 --- a/libgfortran/generated/maxloc1_8_i16.c +++ b/libgfortran/generated/maxloc1_8_i16.c @@ -71,16 +71,24 @@ maxloc1_8_i16 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_8_i16 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_8_i16 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_8_i16 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_8_i16 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_8_i4.c b/libgfortran/generated/maxloc1_8_i4.c index 72a9084e341..9225f13c791 100644 --- a/libgfortran/generated/maxloc1_8_i4.c +++ b/libgfortran/generated/maxloc1_8_i4.c @@ -71,16 +71,24 @@ maxloc1_8_i4 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_8_i4 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_8_i4 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_8_i4 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_8_i4 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_8_i8.c b/libgfortran/generated/maxloc1_8_i8.c index b056e6d1f0f..c0179cd8b7a 100644 --- a/libgfortran/generated/maxloc1_8_i8.c +++ b/libgfortran/generated/maxloc1_8_i8.c @@ -71,16 +71,24 @@ maxloc1_8_i8 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_8_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_8_i8 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_8_i8 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_8_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_8_r10.c b/libgfortran/generated/maxloc1_8_r10.c index f8a5ddb7b48..9bf455ad8be 100644 --- a/libgfortran/generated/maxloc1_8_r10.c +++ b/libgfortran/generated/maxloc1_8_r10.c @@ -71,16 +71,24 @@ maxloc1_8_r10 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_8_r10 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_8_r10 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_8_r10 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_8_r10 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_8_r16.c b/libgfortran/generated/maxloc1_8_r16.c index 26c90b76bbc..13f3c189ec0 100644 --- a/libgfortran/generated/maxloc1_8_r16.c +++ b/libgfortran/generated/maxloc1_8_r16.c @@ -71,16 +71,24 @@ maxloc1_8_r16 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_8_r16 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_8_r16 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_8_r16 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_8_r16 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_8_r4.c b/libgfortran/generated/maxloc1_8_r4.c index 8cb1c1b5a62..313951b1dd0 100644 --- a/libgfortran/generated/maxloc1_8_r4.c +++ b/libgfortran/generated/maxloc1_8_r4.c @@ -71,16 +71,24 @@ maxloc1_8_r4 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_8_r4 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_8_r4 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_8_r4 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_8_r4 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxloc1_8_r8.c b/libgfortran/generated/maxloc1_8_r8.c index 2170a76d9b5..bc694c7ebe0 100644 --- a/libgfortran/generated/maxloc1_8_r8.c +++ b/libgfortran/generated/maxloc1_8_r8.c @@ -71,16 +71,24 @@ maxloc1_8_r8 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ maxloc1_8_r8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mmaxloc1_8_r8 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mmaxloc1_8_r8 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mmaxloc1_8_r8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxval_i16.c b/libgfortran/generated/maxval_i16.c index a43a50698c0..8bdab56d54d 100644 --- a/libgfortran/generated/maxval_i16.c +++ b/libgfortran/generated/maxval_i16.c @@ -70,16 +70,24 @@ maxval_i16 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ maxval_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mmaxval_i16 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mmaxval_i16 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mmaxval_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxval_i4.c b/libgfortran/generated/maxval_i4.c index 9cc078b67a3..ba5b3106841 100644 --- a/libgfortran/generated/maxval_i4.c +++ b/libgfortran/generated/maxval_i4.c @@ -70,16 +70,24 @@ maxval_i4 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ maxval_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mmaxval_i4 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mmaxval_i4 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mmaxval_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxval_i8.c b/libgfortran/generated/maxval_i8.c index 30ab0cb79a6..ee6a5d2d87c 100644 --- a/libgfortran/generated/maxval_i8.c +++ b/libgfortran/generated/maxval_i8.c @@ -70,16 +70,24 @@ maxval_i8 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ maxval_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mmaxval_i8 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mmaxval_i8 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mmaxval_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxval_r10.c b/libgfortran/generated/maxval_r10.c index ed884622dd0..2dcfbef5add 100644 --- a/libgfortran/generated/maxval_r10.c +++ b/libgfortran/generated/maxval_r10.c @@ -70,16 +70,24 @@ maxval_r10 (gfc_array_r10 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ maxval_r10 (gfc_array_r10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mmaxval_r10 (gfc_array_r10 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mmaxval_r10 (gfc_array_r10 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mmaxval_r10 (gfc_array_r10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxval_r16.c b/libgfortran/generated/maxval_r16.c index 94d6789a2eb..bc456f9045d 100644 --- a/libgfortran/generated/maxval_r16.c +++ b/libgfortran/generated/maxval_r16.c @@ -70,16 +70,24 @@ maxval_r16 (gfc_array_r16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ maxval_r16 (gfc_array_r16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mmaxval_r16 (gfc_array_r16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mmaxval_r16 (gfc_array_r16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mmaxval_r16 (gfc_array_r16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxval_r4.c b/libgfortran/generated/maxval_r4.c index 8b3e1d41965..89c944def99 100644 --- a/libgfortran/generated/maxval_r4.c +++ b/libgfortran/generated/maxval_r4.c @@ -70,16 +70,24 @@ maxval_r4 (gfc_array_r4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ maxval_r4 (gfc_array_r4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mmaxval_r4 (gfc_array_r4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mmaxval_r4 (gfc_array_r4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mmaxval_r4 (gfc_array_r4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/maxval_r8.c b/libgfortran/generated/maxval_r8.c index f98ca68b9f8..b53d7deaac6 100644 --- a/libgfortran/generated/maxval_r8.c +++ b/libgfortran/generated/maxval_r8.c @@ -70,16 +70,24 @@ maxval_r8 (gfc_array_r8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ maxval_r8 (gfc_array_r8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mmaxval_r8 (gfc_array_r8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mmaxval_r8 (gfc_array_r8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mmaxval_r8 (gfc_array_r8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_16_i16.c b/libgfortran/generated/minloc1_16_i16.c index d27e5b3dd76..ebbecec7c11 100644 --- a/libgfortran/generated/minloc1_16_i16.c +++ b/libgfortran/generated/minloc1_16_i16.c @@ -71,16 +71,24 @@ minloc1_16_i16 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_16_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_16_i16 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_16_i16 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_16_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_16_i4.c b/libgfortran/generated/minloc1_16_i4.c index 64925cdf132..9b12ab48a89 100644 --- a/libgfortran/generated/minloc1_16_i4.c +++ b/libgfortran/generated/minloc1_16_i4.c @@ -71,16 +71,24 @@ minloc1_16_i4 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_16_i4 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_16_i4 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_16_i4 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_16_i4 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_16_i8.c b/libgfortran/generated/minloc1_16_i8.c index 7ec2c1cc9e6..a0e447f44ea 100644 --- a/libgfortran/generated/minloc1_16_i8.c +++ b/libgfortran/generated/minloc1_16_i8.c @@ -71,16 +71,24 @@ minloc1_16_i8 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_16_i8 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_16_i8 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_16_i8 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_16_i8 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_16_r10.c b/libgfortran/generated/minloc1_16_r10.c index 7865d7ed9eb..9cbc80cb53d 100644 --- a/libgfortran/generated/minloc1_16_r10.c +++ b/libgfortran/generated/minloc1_16_r10.c @@ -71,16 +71,24 @@ minloc1_16_r10 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_16_r10 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_16_r10 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_16_r10 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_16_r10 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_16_r16.c b/libgfortran/generated/minloc1_16_r16.c index 8e0b36e640f..e3efc0db8ae 100644 --- a/libgfortran/generated/minloc1_16_r16.c +++ b/libgfortran/generated/minloc1_16_r16.c @@ -71,16 +71,24 @@ minloc1_16_r16 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_16_r16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_16_r16 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_16_r16 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_16_r16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_16_r4.c b/libgfortran/generated/minloc1_16_r4.c index 8d7f1f15a6b..6fb0ef49414 100644 --- a/libgfortran/generated/minloc1_16_r4.c +++ b/libgfortran/generated/minloc1_16_r4.c @@ -71,16 +71,24 @@ minloc1_16_r4 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_16_r4 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_16_r4 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_16_r4 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_16_r4 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_16_r8.c b/libgfortran/generated/minloc1_16_r8.c index dd4be68c7eb..0b0e7b98d4c 100644 --- a/libgfortran/generated/minloc1_16_r8.c +++ b/libgfortran/generated/minloc1_16_r8.c @@ -71,16 +71,24 @@ minloc1_16_r8 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_16_r8 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_16_r8 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_16_r8 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_16_r8 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_4_i16.c b/libgfortran/generated/minloc1_4_i16.c index ce865e810e6..e72c8e4f60b 100644 --- a/libgfortran/generated/minloc1_4_i16.c +++ b/libgfortran/generated/minloc1_4_i16.c @@ -71,16 +71,24 @@ minloc1_4_i16 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_4_i16 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_4_i16 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_4_i16 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_4_i16 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_4_i4.c b/libgfortran/generated/minloc1_4_i4.c index 4032f1ef741..64e80a30b14 100644 --- a/libgfortran/generated/minloc1_4_i4.c +++ b/libgfortran/generated/minloc1_4_i4.c @@ -71,16 +71,24 @@ minloc1_4_i4 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_4_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_4_i4 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_4_i4 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_4_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_4_i8.c b/libgfortran/generated/minloc1_4_i8.c index 648a658ecf1..408e8328a46 100644 --- a/libgfortran/generated/minloc1_4_i8.c +++ b/libgfortran/generated/minloc1_4_i8.c @@ -71,16 +71,24 @@ minloc1_4_i8 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_4_i8 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_4_i8 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_4_i8 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_4_i8 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_4_r10.c b/libgfortran/generated/minloc1_4_r10.c index 88ae0826074..64ea02e0602 100644 --- a/libgfortran/generated/minloc1_4_r10.c +++ b/libgfortran/generated/minloc1_4_r10.c @@ -71,16 +71,24 @@ minloc1_4_r10 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_4_r10 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_4_r10 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_4_r10 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_4_r10 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_4_r16.c b/libgfortran/generated/minloc1_4_r16.c index fdf995a98cb..34ce250e170 100644 --- a/libgfortran/generated/minloc1_4_r16.c +++ b/libgfortran/generated/minloc1_4_r16.c @@ -71,16 +71,24 @@ minloc1_4_r16 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_4_r16 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_4_r16 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_4_r16 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_4_r16 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_4_r4.c b/libgfortran/generated/minloc1_4_r4.c index ca98b5a8c91..1e22a50aca3 100644 --- a/libgfortran/generated/minloc1_4_r4.c +++ b/libgfortran/generated/minloc1_4_r4.c @@ -71,16 +71,24 @@ minloc1_4_r4 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_4_r4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_4_r4 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_4_r4 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_4_r4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_4_r8.c b/libgfortran/generated/minloc1_4_r8.c index 532954d176d..c46393cff3b 100644 --- a/libgfortran/generated/minloc1_4_r8.c +++ b/libgfortran/generated/minloc1_4_r8.c @@ -71,16 +71,24 @@ minloc1_4_r8 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_4_r8 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_4_r8 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_4_r8 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_4_r8 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_8_i16.c b/libgfortran/generated/minloc1_8_i16.c index 83cdc6b748a..d4392f6cc31 100644 --- a/libgfortran/generated/minloc1_8_i16.c +++ b/libgfortran/generated/minloc1_8_i16.c @@ -71,16 +71,24 @@ minloc1_8_i16 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_8_i16 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_8_i16 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_8_i16 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_8_i16 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_8_i4.c b/libgfortran/generated/minloc1_8_i4.c index 6382e9b6053..f47b5f7b598 100644 --- a/libgfortran/generated/minloc1_8_i4.c +++ b/libgfortran/generated/minloc1_8_i4.c @@ -71,16 +71,24 @@ minloc1_8_i4 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_8_i4 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_8_i4 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_8_i4 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_8_i4 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_8_i8.c b/libgfortran/generated/minloc1_8_i8.c index 82c3836cae8..8de5f03e3d4 100644 --- a/libgfortran/generated/minloc1_8_i8.c +++ b/libgfortran/generated/minloc1_8_i8.c @@ -71,16 +71,24 @@ minloc1_8_i8 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_8_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_8_i8 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_8_i8 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_8_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_8_r10.c b/libgfortran/generated/minloc1_8_r10.c index 8cb2e28174a..5285cc22b39 100644 --- a/libgfortran/generated/minloc1_8_r10.c +++ b/libgfortran/generated/minloc1_8_r10.c @@ -71,16 +71,24 @@ minloc1_8_r10 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_8_r10 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_8_r10 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_8_r10 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_8_r10 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_8_r16.c b/libgfortran/generated/minloc1_8_r16.c index 74eb70bc354..30753ce24f4 100644 --- a/libgfortran/generated/minloc1_8_r16.c +++ b/libgfortran/generated/minloc1_8_r16.c @@ -71,16 +71,24 @@ minloc1_8_r16 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_8_r16 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_8_r16 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_8_r16 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_8_r16 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_8_r4.c b/libgfortran/generated/minloc1_8_r4.c index a6ed57e349a..069e0496f72 100644 --- a/libgfortran/generated/minloc1_8_r4.c +++ b/libgfortran/generated/minloc1_8_r4.c @@ -71,16 +71,24 @@ minloc1_8_r4 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_8_r4 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_8_r4 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_8_r4 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_8_r4 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minloc1_8_r8.c b/libgfortran/generated/minloc1_8_r8.c index b03e4974bc2..260898c7a6e 100644 --- a/libgfortran/generated/minloc1_8_r8.c +++ b/libgfortran/generated/minloc1_8_r8.c @@ -71,16 +71,24 @@ minloc1_8_r8 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -91,12 +99,21 @@ minloc1_8_r8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -213,6 +230,10 @@ mminloc1_8_r8 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -220,10 +241,15 @@ mminloc1_8_r8 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -234,12 +260,22 @@ mminloc1_8_r8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minval_i16.c b/libgfortran/generated/minval_i16.c index a2e7ed84bfb..cc1066bc82c 100644 --- a/libgfortran/generated/minval_i16.c +++ b/libgfortran/generated/minval_i16.c @@ -70,16 +70,24 @@ minval_i16 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ minval_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mminval_i16 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mminval_i16 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mminval_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minval_i4.c b/libgfortran/generated/minval_i4.c index e22a773d412..9bea78aa57c 100644 --- a/libgfortran/generated/minval_i4.c +++ b/libgfortran/generated/minval_i4.c @@ -70,16 +70,24 @@ minval_i4 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ minval_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mminval_i4 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mminval_i4 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mminval_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minval_i8.c b/libgfortran/generated/minval_i8.c index ff289574685..023e9e8269e 100644 --- a/libgfortran/generated/minval_i8.c +++ b/libgfortran/generated/minval_i8.c @@ -70,16 +70,24 @@ minval_i8 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ minval_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mminval_i8 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mminval_i8 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mminval_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minval_r10.c b/libgfortran/generated/minval_r10.c index 4bbe2002c81..3a8a5c089ae 100644 --- a/libgfortran/generated/minval_r10.c +++ b/libgfortran/generated/minval_r10.c @@ -70,16 +70,24 @@ minval_r10 (gfc_array_r10 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ minval_r10 (gfc_array_r10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mminval_r10 (gfc_array_r10 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mminval_r10 (gfc_array_r10 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mminval_r10 (gfc_array_r10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minval_r16.c b/libgfortran/generated/minval_r16.c index 4e16dbf257f..82df48c22e4 100644 --- a/libgfortran/generated/minval_r16.c +++ b/libgfortran/generated/minval_r16.c @@ -70,16 +70,24 @@ minval_r16 (gfc_array_r16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ minval_r16 (gfc_array_r16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mminval_r16 (gfc_array_r16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mminval_r16 (gfc_array_r16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mminval_r16 (gfc_array_r16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minval_r4.c b/libgfortran/generated/minval_r4.c index 0f1a00f29b0..950449bab9d 100644 --- a/libgfortran/generated/minval_r4.c +++ b/libgfortran/generated/minval_r4.c @@ -70,16 +70,24 @@ minval_r4 (gfc_array_r4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ minval_r4 (gfc_array_r4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mminval_r4 (gfc_array_r4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mminval_r4 (gfc_array_r4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mminval_r4 (gfc_array_r4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/minval_r8.c b/libgfortran/generated/minval_r8.c index 4bb77996653..ec814815e96 100644 --- a/libgfortran/generated/minval_r8.c +++ b/libgfortran/generated/minval_r8.c @@ -70,16 +70,24 @@ minval_r8 (gfc_array_r8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -90,12 +98,21 @@ minval_r8 (gfc_array_r8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -207,6 +224,10 @@ mminval_r8 (gfc_array_r8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -214,10 +235,15 @@ mminval_r8 (gfc_array_r8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -228,12 +254,22 @@ mminval_r8 (gfc_array_r8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/product_c10.c b/libgfortran/generated/product_c10.c index f5434efd256..0d73a9b799c 100644 --- a/libgfortran/generated/product_c10.c +++ b/libgfortran/generated/product_c10.c @@ -69,16 +69,24 @@ product_c10 (gfc_array_c10 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ product_c10 (gfc_array_c10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_COMPLEX_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ mproduct_c10 (gfc_array_c10 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ mproduct_c10 (gfc_array_c10 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ mproduct_c10 (gfc_array_c10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_COMPLEX_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/product_c16.c b/libgfortran/generated/product_c16.c index 382e4192d09..a5c8bd07e74 100644 --- a/libgfortran/generated/product_c16.c +++ b/libgfortran/generated/product_c16.c @@ -69,16 +69,24 @@ product_c16 (gfc_array_c16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ product_c16 (gfc_array_c16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_COMPLEX_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ mproduct_c16 (gfc_array_c16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ mproduct_c16 (gfc_array_c16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ mproduct_c16 (gfc_array_c16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_COMPLEX_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/product_c4.c b/libgfortran/generated/product_c4.c index 5a40f8430d7..45a62c9cfb9 100644 --- a/libgfortran/generated/product_c4.c +++ b/libgfortran/generated/product_c4.c @@ -69,16 +69,24 @@ product_c4 (gfc_array_c4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ product_c4 (gfc_array_c4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_COMPLEX_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ mproduct_c4 (gfc_array_c4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ mproduct_c4 (gfc_array_c4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ mproduct_c4 (gfc_array_c4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_COMPLEX_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/product_c8.c b/libgfortran/generated/product_c8.c index d057ec99429..69bcb87c399 100644 --- a/libgfortran/generated/product_c8.c +++ b/libgfortran/generated/product_c8.c @@ -69,16 +69,24 @@ product_c8 (gfc_array_c8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ product_c8 (gfc_array_c8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_COMPLEX_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ mproduct_c8 (gfc_array_c8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ mproduct_c8 (gfc_array_c8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ mproduct_c8 (gfc_array_c8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_COMPLEX_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/product_i16.c b/libgfortran/generated/product_i16.c index 33db08f70b0..7b735783094 100644 --- a/libgfortran/generated/product_i16.c +++ b/libgfortran/generated/product_i16.c @@ -69,16 +69,24 @@ product_i16 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ product_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ mproduct_i16 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ mproduct_i16 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ mproduct_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/product_i4.c b/libgfortran/generated/product_i4.c index 69e1826f31e..72d0e1afbad 100644 --- a/libgfortran/generated/product_i4.c +++ b/libgfortran/generated/product_i4.c @@ -69,16 +69,24 @@ product_i4 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ product_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ mproduct_i4 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ mproduct_i4 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ mproduct_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/product_i8.c b/libgfortran/generated/product_i8.c index f62a281f2ad..d1ae82e4303 100644 --- a/libgfortran/generated/product_i8.c +++ b/libgfortran/generated/product_i8.c @@ -69,16 +69,24 @@ product_i8 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ product_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ mproduct_i8 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ mproduct_i8 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ mproduct_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/product_r10.c b/libgfortran/generated/product_r10.c index 26e3f04e69c..f19b67ba949 100644 --- a/libgfortran/generated/product_r10.c +++ b/libgfortran/generated/product_r10.c @@ -69,16 +69,24 @@ product_r10 (gfc_array_r10 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ product_r10 (gfc_array_r10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ mproduct_r10 (gfc_array_r10 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ mproduct_r10 (gfc_array_r10 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ mproduct_r10 (gfc_array_r10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/product_r16.c b/libgfortran/generated/product_r16.c index 2fc1ca1a130..3d0a76a4ade 100644 --- a/libgfortran/generated/product_r16.c +++ b/libgfortran/generated/product_r16.c @@ -69,16 +69,24 @@ product_r16 (gfc_array_r16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ product_r16 (gfc_array_r16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ mproduct_r16 (gfc_array_r16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ mproduct_r16 (gfc_array_r16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ mproduct_r16 (gfc_array_r16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/product_r4.c b/libgfortran/generated/product_r4.c index f0723c69a0e..069b0d0c0e7 100644 --- a/libgfortran/generated/product_r4.c +++ b/libgfortran/generated/product_r4.c @@ -69,16 +69,24 @@ product_r4 (gfc_array_r4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ product_r4 (gfc_array_r4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ mproduct_r4 (gfc_array_r4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ mproduct_r4 (gfc_array_r4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ mproduct_r4 (gfc_array_r4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/product_r8.c b/libgfortran/generated/product_r8.c index a829ff80019..e9cfae39782 100644 --- a/libgfortran/generated/product_r8.c +++ b/libgfortran/generated/product_r8.c @@ -69,16 +69,24 @@ product_r8 (gfc_array_r8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ product_r8 (gfc_array_r8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ mproduct_r8 (gfc_array_r8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ mproduct_r8 (gfc_array_r8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ mproduct_r8 (gfc_array_r8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/sum_c10.c b/libgfortran/generated/sum_c10.c index 34788c55e9e..96b878b7fcd 100644 --- a/libgfortran/generated/sum_c10.c +++ b/libgfortran/generated/sum_c10.c @@ -69,16 +69,24 @@ sum_c10 (gfc_array_c10 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ sum_c10 (gfc_array_c10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_COMPLEX_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ msum_c10 (gfc_array_c10 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ msum_c10 (gfc_array_c10 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ msum_c10 (gfc_array_c10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_COMPLEX_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/sum_c16.c b/libgfortran/generated/sum_c16.c index ba1b0571fd5..a99d4f65b62 100644 --- a/libgfortran/generated/sum_c16.c +++ b/libgfortran/generated/sum_c16.c @@ -69,16 +69,24 @@ sum_c16 (gfc_array_c16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ sum_c16 (gfc_array_c16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_COMPLEX_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ msum_c16 (gfc_array_c16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ msum_c16 (gfc_array_c16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ msum_c16 (gfc_array_c16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_COMPLEX_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/sum_c4.c b/libgfortran/generated/sum_c4.c index e3f9e67d46f..83979fbdf21 100644 --- a/libgfortran/generated/sum_c4.c +++ b/libgfortran/generated/sum_c4.c @@ -69,16 +69,24 @@ sum_c4 (gfc_array_c4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ sum_c4 (gfc_array_c4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_COMPLEX_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ msum_c4 (gfc_array_c4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ msum_c4 (gfc_array_c4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ msum_c4 (gfc_array_c4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_COMPLEX_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/sum_c8.c b/libgfortran/generated/sum_c8.c index 18e45c39812..d82092a1b6b 100644 --- a/libgfortran/generated/sum_c8.c +++ b/libgfortran/generated/sum_c8.c @@ -69,16 +69,24 @@ sum_c8 (gfc_array_c8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ sum_c8 (gfc_array_c8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_COMPLEX_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ msum_c8 (gfc_array_c8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ msum_c8 (gfc_array_c8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ msum_c8 (gfc_array_c8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_COMPLEX_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_COMPLEX_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/sum_i16.c b/libgfortran/generated/sum_i16.c index 95c4c3269f6..83857734a00 100644 --- a/libgfortran/generated/sum_i16.c +++ b/libgfortran/generated/sum_i16.c @@ -69,16 +69,24 @@ sum_i16 (gfc_array_i16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ sum_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ msum_i16 (gfc_array_i16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ msum_i16 (gfc_array_i16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ msum_i16 (gfc_array_i16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/sum_i4.c b/libgfortran/generated/sum_i4.c index 3421a202fe7..e97d15c62ba 100644 --- a/libgfortran/generated/sum_i4.c +++ b/libgfortran/generated/sum_i4.c @@ -69,16 +69,24 @@ sum_i4 (gfc_array_i4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ sum_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ msum_i4 (gfc_array_i4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ msum_i4 (gfc_array_i4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ msum_i4 (gfc_array_i4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/sum_i8.c b/libgfortran/generated/sum_i8.c index b67f576907c..da913442b4f 100644 --- a/libgfortran/generated/sum_i8.c +++ b/libgfortran/generated/sum_i8.c @@ -69,16 +69,24 @@ sum_i8 (gfc_array_i8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ sum_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ msum_i8 (gfc_array_i8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ msum_i8 (gfc_array_i8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ msum_i8 (gfc_array_i8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_INTEGER_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/sum_r10.c b/libgfortran/generated/sum_r10.c index 730b0688981..0433c90f90b 100644 --- a/libgfortran/generated/sum_r10.c +++ b/libgfortran/generated/sum_r10.c @@ -69,16 +69,24 @@ sum_r10 (gfc_array_r10 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ sum_r10 (gfc_array_r10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ msum_r10 (gfc_array_r10 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ msum_r10 (gfc_array_r10 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ msum_r10 (gfc_array_r10 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_10) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_10) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/sum_r16.c b/libgfortran/generated/sum_r16.c index af7f5c8f9e3..2c9fdf5b221 100644 --- a/libgfortran/generated/sum_r16.c +++ b/libgfortran/generated/sum_r16.c @@ -69,16 +69,24 @@ sum_r16 (gfc_array_r16 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ sum_r16 (gfc_array_r16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ msum_r16 (gfc_array_r16 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ msum_r16 (gfc_array_r16 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ msum_r16 (gfc_array_r16 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_16) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_16) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/sum_r4.c b/libgfortran/generated/sum_r4.c index 7d30805c195..e3c33fbf1d4 100644 --- a/libgfortran/generated/sum_r4.c +++ b/libgfortran/generated/sum_r4.c @@ -69,16 +69,24 @@ sum_r4 (gfc_array_r4 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ sum_r4 (gfc_array_r4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ msum_r4 (gfc_array_r4 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ msum_r4 (gfc_array_r4 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ msum_r4 (gfc_array_r4 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_4) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_4) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/generated/sum_r8.c b/libgfortran/generated/sum_r8.c index 6e07e2a8fa7..4d331e277a7 100644 --- a/libgfortran/generated/sum_r8.c +++ b/libgfortran/generated/sum_r8.c @@ -69,16 +69,24 @@ sum_r8 (gfc_array_r8 * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -89,12 +97,21 @@ sum_r8 (gfc_array_r8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (GFC_REAL_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -205,6 +222,10 @@ msum_r8 (gfc_array_r8 * const restrict retarray, sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -212,10 +233,15 @@ msum_r8 (gfc_array_r8 * const restrict retarray, mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -226,12 +252,22 @@ msum_r8 (gfc_array_r8 * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (GFC_REAL_8) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (GFC_REAL_8) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { diff --git a/libgfortran/m4/ifunction.m4 b/libgfortran/m4/ifunction.m4 index d2f2a80c423..225b89a7562 100644 --- a/libgfortran/m4/ifunction.m4 +++ b/libgfortran/m4/ifunction.m4 @@ -51,16 +51,24 @@ name`'rtype_qual`_'atype_code (rtype * const restrict retarray, { sstride[n] = array->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; } for (n = dim; n < rank; n++) { sstride[n] = array->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -71,12 +79,21 @@ name`'rtype_qual`_'atype_code (rtype * const restrict retarray, retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (rtype_name) - * retarray->dim[rank-1].stride - * extent[rank-1]); retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + alloc_size = sizeof (rtype_name) * retarray->dim[rank-1].stride + * extent[rank-1]; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); } else { @@ -187,6 +204,10 @@ void sstride[n] = array->dim[n].stride; mstride[n] = mask->dim[n].stride; extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound; + + if (extent[n] < 0) + extent[n] = 0; + } for (n = dim; n < rank; n++) { @@ -194,10 +215,15 @@ void mstride[n] = mask->dim[n + 1].stride; extent[n] = array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound; + + if (extent[n] < 0) + extent[n] = 0; } if (retarray->data == NULL) { + size_t alloc_size; + for (n = 0; n < rank; n++) { retarray->dim[n].lbound = 0; @@ -208,12 +234,22 @@ void retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1]; } - retarray->data - = internal_malloc_size (sizeof (rtype_name) - * retarray->dim[rank-1].stride - * extent[rank-1]); + alloc_size = sizeof (rtype_name) * retarray->dim[rank-1].stride + * extent[rank-1]; + retarray->offset = 0; retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; + + if (alloc_size == 0) + { + /* Make sure we have a zero-sized array. */ + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = -1; + return; + } + else + retarray->data = internal_malloc_size (alloc_size); + } else { |