2010-07-06 Tobias Burnus <burnus@net-b.de>
PR fortran/44742
* array.c (gfc_expand_constructor): Add optional diagnostic.
* gfortran.h (gfc_expand_constructor): Update prototype.
* expr.c (gfc_simplify_expr, check_init_expr,
gfc_reduce_init_expr): Update gfc_expand_constructor call.
* resolve.c (gfc_resolve_expr): Ditto.
2010-07-06 Tobias Burnus <burnus@net-b.de>
PR fortran/44742
* gfortran.dg/parameter_array_init_6.f90: New.
@@ -1545,7 +1545,7 @@ gfc_get_array_element (gfc_expr *array, int element)
constructor if they are small enough. */
gfc_try
-gfc_expand_constructor (gfc_expr *e)
+gfc_expand_constructor (gfc_expr *e, bool fatal)
{
expand_info expand_save;
gfc_expr *f;
@@ -1557,6 +1557,15 @@ gfc_expand_constructor (gfc_expr *e)
if (f != NULL)
{
gfc_free_expr (f);
+ if (fatal)
+ {
+ gfc_error ("The number of elements in the array constructor "
+ "at %L requires an increase of the allowed %d "
+ "upper limit. See -fmax-array-constructor "
+ "option", &e->where,
+ gfc_option.flag_max_array_constructor);
+ return FAILURE;
+ }
return SUCCESS;
}
@@ -1894,7 +1894,7 @@ gfc_simplify_expr (gfc_expr *p, int type)
if (p->expr_type == EXPR_ARRAY && p->ref && p->ref->type == REF_ARRAY
&& p->ref->u.ar.type == AR_FULL)
- gfc_expand_constructor (p);
+ gfc_expand_constructor (p, false);
if (simplify_const_ref (p) == FAILURE)
return FAILURE;
@@ -2573,7 +2573,7 @@ check_init_expr (gfc_expr *e)
if (t == FAILURE)
break;
- t = gfc_expand_constructor (e);
+ t = gfc_expand_constructor (e, true);
if (t == FAILURE)
break;
@@ -2609,7 +2609,7 @@ gfc_reduce_init_expr (gfc_expr *expr)
{
if (gfc_check_constructor_type (expr) == FAILURE)
return FAILURE;
- if (gfc_expand_constructor (expr) == FAILURE)
+ if (gfc_expand_constructor (expr, true) == FAILURE)
return FAILURE;
}
@@ -2715,7 +2715,7 @@ gfc_try gfc_resolve_array_spec (gfc_array_spec *, int);
int gfc_compare_array_spec (gfc_array_spec *, gfc_array_spec *);
void gfc_simplify_iterator_var (gfc_expr *);
-gfc_try gfc_expand_constructor (gfc_expr *);
+gfc_try gfc_expand_constructor (gfc_expr *, bool);
int gfc_constant_ac (gfc_expr *);
int gfc_expanded_ac (gfc_expr *);
gfc_try gfc_resolve_character_array_constructor (gfc_expr *);
@@ -5776,7 +5776,7 @@ gfc_resolve_expr (gfc_expr *e)
{
expression_rank (e);
if (gfc_is_constant_expr (e) || gfc_is_expandable_expr (e))
- gfc_expand_constructor (e);
+ gfc_expand_constructor (e, false);
}
/* This provides the opportunity for the length of constructors with
@@ -5786,7 +5786,7 @@ gfc_resolve_expr (gfc_expr *e)
{
/* For efficiency, we call gfc_expand_constructor for BT_CHARACTER
here rather then add a duplicate test for it above. */
- gfc_expand_constructor (e);
+ gfc_expand_constructor (e, false);
t = gfc_resolve_character_array_constructor (e);
}
@@ -0,0 +1,18 @@
+! { dg-do compile }
+!
+! PR fortran/44742
+!
+! Test case based on Juergen Reuter's and reduced by
+! Janus Weil.
+!
+! The program creates a large array constructor, which
+! exceeds -fmax-array-constructor - and caused an ICE.
+!
+
+module proc8
+ implicit none
+ integer, parameter :: N = 256
+ logical, dimension(N**2), parameter :: A = .false.
+ logical, dimension(N,N), parameter :: B &
+ = reshape ( (/ A /), (/ N, N /) ) ! { dg-error "array constructor at .1. requires an increase" }
+end module