diff options
author | Thomas Koenig <tkoenig@gcc.gnu.org> | 2018-03-11 20:28:00 +0000 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2018-03-11 20:28:00 +0000 |
commit | 6f76317a471e2960343ff94a60620fec76cdc35c (patch) | |
tree | 12fb00fb1d72af63187d841668ec88eab41d869e /gcc/fortran/simplify.c | |
parent | cd5437ab5d98cf95cc6686a533b7d3582bcb1706 (diff) | |
download | gcc-6f76317a471e2960343ff94a60620fec76cdc35c.zip gcc-6f76317a471e2960343ff94a60620fec76cdc35c.tar.gz gcc-6f76317a471e2960343ff94a60620fec76cdc35c.tar.bz2 |
re PR fortran/66128 (ICE for some intrinsics with zero sized array parameter)
2018-03-11 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/66128
* simplify.c (simplify_transformation): Return default result for
empty array argument.
(gfc_simplify_all): Remove special-case handling for zerosize.
(gfc_simplify_any): Likewise.
(gfc_simplify_count): Likewise.
(gfc_simplify_iall): Likewise.
(gfc_simplify_iany): Likewise.
(gfc_simplify_iparity): Likewise.
(gfc_simplify_minval): Likewise.
(gfc_simplify_maxval): Likewise.
(gfc_simplify_norm2): Likewise.
(gfc_simplify_product): Likewise.
(gfc_simplify_sum): Likewise.
2018-03-11 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/66128
* gfortran.dg/zero_sized_9.f90: New test.
From-SVN: r258435
Diffstat (limited to 'gcc/fortran/simplify.c')
-rw-r--r-- | gcc/fortran/simplify.c | 177 |
1 files changed, 19 insertions, 158 deletions
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index dd46933..680e625 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -689,8 +689,11 @@ simplify_transformation (gfc_expr *array, gfc_expr *dim, gfc_expr *mask, int init_val, transformational_op op) { gfc_expr *result; + bool size_zero; - if (!is_constant_array_expr (array) + size_zero = gfc_is_size_zero_array (array); + + if (!(is_constant_array_expr (array) || size_zero) || !gfc_is_constant_expr (dim)) return NULL; @@ -703,6 +706,9 @@ simplify_transformation (gfc_expr *array, gfc_expr *dim, gfc_expr *mask, array->ts.kind, &array->where); init_result_expr (result, init_val, array); + if (size_zero) + return result; + return !dim || array->rank == 1 ? simplify_transformation_to_scalar (result, array, mask, op) : simplify_transformation_to_array (result, array, dim, mask, op, NULL); @@ -976,9 +982,6 @@ gfc_simplify_aint (gfc_expr *e, gfc_expr *k) gfc_expr * gfc_simplify_all (gfc_expr *mask, gfc_expr *dim) { - if (gfc_is_size_zero_array (mask)) - return gfc_get_logical_expr (mask->ts.kind, &mask->where, true); - return simplify_transformation (mask, dim, NULL, true, gfc_and); } @@ -1068,9 +1071,6 @@ gfc_simplify_and (gfc_expr *x, gfc_expr *y) gfc_expr * gfc_simplify_any (gfc_expr *mask, gfc_expr *dim) { - if (gfc_is_size_zero_array (mask)) - return gfc_get_logical_expr (mask->ts.kind, &mask->where, false); - return simplify_transformation (mask, dim, NULL, false, gfc_or); } @@ -1966,15 +1966,11 @@ gfc_expr * gfc_simplify_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind) { gfc_expr *result; + bool size_zero; - if (gfc_is_size_zero_array (mask)) - { - int k; - k = kind ? mpz_get_si (kind->value.integer) : gfc_default_integer_kind; - return gfc_get_int_expr (k, NULL, 0); - } + size_zero = gfc_is_size_zero_array (mask); - if (!is_constant_array_expr (mask) + if (!(is_constant_array_expr (mask) || size_zero) || !gfc_is_constant_expr (dim) || !gfc_is_constant_expr (kind)) return NULL; @@ -1987,6 +1983,9 @@ gfc_simplify_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind) init_result_expr (result, 0, NULL); + if (size_zero) + return result; + /* Passing MASK twice, once as data array, once as mask. Whenever gfc_count is called, '1' is added to the result. */ return !dim || mask->rank == 1 ? @@ -3265,9 +3264,6 @@ do_bit_and (gfc_expr *result, gfc_expr *e) gfc_expr * gfc_simplify_iall (gfc_expr *array, gfc_expr *dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - return gfc_get_int_expr (array->ts.kind, NULL, -1); - return simplify_transformation (array, dim, mask, -1, do_bit_and); } @@ -3287,9 +3283,6 @@ do_bit_ior (gfc_expr *result, gfc_expr *e) gfc_expr * gfc_simplify_iany (gfc_expr *array, gfc_expr *dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - return gfc_get_int_expr (array->ts.kind, NULL, 0); - return simplify_transformation (array, dim, mask, 0, do_bit_ior); } @@ -3730,9 +3723,6 @@ do_bit_xor (gfc_expr *result, gfc_expr *e) gfc_expr * gfc_simplify_iparity (gfc_expr *array, gfc_expr *dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - return gfc_get_int_expr (array->ts.kind, NULL, 0); - return simplify_transformation (array, dim, mask, 0, do_bit_xor); } @@ -5040,43 +5030,6 @@ gfc_min (gfc_expr *op1, gfc_expr *op2) gfc_expr * gfc_simplify_minval (gfc_expr *array, gfc_expr* dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - { - gfc_expr *result; - int i; - - i = gfc_validate_kind (array->ts.type, array->ts.kind, false); - result = gfc_get_constant_expr (array->ts.type, array->ts.kind, - &array->where); - switch (array->ts.type) - { - case BT_INTEGER: - mpz_set (result->value.integer, gfc_integer_kinds[i].huge); - break; - - case BT_REAL: - mpfr_set (result->value.real, gfc_real_kinds[i].huge, GFC_RND_MODE); - break; - - case BT_CHARACTER: - /* If ARRAY has size zero and type character, the result has the - value of a string of characters of length LEN (ARRAY), with - each character equal to CHAR(n - 1, KIND (ARRAY)), where n is - the number of characters in the collating sequence for - characters with the kind type parameter of ARRAY. */ - gfc_error ("MINVAL(string) at %L is not implemented, yet!", - &array->where); - gfc_free_expr (result); - return &gfc_bad_expr; - break; - - default: - gcc_unreachable (); - } - - return result; - } - return simplify_transformation (array, dim, mask, INT_MAX, gfc_min); } @@ -5096,42 +5049,6 @@ gfc_max (gfc_expr *op1, gfc_expr *op2) gfc_expr * gfc_simplify_maxval (gfc_expr *array, gfc_expr* dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - { - gfc_expr *result; - int i; - - i = gfc_validate_kind (array->ts.type, array->ts.kind, false); - result = gfc_get_constant_expr (array->ts.type, array->ts.kind, - &array->where); - switch (array->ts.type) - { - case BT_INTEGER: - mpz_set (result->value.integer, gfc_integer_kinds[i].min_int); - break; - - case BT_REAL: - mpfr_set (result->value.real, gfc_real_kinds[i].huge, GFC_RND_MODE); - mpfr_neg (result->value.real, result->value.real, GFC_RND_MODE); - break; - - case BT_CHARACTER: - /* If ARRAY has size zero and type character, the result has the - value of a string of characters of length LEN (ARRAY), with - each character equal to CHAR (0, KIND (ARRAY)). */ - gfc_error ("MAXVAL(string) at %L is not implemented, yet!", - &array->where); - gfc_free_expr (result); - return &gfc_bad_expr; - break; - - default: - gcc_unreachable (); - } - - return result; - } - return simplify_transformation (array, dim, mask, INT_MIN, gfc_max); } @@ -5777,22 +5694,20 @@ gfc_expr * gfc_simplify_norm2 (gfc_expr *e, gfc_expr *dim) { gfc_expr *result; + bool size_zero; - if (gfc_is_size_zero_array (e)) - { - gfc_expr *result; - result = gfc_get_constant_expr (e->ts.type, e->ts.kind, &e->where); - mpfr_set_ui (result->value.real, 0, GFC_RND_MODE); - return result; - } + size_zero = gfc_is_size_zero_array (e); - if (!is_constant_array_expr (e) + if (!(is_constant_array_expr (e) || size_zero) || (dim != NULL && !gfc_is_constant_expr (dim))) return NULL; result = transformational_result (e, dim, e->ts.type, e->ts.kind, &e->where); init_result_expr (result, 0, NULL); + if (size_zero) + return result; + if (!dim || e->rank == 1) { result = simplify_transformation_to_scalar (result, e, NULL, @@ -6042,33 +5957,6 @@ gfc_simplify_precision (gfc_expr *e) gfc_expr * gfc_simplify_product (gfc_expr *array, gfc_expr *dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - { - gfc_expr *result; - - result = gfc_get_constant_expr (array->ts.type, array->ts.kind, - &array->where); - switch (array->ts.type) - { - case BT_INTEGER: - mpz_set_ui (result->value.integer, 1); - break; - - case BT_REAL: - mpfr_set_ui (result->value.real, 1, GFC_RND_MODE); - break; - - case BT_COMPLEX: - mpc_set_ui (result->value.complex, 1, GFC_MPC_RND_MODE); - break; - - default: - gcc_unreachable (); - } - - return result; - } - return simplify_transformation (array, dim, mask, 1, gfc_multiply); } @@ -7386,33 +7274,6 @@ gfc_simplify_sqrt (gfc_expr *e) gfc_expr * gfc_simplify_sum (gfc_expr *array, gfc_expr *dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - { - gfc_expr *result; - - result = gfc_get_constant_expr (array->ts.type, array->ts.kind, - &array->where); - switch (array->ts.type) - { - case BT_INTEGER: - mpz_set_ui (result->value.integer, 0); - break; - - case BT_REAL: - mpfr_set_ui (result->value.real, 0, GFC_RND_MODE); - break; - - case BT_COMPLEX: - mpc_set_ui (result->value.complex, 0, GFC_MPC_RND_MODE); - break; - - default: - gcc_unreachable (); - } - - return result; - } - return simplify_transformation (array, dim, mask, 0, gfc_add); } |