Consider this short test case: module mytypes implicit none contains pure integer function get_i () get_i = 13 end function end module program test use mytypes implicit none integer, dimension(get_i()), save :: x print *, size (x) end It seems to be valid Fortran, but generates an ICE with every gfortran version I tried (from 4.7 to to 7-trunk). On trunk, the error looks like this: internal compiler error: in gfc_trans_auto_array_allocation, at fortran/trans-array.c:5979 0x8dff23 gfc_trans_auto_array_allocation(tree_node*, gfc_symbol*, gfc_wrapped_block*) /home/jweil/gcc/gcc7/trunk/gcc/fortran/trans-array.c:5979 0x90494d gfc_trans_deferred_vars(gfc_symbol*, gfc_wrapped_block*) /home/jweil/gcc/gcc7/trunk/gcc/fortran/trans-decl.c:4321 0x90b66e gfc_generate_function_code(gfc_namespace*) /home/jweil/gcc/gcc7/trunk/gcc/fortran/trans-decl.c:6366 0x8cdcfd gfc_generate_code(gfc_namespace*) /home/jweil/gcc/gcc7/trunk/gcc/fortran/trans.c:2030 0x85cefd translate_all_program_units /home/jweil/gcc/gcc7/trunk/gcc/fortran/parse.c:6038 0x85d572 gfc_parse_file() /home/jweil/gcc/gcc7/trunk/gcc/fortran/parse.c:6238 0x8b66a5 gfc_be_parse_file /home/jweil/gcc/gcc7/trunk/gcc/fortran/f95-lang.c:202 It is related to typebound_proc_19.f90 in the testsuite (from PR 47399).
When removing the SAVE attribute ... module mytypes implicit none contains pure integer function get_i () get_i = 13 end function end module program test use mytypes implicit none integer, dimension(get_i()) :: x print *, size (x) end ... it compiles fine with all tested versions. However, this variant is a regression of the patch for PR 55207, see: https://gcc.gnu.org/ml/fortran/2014-03/msg00108.html However, as comment 0 shows, it is not a problem introduced with that patch, but it is rather a long-standing problem that is only uncovered by the patch (according to F08, variables in the main PROGRAM implicitly get the SAVE attribute).
(In reply to janus from comment #0) > On trunk, the error looks like this: > > internal compiler error: in gfc_trans_auto_array_allocation, at > fortran/trans-array.c:5979 This line is an assert, and simply removing it makes the code in comment 0 compile and run without errors: Index: gcc/fortran/trans-array.c =================================================================== --- gcc/fortran/trans-array.c (Revision 242535) +++ gcc/fortran/trans-array.c (Arbeitskopie) @@ -5976,7 +5976,6 @@ gfc_trans_auto_array_allocation (tree decl, gfc_sy type = TREE_TYPE (type); gcc_assert (!sym->attr.use_assoc); - gcc_assert (!TREE_STATIC (decl)); gcc_assert (!sym->module); if (sym->ts.type == BT_CHARACTER It also regtests cleanly on current trunk. With this patch, the only difference in the dump of comment 0 and comment 1 is: --- c0.f90.003t.original 2016-11-17 13:15:57.487735846 +0100 +++ c1.f90.003t.original 2016-11-17 13:13:07.096377920 +0100 @@ -12,7 +12,7 @@ test () void * restrict D.3458; integer(kind=8) ubound.0; integer(kind=8) size.1; - static integer(kind=4)[0:D.3455] * restrict x; + integer(kind=4)[0:D.3455] * restrict x; integer(kind=8) D.3455; bitsizetype D.3456; sizetype D.3457; As an alternative to removing the assert, one could possibly prevent SAVEd variables in the main PROGRAM from being declared as "static" (which might also cure the performance regressions that Dominique reported for my patch for PR 55207)?
(In reply to janus from comment #2) > As an alternative to removing the assert, one could possibly prevent SAVEd > variables in the main PROGRAM from being declared as "static" (which might > also cure the performance regressions that Dominique reported for my patch > for PR 55207)? This could possibly be accomplished like this: Index: gcc/fortran/trans-decl.c =================================================================== --- gcc/fortran/trans-decl.c (Revision 242584) +++ gcc/fortran/trans-decl.c (Arbeitskopie) @@ -635,7 +635,8 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym) initialized variables are SAVE_IMPLICIT and explicitly saved are SAVE_EXPLICIT. */ if (!sym->attr.use_assoc - && (sym->attr.save != SAVE_NONE || sym->attr.data + && ((sym->attr.save != SAVE_NONE && !sym->ns->proc_name->attr.is_main_program) + || sym->attr.data || (sym->value && sym->ns->proc_name->attr.is_main_program) || (flag_coarray == GFC_FCOARRAY_LIB && sym->attr.codimension && !sym->attr.allocatable))) That indeed removes the ICE on comment 0, however it causes loads of testsuite regressions, so it's certainly not a very good idea.
Confirmed from 4.8 up to trunk (7.0).
> As an alternative to removing the assert, one could possibly prevent SAVEd > variables in the main PROGRAM from being declared as "static" (which might > also cure the performance regressions that Dominique reported for my patch > for PR 55207)? Related to pr42122?
(In reply to Dominique d'Humieres from comment #5) > Related to pr42122? Don't think so.
Likely a duplicate of pr42359.
(In reply to Dominique d'Humieres from comment #7) > Likely a duplicate of pr42359. Agreed.
*** Bug 42359 has been marked as a duplicate of this bug. ***
Working patch at https://gcc.gnu.org/ml/fortran/2016-11/msg00188.html.
As noted by Dominique, the problem here has originally been introduced by r126826.
Author: janus Date: Mon Dec 12 18:54:54 2016 New Revision: 243580 URL: https://gcc.gnu.org/viewcvs?rev=243580&root=gcc&view=rev Log: 2016-12-12 Janus Weil <janus@gcc.gnu.org> PR fortran/78392 * expr.c (gfc_is_constant_expr): Specification functions are not compile-time constants. Update documentation (add reference to F08 standard), add a FIXME. (external_spec_function): Add reference to F08 standard. * resolve.c (resolve_fl_variable): Ditto. 2016-12-12 Janus Weil <janus@gcc.gnu.org> PR fortran/78392 * gfortran.dg/constant_shape.f90: New test case. Added: trunk/gcc/testsuite/gfortran.dg/constant_shape.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog
Fixed on 7-trunk with r243580. Closing.