diff options
author | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-07-05 18:16:17 +0000 |
---|---|---|
committer | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-07-05 18:16:17 +0000 |
commit | 0248e4c1015d8dc69c0638b1b785958e703e2d0c (patch) | |
tree | 39e9a0538999ccc19813d9e4c1132c8912803e5a /libgfortran | |
parent | f1bd80958b3cdb8ac354e00a6f9bd3b9773da788 (diff) | |
download | gcc-0248e4c1015d8dc69c0638b1b785958e703e2d0c.tar.gz |
2011-07-05 Thomas Koenig <tkoenig@gcc.gnu.org>
* runtime/memory.c (internal_malloc_size): If size is zero,
allocate a single byte.
* m4/pack.m4 (pack_'rtype_code`): Don't check for zero size
for the argument of internal_malloc_size.
* m4/spread.m4 (spread_'rtype_code`): Likewise.
* m4/eoshift1.m4 (eoshift1): Don't allocate twice. Don't check
for zero size for the argument of internal_malloc_size.
* m4/eoshift3.m4: Don't check for zero size for the argument of
internal_malloc_size.
* intrinsics/pack_generic.c (pack_internal): Likewise.
(pack_s_internal): Likewise.
* intrinsics/cshift0.c (cshift0): Likewise.
* intrinsics/spread_generic.c (spread_internal): Likewise.
* intrinsics/eoshift0.c (eoshift0): Likewise.
* intrinsics/eoshift2.c (eoshift2): Likewise.
* generated/eoshift1_16.c: Regenerated.
* generated/eoshift1_4.c: Regenerated.
* generated/eoshift1_8.c: Regenerated.
* generated/eoshift3_16.c: Regenerated.
* generated/eoshift3_4.c: Regenerated.
* generated/eoshift3_8.c: Regenerated.
* generated/pack_c10.c: Regenerated.
* generated/pack_c16.c: Regenerated.
* generated/pack_c4.c: Regenerated.
* generated/pack_c8.c: Regenerated.
* generated/pack_i16.c: Regenerated.
* generated/pack_i1.c: Regenerated.
* generated/pack_i2.c: Regenerated.
* generated/pack_i4.c: Regenerated.
* generated/pack_i8.c: Regenerated.
* generated/pack_r10.c: Regenerated.
* generated/pack_r16.c: Regenerated.
* generated/pack_r4.c: Regenerated.
* generated/pack_r8.c: Regenerated.
* generated/spread_c10.c: Regenerated.
* generated/spread_c16.c: Regenerated.
* generated/spread_c4.c: Regenerated.
* generated/spread_c8.c: Regenerated.
* generated/spread_i16.c: Regenerated.
* generated/spread_i1.c: Regenerated.
* generated/spread_i2.c: Regenerated.
* generated/spread_i4.c: Regenerated.
* generated/spread_i8.c: Regenerated.
* generated/spread_r10.c: Regenerated.
* generated/spread_r16.c: Regenerated.
* generated/spread_r4.c: Regenerated.
* generated/spread_r8.c: Regenerated.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@175880 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
43 files changed, 225 insertions, 267 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 88ee3638d17..442c032f477 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,53 @@ +2011-07-05 Thomas Koenig <tkoenig@gcc.gnu.org> + + * runtime/memory.c (internal_malloc_size): If size is zero, + allocate a single byte. + * m4/pack.m4 (pack_'rtype_code`): Don't check for zero size + for the argument of internal_malloc_size. + * m4/spread.m4 (spread_'rtype_code`): Likewise. + * m4/eoshift1.m4 (eoshift1): Don't allocate twice. Don't check + for zero size for the argument of internal_malloc_size. + * m4/eoshift3.m4: Don't check for zero size for the argument of + internal_malloc_size. + * intrinsics/pack_generic.c (pack_internal): Likewise. + (pack_s_internal): Likewise. + * intrinsics/cshift0.c (cshift0): Likewise. + * intrinsics/spread_generic.c (spread_internal): Likewise. + * intrinsics/eoshift0.c (eoshift0): Likewise. + * intrinsics/eoshift2.c (eoshift2): Likewise. + * generated/eoshift1_16.c: Regenerated. + * generated/eoshift1_4.c: Regenerated. + * generated/eoshift1_8.c: Regenerated. + * generated/eoshift3_16.c: Regenerated. + * generated/eoshift3_4.c: Regenerated. + * generated/eoshift3_8.c: Regenerated. + * generated/pack_c10.c: Regenerated. + * generated/pack_c16.c: Regenerated. + * generated/pack_c4.c: Regenerated. + * generated/pack_c8.c: Regenerated. + * generated/pack_i16.c: Regenerated. + * generated/pack_i1.c: Regenerated. + * generated/pack_i2.c: Regenerated. + * generated/pack_i4.c: Regenerated. + * generated/pack_i8.c: Regenerated. + * generated/pack_r10.c: Regenerated. + * generated/pack_r16.c: Regenerated. + * generated/pack_r4.c: Regenerated. + * generated/pack_r8.c: Regenerated. + * generated/spread_c10.c: Regenerated. + * generated/spread_c16.c: Regenerated. + * generated/spread_c4.c: Regenerated. + * generated/spread_c8.c: Regenerated. + * generated/spread_i16.c: Regenerated. + * generated/spread_i1.c: Regenerated. + * generated/spread_i2.c: Regenerated. + * generated/spread_i4.c: Regenerated. + * generated/spread_i8.c: Regenerated. + * generated/spread_r10.c: Regenerated. + * generated/spread_r16.c: Regenerated. + * generated/spread_r4.c: Regenerated. + * generated/spread_r8.c: Regenerated. + 2011-06-28 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/49479 diff --git a/libgfortran/generated/eoshift1_16.c b/libgfortran/generated/eoshift1_16.c index a14bd292715..eb3a27a1c64 100644 --- a/libgfortran/generated/eoshift1_16.c +++ b/libgfortran/generated/eoshift1_16.c @@ -88,7 +88,6 @@ eoshift1 (gfc_array_char * const restrict ret, { int i; - ret->data = internal_malloc_size (size * arraysize); ret->offset = 0; ret->dtype = array->dtype; for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) @@ -106,10 +105,8 @@ eoshift1 (gfc_array_char * const restrict ret, GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); } - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * arraysize); } else if (unlikely (compile_options.bounds_check)) diff --git a/libgfortran/generated/eoshift1_4.c b/libgfortran/generated/eoshift1_4.c index 06bc309c4a8..d3776b911b0 100644 --- a/libgfortran/generated/eoshift1_4.c +++ b/libgfortran/generated/eoshift1_4.c @@ -88,7 +88,6 @@ eoshift1 (gfc_array_char * const restrict ret, { int i; - ret->data = internal_malloc_size (size * arraysize); ret->offset = 0; ret->dtype = array->dtype; for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) @@ -106,10 +105,8 @@ eoshift1 (gfc_array_char * const restrict ret, GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); } - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * arraysize); } else if (unlikely (compile_options.bounds_check)) diff --git a/libgfortran/generated/eoshift1_8.c b/libgfortran/generated/eoshift1_8.c index 3e9162d0f08..5f026acdfcb 100644 --- a/libgfortran/generated/eoshift1_8.c +++ b/libgfortran/generated/eoshift1_8.c @@ -88,7 +88,6 @@ eoshift1 (gfc_array_char * const restrict ret, { int i; - ret->data = internal_malloc_size (size * arraysize); ret->offset = 0; ret->dtype = array->dtype; for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) @@ -106,10 +105,8 @@ eoshift1 (gfc_array_char * const restrict ret, GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); } - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * arraysize); } else if (unlikely (compile_options.bounds_check)) diff --git a/libgfortran/generated/eoshift3_16.c b/libgfortran/generated/eoshift3_16.c index ec21d1ec14d..1cf216767ac 100644 --- a/libgfortran/generated/eoshift3_16.c +++ b/libgfortran/generated/eoshift3_16.c @@ -107,10 +107,8 @@ eoshift3 (gfc_array_char * const restrict ret, GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); } - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * arraysize); } else if (unlikely (compile_options.bounds_check)) diff --git a/libgfortran/generated/eoshift3_4.c b/libgfortran/generated/eoshift3_4.c index ce4cede1f1d..c6033d0a58a 100644 --- a/libgfortran/generated/eoshift3_4.c +++ b/libgfortran/generated/eoshift3_4.c @@ -107,10 +107,8 @@ eoshift3 (gfc_array_char * const restrict ret, GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); } - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * arraysize); } else if (unlikely (compile_options.bounds_check)) diff --git a/libgfortran/generated/eoshift3_8.c b/libgfortran/generated/eoshift3_8.c index 4af36f72bb4..7a7b196eec4 100644 --- a/libgfortran/generated/eoshift3_8.c +++ b/libgfortran/generated/eoshift3_8.c @@ -107,10 +107,8 @@ eoshift3 (gfc_array_char * const restrict ret, GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); } - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * arraysize); } else if (unlikely (compile_options.bounds_check)) diff --git a/libgfortran/generated/pack_c10.c b/libgfortran/generated/pack_c10.c index cc66c538e1c..621ba8d8b79 100644 --- a/libgfortran/generated/pack_c10.c +++ b/libgfortran/generated/pack_c10.c @@ -166,14 +166,12 @@ pack_c10 (gfc_array_c10 *ret, const gfc_array_c10 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_COMPLEX_10) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_COMPLEX_10) * total); + return; } else { diff --git a/libgfortran/generated/pack_c16.c b/libgfortran/generated/pack_c16.c index 9397262dd06..e98de98c91c 100644 --- a/libgfortran/generated/pack_c16.c +++ b/libgfortran/generated/pack_c16.c @@ -166,14 +166,12 @@ pack_c16 (gfc_array_c16 *ret, const gfc_array_c16 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_COMPLEX_16) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_COMPLEX_16) * total); + return; } else { diff --git a/libgfortran/generated/pack_c4.c b/libgfortran/generated/pack_c4.c index 093bdcc9a1d..85e15417851 100644 --- a/libgfortran/generated/pack_c4.c +++ b/libgfortran/generated/pack_c4.c @@ -166,14 +166,12 @@ pack_c4 (gfc_array_c4 *ret, const gfc_array_c4 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_COMPLEX_4) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_COMPLEX_4) * total); + return; } else { diff --git a/libgfortran/generated/pack_c8.c b/libgfortran/generated/pack_c8.c index 7971e2ba135..bfaec2fc910 100644 --- a/libgfortran/generated/pack_c8.c +++ b/libgfortran/generated/pack_c8.c @@ -166,14 +166,12 @@ pack_c8 (gfc_array_c8 *ret, const gfc_array_c8 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_COMPLEX_8) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_COMPLEX_8) * total); + return; } else { diff --git a/libgfortran/generated/pack_i1.c b/libgfortran/generated/pack_i1.c index 3e4647dbd55..c168affaea0 100644 --- a/libgfortran/generated/pack_i1.c +++ b/libgfortran/generated/pack_i1.c @@ -166,14 +166,12 @@ pack_i1 (gfc_array_i1 *ret, const gfc_array_i1 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_INTEGER_1) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_INTEGER_1) * total); + return; } else { diff --git a/libgfortran/generated/pack_i16.c b/libgfortran/generated/pack_i16.c index 99d3491c38f..81ed49a8208 100644 --- a/libgfortran/generated/pack_i16.c +++ b/libgfortran/generated/pack_i16.c @@ -166,14 +166,12 @@ pack_i16 (gfc_array_i16 *ret, const gfc_array_i16 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * total); + return; } else { diff --git a/libgfortran/generated/pack_i2.c b/libgfortran/generated/pack_i2.c index e796d169f76..a04b7af6969 100644 --- a/libgfortran/generated/pack_i2.c +++ b/libgfortran/generated/pack_i2.c @@ -166,14 +166,12 @@ pack_i2 (gfc_array_i2 *ret, const gfc_array_i2 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_INTEGER_2) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_INTEGER_2) * total); + return; } else { diff --git a/libgfortran/generated/pack_i4.c b/libgfortran/generated/pack_i4.c index 91ce99fe4fd..c5d112bd394 100644 --- a/libgfortran/generated/pack_i4.c +++ b/libgfortran/generated/pack_i4.c @@ -166,14 +166,12 @@ pack_i4 (gfc_array_i4 *ret, const gfc_array_i4 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * total); + return; } else { diff --git a/libgfortran/generated/pack_i8.c b/libgfortran/generated/pack_i8.c index e49d8c29e95..7307192749b 100644 --- a/libgfortran/generated/pack_i8.c +++ b/libgfortran/generated/pack_i8.c @@ -166,14 +166,12 @@ pack_i8 (gfc_array_i8 *ret, const gfc_array_i8 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * total); + return; } else { diff --git a/libgfortran/generated/pack_r10.c b/libgfortran/generated/pack_r10.c index f70c932640e..c3b55cc1a9f 100644 --- a/libgfortran/generated/pack_r10.c +++ b/libgfortran/generated/pack_r10.c @@ -166,14 +166,12 @@ pack_r10 (gfc_array_r10 *ret, const gfc_array_r10 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_REAL_10) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_REAL_10) * total); + return; } else { diff --git a/libgfortran/generated/pack_r16.c b/libgfortran/generated/pack_r16.c index ff2ad6e7eed..489ff957aa1 100644 --- a/libgfortran/generated/pack_r16.c +++ b/libgfortran/generated/pack_r16.c @@ -166,14 +166,12 @@ pack_r16 (gfc_array_r16 *ret, const gfc_array_r16 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_REAL_16) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_REAL_16) * total); + return; } else { diff --git a/libgfortran/generated/pack_r4.c b/libgfortran/generated/pack_r4.c index 0c08b8c8c94..05172dbbb06 100644 --- a/libgfortran/generated/pack_r4.c +++ b/libgfortran/generated/pack_r4.c @@ -166,14 +166,12 @@ pack_r4 (gfc_array_r4 *ret, const gfc_array_r4 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_REAL_4) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_REAL_4) * total); + return; } else { diff --git a/libgfortran/generated/pack_r8.c b/libgfortran/generated/pack_r8.c index 2b307e29a2b..df5cc3f3a6e 100644 --- a/libgfortran/generated/pack_r8.c +++ b/libgfortran/generated/pack_r8.c @@ -166,14 +166,12 @@ pack_r8 (gfc_array_r8 *ret, const gfc_array_r8 *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof (GFC_REAL_8) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof (GFC_REAL_8) * total); + return; } else { diff --git a/libgfortran/generated/spread_c10.c b/libgfortran/generated/spread_c10.c index 77a838f01a4..d8a5bafe235 100644 --- a/libgfortran/generated/spread_c10.c +++ b/libgfortran/generated/spread_c10.c @@ -100,13 +100,11 @@ spread_c10 (gfc_array_c10 *ret, const gfc_array_c10 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_COMPLEX_10)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_COMPLEX_10)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_c16.c b/libgfortran/generated/spread_c16.c index 1276e4dfb44..0bfba7f4145 100644 --- a/libgfortran/generated/spread_c16.c +++ b/libgfortran/generated/spread_c16.c @@ -100,13 +100,11 @@ spread_c16 (gfc_array_c16 *ret, const gfc_array_c16 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_COMPLEX_16)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_COMPLEX_16)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_c4.c b/libgfortran/generated/spread_c4.c index 5224e8477a9..e1a475f6f12 100644 --- a/libgfortran/generated/spread_c4.c +++ b/libgfortran/generated/spread_c4.c @@ -100,13 +100,11 @@ spread_c4 (gfc_array_c4 *ret, const gfc_array_c4 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_COMPLEX_4)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_COMPLEX_4)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_c8.c b/libgfortran/generated/spread_c8.c index 96ecb3afb87..a2902908e76 100644 --- a/libgfortran/generated/spread_c8.c +++ b/libgfortran/generated/spread_c8.c @@ -100,13 +100,11 @@ spread_c8 (gfc_array_c8 *ret, const gfc_array_c8 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_COMPLEX_8)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_COMPLEX_8)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_i1.c b/libgfortran/generated/spread_i1.c index e002c146262..111c4ccea5f 100644 --- a/libgfortran/generated/spread_i1.c +++ b/libgfortran/generated/spread_i1.c @@ -100,13 +100,11 @@ spread_i1 (gfc_array_i1 *ret, const gfc_array_i1 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_INTEGER_1)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_INTEGER_1)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_i16.c b/libgfortran/generated/spread_i16.c index bdefdac3271..2a4864ba41c 100644 --- a/libgfortran/generated/spread_i16.c +++ b/libgfortran/generated/spread_i16.c @@ -100,13 +100,11 @@ spread_i16 (gfc_array_i16 *ret, const gfc_array_i16 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_INTEGER_16)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_INTEGER_16)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_i2.c b/libgfortran/generated/spread_i2.c index 8482cfde857..5a5d87064e6 100644 --- a/libgfortran/generated/spread_i2.c +++ b/libgfortran/generated/spread_i2.c @@ -100,13 +100,11 @@ spread_i2 (gfc_array_i2 *ret, const gfc_array_i2 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_INTEGER_2)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_INTEGER_2)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_i4.c b/libgfortran/generated/spread_i4.c index 6eff6326b26..e990408b0a4 100644 --- a/libgfortran/generated/spread_i4.c +++ b/libgfortran/generated/spread_i4.c @@ -100,13 +100,11 @@ spread_i4 (gfc_array_i4 *ret, const gfc_array_i4 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_INTEGER_4)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_INTEGER_4)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_i8.c b/libgfortran/generated/spread_i8.c index 29312636306..1e3b3055b8f 100644 --- a/libgfortran/generated/spread_i8.c +++ b/libgfortran/generated/spread_i8.c @@ -100,13 +100,11 @@ spread_i8 (gfc_array_i8 *ret, const gfc_array_i8 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_INTEGER_8)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_INTEGER_8)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_r10.c b/libgfortran/generated/spread_r10.c index 3c3f197b4c2..ef86bc59007 100644 --- a/libgfortran/generated/spread_r10.c +++ b/libgfortran/generated/spread_r10.c @@ -100,13 +100,11 @@ spread_r10 (gfc_array_r10 *ret, const gfc_array_r10 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_REAL_10)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_REAL_10)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_r16.c b/libgfortran/generated/spread_r16.c index 13162609696..9678e8768a0 100644 --- a/libgfortran/generated/spread_r16.c +++ b/libgfortran/generated/spread_r16.c @@ -100,13 +100,11 @@ spread_r16 (gfc_array_r16 *ret, const gfc_array_r16 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_REAL_16)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_REAL_16)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_r4.c b/libgfortran/generated/spread_r4.c index cc0f1197b69..fac0900cbb4 100644 --- a/libgfortran/generated/spread_r4.c +++ b/libgfortran/generated/spread_r4.c @@ -100,13 +100,11 @@ spread_r4 (gfc_array_r4 *ret, const gfc_array_r4 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_REAL_4)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_REAL_4)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/generated/spread_r8.c b/libgfortran/generated/spread_r8.c index f38ef3885fc..0dd9e7bf5ad 100644 --- a/libgfortran/generated/spread_r8.c +++ b/libgfortran/generated/spread_r8.c @@ -100,13 +100,11 @@ spread_r8 (gfc_array_r8 *ret, const gfc_array_r8 *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof(GFC_REAL_8)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof(GFC_REAL_8)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/intrinsics/cshift0.c b/libgfortran/intrinsics/cshift0.c index 00a50d5db7c..026dd1adc0d 100644 --- a/libgfortran/intrinsics/cshift0.c +++ b/libgfortran/intrinsics/cshift0.c @@ -79,10 +79,8 @@ cshift0 (gfc_array_char * ret, const gfc_array_char * array, GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); } - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * arraysize); } else if (unlikely (compile_options.bounds_check)) { diff --git a/libgfortran/intrinsics/eoshift0.c b/libgfortran/intrinsics/eoshift0.c index 74ba5ab7a97..6ceed2000e0 100644 --- a/libgfortran/intrinsics/eoshift0.c +++ b/libgfortran/intrinsics/eoshift0.c @@ -86,11 +86,8 @@ eoshift0 (gfc_array_char * ret, const gfc_array_char * array, } - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); - + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * arraysize); } else if (unlikely (compile_options.bounds_check)) { diff --git a/libgfortran/intrinsics/eoshift2.c b/libgfortran/intrinsics/eoshift2.c index 2fbf62e118c..b4f82786964 100644 --- a/libgfortran/intrinsics/eoshift2.c +++ b/libgfortran/intrinsics/eoshift2.c @@ -91,10 +91,8 @@ eoshift2 (gfc_array_char *ret, const gfc_array_char *array, GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * arraysize); } } diff --git a/libgfortran/intrinsics/pack_generic.c b/libgfortran/intrinsics/pack_generic.c index c15bdd08f41..de1e07facab 100644 --- a/libgfortran/intrinsics/pack_generic.c +++ b/libgfortran/intrinsics/pack_generic.c @@ -153,14 +153,11 @@ pack_internal (gfc_array_char *ret, const gfc_array_char *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (size * total); + return; /* In this case, nothing remains to be done. */ } else { @@ -523,13 +520,10 @@ pack_s_internal (gfc_array_char *ret, const gfc_array_char *array, ret->offset = 0; + ret->data = internal_malloc_size (size * total); + if (total == 0) - { - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (size * total); + return; } rstride0 = GFC_DESCRIPTOR_STRIDE_BYTES(ret,0); diff --git a/libgfortran/intrinsics/spread_generic.c b/libgfortran/intrinsics/spread_generic.c index 29671ce4c86..2eeb24b8444 100644 --- a/libgfortran/intrinsics/spread_generic.c +++ b/libgfortran/intrinsics/spread_generic.c @@ -100,13 +100,10 @@ spread_internal (gfc_array_char *ret, const gfc_array_char *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * size); - else - { - ret->data = internal_malloc_size (1); - return; - } + ret->data = internal_malloc_size (rs * size); + + if (rs <= 0) + return; } else { diff --git a/libgfortran/m4/eoshift1.m4 b/libgfortran/m4/eoshift1.m4 index be9b1008a60..339e1d89965 100644 --- a/libgfortran/m4/eoshift1.m4 +++ b/libgfortran/m4/eoshift1.m4 @@ -89,7 +89,6 @@ eoshift1 (gfc_array_char * const restrict ret, { int i; - ret->data = internal_malloc_size (size * arraysize); ret->offset = 0; ret->dtype = array->dtype; for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) @@ -107,10 +106,8 @@ eoshift1 (gfc_array_char * const restrict ret, GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); } - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * arraysize); } else if (unlikely (compile_options.bounds_check)) diff --git a/libgfortran/m4/eoshift3.m4 b/libgfortran/m4/eoshift3.m4 index 6fa3bd2f7dc..1c19575ffb8 100644 --- a/libgfortran/m4/eoshift3.m4 +++ b/libgfortran/m4/eoshift3.m4 @@ -108,10 +108,8 @@ eoshift3 (gfc_array_char * const restrict ret, GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); } - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (size * arraysize); } else if (unlikely (compile_options.bounds_check)) diff --git a/libgfortran/m4/pack.m4 b/libgfortran/m4/pack.m4 index c5fd2fd817d..e1882d077c2 100644 --- a/libgfortran/m4/pack.m4 +++ b/libgfortran/m4/pack.m4 @@ -167,14 +167,12 @@ pack_'rtype_code` ('rtype` *ret, const 'rtype` *array, GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1); ret->offset = 0; + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (sizeof ('rtype_name`) * total); + if (total == 0) - { - /* In this case, nothing remains to be done. */ - ret->data = internal_malloc_size (1); - return; - } - else - ret->data = internal_malloc_size (sizeof ('rtype_name`) * total); + return; } else { diff --git a/libgfortran/m4/spread.m4 b/libgfortran/m4/spread.m4 index 5e73d97423a..89a2e65297c 100644 --- a/libgfortran/m4/spread.m4 +++ b/libgfortran/m4/spread.m4 @@ -101,13 +101,11 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source, GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride); } ret->offset = 0; - if (rs > 0) - ret->data = internal_malloc_size (rs * sizeof('rtype_name`)); - else - { - ret->data = internal_malloc_size (1); - return; - } + + /* internal_malloc_size allocates a single byte for zero size. */ + ret->data = internal_malloc_size (rs * sizeof('rtype_name`)); + if (rs <= 0) + return; } else { diff --git a/libgfortran/runtime/memory.c b/libgfortran/runtime/memory.c index 5f710849e52..a26d9e59efa 100644 --- a/libgfortran/runtime/memory.c +++ b/libgfortran/runtime/memory.c @@ -54,8 +54,8 @@ get_mem (size_t n) void * internal_malloc_size (size_t size) { - if (size == 0) - return NULL; + if (unlikely (size == 0)) + size = 1; return get_mem (size); } |