aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/simplify.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fortran/simplify.c')
-rw-r--r--gcc/fortran/simplify.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index dac48a8..23317a2 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -220,6 +220,8 @@ static bool
is_constant_array_expr (gfc_expr *e)
{
gfc_constructor *c;
+ bool array_OK = true;
+ mpz_t size;
if (e == NULL)
return true;
@@ -235,9 +237,39 @@ is_constant_array_expr (gfc_expr *e)
c; c = gfc_constructor_next (c))
if (c->expr->expr_type != EXPR_CONSTANT
&& c->expr->expr_type != EXPR_STRUCTURE)
+ {
+ array_OK = false;
+ break;
+ }
+
+ /* Check and expand the constructor. */
+ if (!array_OK && gfc_init_expr_flag && e->rank == 1)
+ {
+ array_OK = gfc_reduce_init_expr (e);
+ /* gfc_reduce_init_expr resets the flag. */
+ gfc_init_expr_flag = true;
+ }
+ else
+ return array_OK;
+
+ /* Recheck to make sure that any EXPR_ARRAYs have gone. */
+ for (c = gfc_constructor_first (e->value.constructor);
+ c; c = gfc_constructor_next (c))
+ if (c->expr->expr_type != EXPR_CONSTANT
+ && c->expr->expr_type != EXPR_STRUCTURE)
return false;
- return true;
+ /* Make sure that the array has a valid shape. */
+ if (e->shape == NULL && e->rank == 1)
+ {
+ if (!gfc_array_size(e, &size))
+ return false;
+ e->shape = gfc_get_shape (1);
+ mpz_init_set (e->shape[0], size);
+ mpz_clear (size);
+ }
+
+ return array_OK;
}
/* Test for a size zero array. */