https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106049
--- Comment #2 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #1)
> Maybe there is a better solution.
Here's an alternative, probably more general approach that modifies
is_constant_array_expr: when the array size - as implied by the shape -
is larger than zero, but the constructor is empty, then something went
wrong, and we return false:
diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index ab59fbca622..fb725994653 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -233,6 +233,18 @@ is_constant_array_expr (gfc_expr *e)
if (e->expr_type != EXPR_ARRAY || !gfc_is_constant_expr (e))
return false;
+ /* A non-zero-sized constant array shall have a non-empty constructor. */
+ if (e->rank > 0 && e->shape != NULL && e->value.constructor == NULL)
+ {
+ mpz_init_set_ui (size, 1);
+ for (int j = 0; j < e->rank; j++)
+ mpz_mul (size, size, e->shape[j]);
+ bool not_size0 = (mpz_cmp_si (size, 0) != 0);
+ mpz_clear (size);
+ if (not_size0)
+ return false;
+ }
+
for (c = gfc_constructor_first (e->value.constructor);
c; c = gfc_constructor_next (c))
if (c->expr->expr_type != EXPR_CONSTANT
This seems to regtest OK.