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;
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);
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);
}
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);
}
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;
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 ?
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);
}
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);
}
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);
}
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);
}
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);
}
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,
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);
}
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);
}
--- /dev/null
+! { dg-do run }
+program main
+ implicit none
+ integer, parameter :: a(0,3) = 0
+ integer, parameter :: b(3,0) = -42
+ integer, parameter, dimension(3) :: a1 = minval(a,dim=1)
+ integer, parameter, dimension(0) :: a2 = minval(a,dim=2)
+ integer, parameter, dimension(0) :: b1 = minval(b,dim=1)
+ integer, parameter, dimension(3) :: b2 = minval(b,dim=2)
+ logical, parameter :: c(0,3) = .false.
+ logical, parameter :: d(3,0) = .false.
+ logical, parameter, dimension(3) :: tr = all(c,dim=1)
+ logical, parameter, dimension(3) :: fa = any(c,dim=1)
+ integer, parameter, dimension(3) :: ze = count(d,dim=2)
+ integer, parameter, dimension(3) :: ze2 = iany(b,dim=2)
+ integer, parameter, dimension(3) :: ze3 = iparity(a,dim=1)
+ real, parameter, dimension(0,3) :: r = 1.0
+ real, parameter, dimension(3) :: n2 = norm2(r,dim=1)
+ integer, parameter, dimension(3) :: one = product(b,dim=2)
+ integer, parameter, dimension(3) :: ze4 = sum(a,dim=1)
+ if (any(a1 /= huge(0))) stop 1
+ if (any(b2 /= huge(b2))) stop 2
+ if (any(.not.tr)) stop 3
+ if (any(fa)) stop 3
+ if (any(ze /= 0)) stop 4
+ if (any(ze2 /= 0)) stop 5
+ if (any(ze3 /= 0)) stop 6
+ if (any(n2 /= 0.0)) stop 7
+ if (any(one /= 1)) stop 8
+ if (any(ze4 /= 0)) stop 9
+end program main