From 9231aa17d6498905234d8e35216b324a1b067c8c Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Wed, 18 Nov 2015 22:51:39 +0000 Subject: [PATCH] re PR fortran/43996 (ICE in gfc_conv_array_initializer due to incomplete simplification of init expressions) 2015-11-18 Steven G. Kargl PR fortran/43996 * simplify.c (gfc_simplify_spread): Issue error for too large array constructor in a PARAMETER statement. 2015-11-18 Steven G. Kargl PR fortran/43996 * gfortran.dg/pr43996.f90: New test. From-SVN: r230579 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/simplify.c | 20 ++++++++++++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr43996.f90 | 7 +++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr43996.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 34bc058c3ee..5e10387b8a0 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2015-11-18 Steven G. Kargl + + PR fortran/43996 + * simplify.c (gfc_simplify_spread): Issue error for too large array + constructor in a PARAMETER statement. + 2015-11-17 Steven G. Kargl * primary.c (gfc_match_structure_constructor): Fix whitespace. diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 9b58b994d52..4df3fe6c5b5 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -5991,8 +5991,8 @@ gfc_simplify_spacing (gfc_expr *x) gfc_expr * gfc_simplify_spread (gfc_expr *source, gfc_expr *dim_expr, gfc_expr *ncopies_expr) { - gfc_expr *result = 0L; - int i, j, dim, ncopies; + gfc_expr *result = NULL; + int nelem, i, j, dim, ncopies; mpz_t size; if ((!gfc_is_constant_expr (source) @@ -6019,8 +6019,20 @@ gfc_simplify_spread (gfc_expr *source, gfc_expr *dim_expr, gfc_expr *ncopies_exp else mpz_init_set_ui (size, 1); - if (mpz_get_si (size)*ncopies > flag_max_array_constructor) - return NULL; + nelem = mpz_get_si (size) * ncopies; + if (nelem > flag_max_array_constructor) + { + if (gfc_current_ns->sym_root->n.sym->attr.flavor == FL_PARAMETER) + { + gfc_error ("The number of elements (%d) in the array constructor " + "at %L requires an increase of the allowed %d upper " + "limit. See %<-fmax-array-constructor%> option.", + nelem, &source->where, flag_max_array_constructor); + return &gfc_bad_expr; + } + else + return NULL; + } if (source->expr_type == EXPR_CONSTANT) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3ac9cb86473..b820e136246 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-11-18 Steven G. Kargl + + PR fortran/43996 + * gfortran.dg/pr43996.f90: New test. + 2015-11-18 Joseph Myers PR c/65083 diff --git a/gcc/testsuite/gfortran.dg/pr43996.f90 b/gcc/testsuite/gfortran.dg/pr43996.f90 new file mode 100644 index 00000000000..d0a4daf3cc3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr43996.f90 @@ -0,0 +1,7 @@ +! { dg-do compile } +! PR fortran/43996 +! +real, parameter :: a(720,360) = spread((/(j, j=1,720) /), dim=2, ncopies=360) ! { dg-error "number of elements" } +real x +x = a(720,360) +end -- 2.30.2