[ forwarded from http://bugs.debian.org/401496 The report and original testcase came from Jonathan Stott. I further reduced it down in size. ] I've confirmed this bug with 4.1.2 20061115 and 4.3.0 20070326. (sid)18753:tbm@em64t: ~/src/t] gfortran -c c.f90 c.f90: In function ‘xstrcmp’: c.f90:5: internal compiler error: in gfc_conv_constant, at fortran/trans-const.c:348 Please submit a full bug report, with preprocessed source if appropriate. Testcase: module cfgfile contains integer function xstrcmp(s1) character*(*), intent(in) :: s1 integer :: n1 = len(s1) n1 = 1 return end function xstrcmp end module cfgfile
This is invalid code, since initialization expressions must be constants, and the length of an assumed-length string argument is not a constant. Regardless, we shouldn't be ICE'ing on it.
Further reduced testcase: $> cat pr31639.f90 function f() integer :: i = irand() f = i end function $> gfortran-svn -g -Wall -c pr31639.f90 pr31639.f90: In function 'f': pr31639.f90:1: internal compiler error: in gfc_conv_constant, at fortran/trans-const.c:297 With this code: function f() integer :: i = irand() end function one gets: $> gfortran-svn -g -Wall -c pr31639.f90 pr31639.f90: In function 'f': pr31639.f90:1: warning: Function return value not set pr31639.f90:1: warning: control reaches end of non-void function which is noteworthy in itself ...
> function f() > integer :: i = irand() > end function Make that: function f() integer :: f = irand() end function
> function f() > integer :: i = irand() > f = i > end function We should give a message such as ifort: The initialization shall not appear for this object name. [F] This array or function or substring is invalid in constant expressions. [IRAND] The place to change is check_init_expr; maybe gfc_intrinsic_func_interface. Giving an error should fix both problems.
Subject: Bug 31639 Author: dfranke Date: Thu Jul 12 22:15:11 2007 New Revision: 126605 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126605 Log: gcc/fortran: 2007-07-12 Daniel Franke <franke.daniel@gmail.com> PR fortran/31639 * decl.c (gfc_match_suffix): Removed surplus general error that hides a more specific message. * resolve.c (resolve_fl_variable): Reject illegal initializiers only if not already done. (resolve_fl_procedure): Added check for initializers of functions. gcc/testsuite: 2007-07-12 Daniel Franke <franke.daniel@gmail.com> PR fortran/31639 * gfortran.dg/func_decl_4.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/func_decl_4.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/decl.c trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 31639 Author: dfranke Date: Sun Jul 22 16:31:11 2007 New Revision: 126826 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126826 Log: gcc/fortran: 2007-07-22 Daniel Franke <franke.daniel@gmail.com> PR fortran/29962 PR fortran/31253 PR fortran/31265 PR fortran/31639 * gfortran.h (gfc_intrinsic_sym): Changed members elemental, pure, generic, specific, actual_ok, noreturn into bits of a bitfield, added bits for inquiry, transformational, conversion. * check.c (non_init_transformational): Removed, removed all callers. * intrinsic.c (enum class): New. (add_sym*): Replaced argument elemetal by enum class. Changed all callers. (add_functions): Assign appropriate classes to intrinsic functions. (add_subroutines): Assign appropriate classes to intrinsic subroutines. (add_conv): Set conversion attribute. (gfc_init_expr_extensions): Removed, removed all callers. (gfc_intrinsic_func_interface): Reimplemented check for non-standard initializatione expressions. * expr.c (check_specification_function): New. (gfc_is_constant_expr): Added check for specification functions. (check_init_expr_arguments): New. (check_inquiry): Changed return value to MATCH, added checks for inquiry functions defined by F2003. (check_transformational): New. (check_null): New. (check_elemental): New. (check_conversion): New. (check_init_expr): Call new check functions, add more specific error messages. gcc/testsuite: 2007-07-22 Daniel Franke <franke.daniel@gmail.com> PR fortran/29962 * gfortran.dg/array_initializer_1.f90: Removed warning. * gfortran.dg/initialization_1.f90: Adjusted messages. * gfortran.dg/nested_modules_6.f90: Removed warning. PR fortran/31253 * gfortran.dg/initialization_7.f90: New test. PR fortran/31639 * gfortran.dg/initialization_8.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/initialization_7.f90 trunk/gcc/testsuite/gfortran.dg/initialization_8.f90 Modified: trunk/gcc/fortran/check.c trunk/gcc/fortran/expr.c trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/intrinsic.c trunk/gcc/testsuite/gfortran.dg/array_initializer_1.f90 trunk/gcc/testsuite/gfortran.dg/initialization_1.f90 trunk/gcc/testsuite/gfortran.dg/nested_modules_6.f90
Fixed in trunk. Closing.
As said, closing as fixed.
I don't know the fortran policy on closing bug reports with regressions; is there no chance to backport the fix to the active branches? Matthias
(In reply to comment #9) > I don't know the fortran policy on closing bug reports with regressions; is > there no chance to backport the fix to the active branches? It isn't a gfortran policy. The general GCC policy is that only regression fixes can/should be backported. You would need to show that the code in comment #1 could be compiled with a version of gfortran that is older than 4.1.2 20061115; otherwise, this is simply a bug that finally got fixed. Additionally, there simply are too few gfortran developers to maintain 3 active branches. So, we have chosen to concentrate our effort on trunk. If a patch fixes a regression in 4.2, it may be backported but there is no guarantee.
Reopening, the original testcase still fails for std=gnu. Sigh. For the record: an error is generated for -std=f95, std=f2003 and a warning for -std=gnu -pedantic. Currently testing ... Index: expr.c =================================================================== --- expr.c (revision 126826) +++ expr.c (working copy) @@ -1966,9 +1966,8 @@ && ap->expr->symtree->n.sym->ts.type == BT_CHARACTER && ap->expr->symtree->n.sym->ts.cl->length == NULL) { - if (gfc_notify_std (GFC_STD_GNU, "assumed character length " - "variable '%s' in constant expression at %L", - e->symtree->n.sym->name, &e->where) == FAILURE) + gfc_error ("assumed character length variable '%s' in constant " + "expression at %L", e->symtree->n.sym->name, &e->where); return MATCH_ERROR; } else if (not_restricted && check_init_expr (ap->expr) == FAILURE)
Subject: Bug 31639 Author: dfranke Date: Mon Jul 23 20:35:03 2007 New Revision: 126858 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126858 Log: gcc/fortran: 2007-07-23 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/31639 * expr.c (check_transformational): Reject valid transformational intrinsics to avoid ICE. (check_inquiry): Report error for assumed character lengths for all supported standards. (check_init_expr): Whitespace fix. gcc/testsuite: 2007-07-23 Daniel Franke <franke.daniel@gmail.com> PR fortran/31639 * gfortran.dg/initialization_9.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/initialization_9.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/testsuite/ChangeLog
Closing again. The orginal testcase is now correctly handled for all standards.