From d6c9e9d7c4003e0cb0adebeab18d933f399c65aa Mon Sep 17 00:00:00 2001 From: jvdelisle Date: Sat, 1 Nov 2008 16:42:31 +0000 Subject: [PATCH] 2008-11-01 Steven G. Kargl PR fortran/19925 * trans-array.c (gfc_trans_array_constructor_value): Fix comment. (gfc_conv_array_initializer): Convert internal_error() to gfc_error_now. * array.c: Remove GFC_MAX_AC_EXPAND macro. (gfc_expand_constructor): Use gfc_option.flag_max_array_constructor. * gfortran.h (gfc_option): Add flag_max_array_constructor member. * lang.opt: Add -fmax-array-constructor option. * expr.c (gfc_match_init_expr): Fix error message to mention new option. * invoke.texi: Document new option. * options.c (gfc_init_options): Set default value for new option. (gfc_handle_option): Deal with commandline. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@141518 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 16 +++++++++++++++- gcc/fortran/array.c | 9 +-------- gcc/fortran/gfortran.h | 1 + gcc/fortran/invoke.texi | 30 +++++++++++++++++++++++++++--- gcc/fortran/lang.opt | 4 ++++ gcc/fortran/options.c | 5 +++++ gcc/fortran/trans-array.c | 13 ++++++++----- 7 files changed, 61 insertions(+), 17 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index a7baab24526..574ddc84e51 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,17 @@ +2008-11-01 Steven G. Kargl + + PR fortran/19925 + * trans-array.c (gfc_trans_array_constructor_value): Fix comment. + (gfc_conv_array_initializer): Convert internal_error() to gfc_error_now. + * array.c: Remove GFC_MAX_AC_EXPAND macro. + (gfc_expand_constructor): Use gfc_option.flag_max_array_constructor. + * gfortran.h (gfc_option): Add flag_max_array_constructor member. + * lang.opt: Add -fmax-array-constructor option. + * expr.c (gfc_match_init_expr): Fix error message to mention new option. + * invoke.texi: Document new option. + * options.c (gfc_init_options): Set default value for new option. + (gfc_handle_option): Deal with commandline. + 2008-11-01 Daniel Kraft PR fortran/35681 @@ -72,7 +86,7 @@ * fortran/arith.h: Update mpfr_to_mpz prototype. * fortran/simplify.c (gfc_simplify_ceiling, gfc_simplify_floor, gfc_simplify_ifix, gfc_simplify_idint, simplify_nint): Update function - calls to include locus + calls to include locus. 2008-10-30 Mikael Morin diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index 70cf66294da..fe83ec685f9 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -24,13 +24,6 @@ along with GCC; see the file COPYING3. If not see #include "gfortran.h" #include "match.h" -/* This parameter is the size of the largest array constructor that we - will expand to an array constructor without iterators. - Constructors larger than this will remain in the iterator form. */ - -#define GFC_MAX_AC_EXPAND 65535 - - /**************** Array reference matching subroutines *****************/ /* Copy an array reference structure. */ @@ -1463,7 +1456,7 @@ gfc_expand_constructor (gfc_expr *e) gfc_expr *f; gfc_try rc; - f = gfc_get_array_element (e, GFC_MAX_AC_EXPAND); + f = gfc_get_array_element (e, gfc_option.flag_max_array_constructor); if (f != NULL) { gfc_free_expr (f); diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 5f4880eebf2..9ac6f3c7815 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -1992,6 +1992,7 @@ typedef struct int flag_second_underscore; int flag_implicit_none; int flag_max_stack_var_size; + int flag_max_array_constructor; int flag_range_check; int flag_pack_derived; int flag_repack_arrays; diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index 2f6f4b0f9a4..8e47df4f684 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -148,7 +148,8 @@ and warnings}. @item Directory Options @xref{Directory Options,,Options for directory search}. -@gccoptlist{-I@var{dir} -J@var{dir} -M@var{dir} -fintrinsic-modules-path @var{dir}} +@gccoptlist{-I@var{dir} -J@var{dir} -M@var{dir} @gol +-fintrinsic-modules-path @var{dir}} @item Link Options @xref{Link Options,,Options for influencing the linking step}. @@ -162,9 +163,10 @@ and warnings}. @item Code Generation Options @xref{Code Gen Options,,Options for code generation conventions}. -@gccoptlist{-fno-automatic -ff2c -fno-underscoring +@gccoptlist{-fno-automatic -ff2c -fno-underscoring @gol -fsecond-underscore @gol --fbounds-check -fcheck-array-temporaries -fmax-stack-var-size=@var{n} @gol +-fbounds-check -fcheck-array-temporaries -fmax-array-constructor =@var{n} @gol +-fmax-stack-var-size=@var{n} @gol -fpack-derived -frepack-arrays -fshort-enums -fexternal-blas @gol -fblas-matmul-limit=@var{n} -frecursive -finit-local-zero @gol -finit-integer=@var{n} -finit-real=@var{} @gol @@ -1191,6 +1193,28 @@ sometimes useful in optimization, in order to avoid such temporaries. Note: The warning is only printed once per location. +@item -fmax-array-constructor=@var{n} +@opindex @code{fmax-array-constructor} +This option can be used to increase the upper limit permitted in +array constructors. The code below requires this option to expand +the array at compile time. + +@smallexample +@code{program test} +@code{implicit none} +@code{integer j} +@code{integer, parameter :: n = 100000} +@code{integer, parameter :: i(n) = (/ (2*j, j = 1, n) /)} +@code{print '(10(I0,1X))', i} +@code{end program test} +@end smallexample + +@emph{Caution: This option can lead to long compile times and excessively +large object files.} + +The default value for @var{n} is 65535. + + @item -fmax-stack-var-size=@var{n} @opindex @code{fmax-stack-var-size} This option specifies the size in bytes of the largest array that will be put diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 49055f38e5b..04682c19118 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -284,6 +284,10 @@ finit-real= Fortran RejectNegative Joined -finit-real= Initialize local real variables +fmax-array-constructor= +Fortran RejectNegative Joined UInteger +-fmax-array-constructor= Maximum number of objects in an array constructor + fmax-errors= Fortran RejectNegative Joined UInteger -fmax-errors= Maximum number of errors to report diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index e84b3b15370..3f49d563131 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -65,6 +65,7 @@ gfc_init_options (unsigned int argc, const char **argv) gfc_option.max_continue_free = 255; gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN; gfc_option.max_subrecord_length = 0; + gfc_option.flag_max_array_constructor = 65535; gfc_option.convert = GFC_CONVERT_NATIVE; gfc_option.record_marker = 0; gfc_option.dump_parse_tree = 0; @@ -642,6 +643,10 @@ gfc_handle_option (size_t scode, const char *arg, int value) gfc_add_intrinsic_modules_path (arg); break; + case OPT_fmax_array_constructor_: + gfc_option.flag_max_array_constructor = value > 65535 ? value : 65535; + break; + case OPT_fmax_errors_: gfc_option.max_errors = value; break; diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index db43a40d82d..218c401af80 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -1303,7 +1303,7 @@ gfc_trans_array_constructor_value (stmtblock_t * pblock, tree type, } } - /* The frontend should already have done any expansions possible + /* The frontend should already have done any expansions at compile-time. */ if (!c->iterator) { @@ -3946,10 +3946,13 @@ gfc_conv_array_initializer (tree type, gfc_expr * expr) if (c->iterator) { /* Problems occur when we get something like - integer :: a(lots) = (/(i, i=1,lots)/) */ - /* TODO: Unexpanded array initializers. */ - internal_error - ("Possible frontend bug: array constructor not expanded"); + integer :: a(lots) = (/(i, i=1, lots)/) */ + gfc_error_now ("The number of elements in the array constructor " + "at %L requires an increase of the allowed %d " + "upper limit. See -fmax-array-constructor " + "option", &expr->where, + gfc_option.flag_max_array_constructor); + return NULL_TREE; } if (mpz_cmp_si (c->n.offset, 0) != 0) index = gfc_conv_mpz_to_tree (c->n.offset, gfc_index_integer_kind); -- 2.11.0