http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50163
Tobias Burnus <burnus at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |ice-on-invalid-code CC| |burnus at gcc dot gnu.org Known to work| |4.1.2 Target Milestone|--- |4.6.2 Summary|Internal compiler error: |[4.3/4.4/4.5/4.6/4.7 |initialization expression |Regression] ICE: | |initialization expression Known to fail| |4.3.4, 4.5.3, 4.6.1, 4.7.0 --- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-08-23 10:37:38 UTC --- 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);