Get following error message when compiling (gfortran -c test.f90): f951: internal compiler error: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions. Offending source code (test.f90): <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< module stringy character(len=2) :: xx='aa' integer :: iloc=index(xx,'bb') end module stringy >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> NOTE: I think the code is slightly illegal - i.e. xx should be compile-time constant. Compiles OK if xx is qualified as a parameter.
Confirmed on 4.4.6, 4.5.3, 4.6.1, and trunk. g95 and ifort reject the code with [macbook] f90/bug% g95 pr50163.f90 In file pr50163.f90:3 integer :: iloc=index(xx,'bb') 1 Error: Variable 'xx' at (1) cannot appear in an initialization expression [macbook] f90/bug% ifc pr50163.f90 pr50163.f90(3): error #6592: This symbol must be a defined parameter, an enumerator, or an argument of an inquiry function that evaluates to a compile-time constant. [XX] integer :: iloc=index(xx,'bb') ----------------------^ pr50163.f90(3): error #6973: This is not a valid initialization expression. [INDEX] integer :: iloc=index(xx,'bb') ----------------^ compilation aborted for pr50163.f90 (code 1) The segmentation fault is due to Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000 check_init_expr (e=0x141f1c640) at ../../work/gcc/fortran/expr.c:1969 1969 if (a->expr->expr_type != EXPR_ARRAY) (gdb) bt #0 check_init_expr (e=0x141f1c640) at ../../work/gcc/fortran/expr.c:1969 #1 0x000000010002e778 in gfc_reduce_init_expr (expr=0x3) at ../../work/gcc/fortran/expr.c:2626 Current language: auto; currently c++ (gdb) p *a $3 = { name = 0x0, label = 0x0, missing_arg_type = BT_LOGICAL, expr = 0x0, next = 0x141f1cac0 }
That's actually a regression: With 4.1.2 I get: integer :: iloc=index(xx,'bb') 1 Error: Parameter 'xx' at (1) has not been declared or is a variable, which does not reduce to a constant expression While with GCC 4.3.4 and later, I get an ICE. I have not tested 4.2. * * * The problem seems to be the delayed error output. In expr.c's check_init_expr, one has: if ((m = check_conversion (e)) == MATCH_NO && (m = check_inquiry (e, 1)) == MATCH_NO && (m = check_null (e)) == MATCH_NO && (m = check_transformational (e)) == MATCH_NO && (m = check_elemental (e)) == MATCH_NO) { gfc_error ("Intrinsic function '%s' at %L is not permitted " "in an initialization expression", e->symtree->n.sym->name, &e->where); m = MATCH_ERROR; } /* Try to scalarize an elemental intrinsic function that has an array argument. */ isym = gfc_find_function (e->symtree->n.sym->name); if (isym && isym->elemental && (t = scalarize_intrinsic_call (e)) == SUCCESS) What happens now is: "check_elemental" prints an error (which gets buffered) and returns MATCH_ERROR. However, that value is not checked - thus the code continues to the scalarize_intrinsic_call(e), which then gives an ICE. Draft patch (only very lightly tested): --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -2481,6 +2481,9 @@ check_init_expr (gfc_expr *e) m = MATCH_ERROR; } + if (m == MATCH_ERROR) + return FAILURE; + /* Try to scalarize an elemental intrinsic function that has an array argument. */ isym = gfc_find_function (e->symtree->n.sym->name);
Author: burnus Date: Wed Aug 24 13:11:08 2011 New Revision: 178038 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178038 Log: 2011-08-24 Tobias Burnus <burnus@net-b.de> PR fortran/50163 * expr.c (check_init_expr): Return when an error occured. 2011-08-24 Tobias Burnus <burnus@net-b.de> PR fortran/50163 * gfortran.dg/initialization_28.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/initialization_28.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/testsuite/ChangeLog
Author: burnus Date: Thu Aug 25 08:29:29 2011 New Revision: 178054 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178054 Log: 2011-08-25 Tobias Burnus <burnus@net-b.de> PR fortran/50163 * check_init_expr (check_init_expr): Return when an error occured. 2011-08-25 Tobias Burnus <burnus@net-b.de> PR fortran/50163 * gfortran.dg/initialization_28.f90: New. Added: branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/initialization_28.f90 Modified: branches/gcc-4_6-branch/gcc/fortran/ChangeLog branches/gcc-4_6-branch/gcc/fortran/expr.c branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Author: burnus Date: Tue Aug 30 06:50:22 2011 New Revision: 178280 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178280 Log: 2011-08-30 Tobias Burnus <burnus@net-b.de> PR fortran/50163 * check_init_expr (check_init_expr): Return when an error * occured. 2011-08-30 Tobias Burnus <burnus@net-b.de> PR fortran/50163 * gfortran.dg/initialization_28.f90: New. Added: branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/initialization_28.f90 Modified: branches/gcc-4_5-branch/gcc/fortran/ChangeLog branches/gcc-4_5-branch/gcc/fortran/expr.c branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
FIXED on the trunk (4.7) and on the 4.5 and 4.6 branches. As mere ice-on-invalid-code bug, I decided not to backport it to 4.4. Anyone who wants to have it also in 4.4: Feel free to either backport it yourself or to tell us. Thanks for the bug report!