https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68283
Dominique d'Humieres <dominiq at lps dot ens.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pault at gcc dot gnu.org, | |tkoenig at gcc dot gnu.org --- Comment #12 from Dominique d'Humieres <dominiq at lps dot ens.fr> --- The block for (n = 0; n < ref->u.ar.as->rank; n++) { int errors; gfc_get_errors (NULL, &errors); if (((ref->u.ar.start[n] && ref->u.ar.start[n]->ts.type == BT_UNKNOWN) || (ref->u.ar.end[n] && ref->u.ar.end[n]->ts.type == BT_UNKNOWN) || (ref->u.ar.stride[n] && ref->u.ar.stride[n]->ts.type == BT_UNKNOWN)) && errors > 0) break; } if (n == ref->u.ar.as->rank) gfc_internal_error ("gfc_variable_attr(): Bad array reference"); in gcc/fortran/primary.c (introduced at r221955) looks fishy, CCed Paul. It is not accessed if the code is compiled with -fno-frontend-optimize, CCed Thomas. The patch --- ../_clean/gcc/fortran/primary.c 2015-10-18 13:07:28.000000000 +0200 +++ gcc/fortran/primary.c 2015-11-12 11:15:02.000000000 +0100 @@ -2194,7 +2194,7 @@ check_substring: symbol_attribute gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts) { - int dimension, codimension, pointer, allocatable, target, n; + int dimension, codimension, pointer, allocatable, target; symbol_attribute attr; gfc_ref *ref; gfc_symbol *sym; @@ -2253,22 +2253,9 @@ gfc_variable_attr (gfc_expr *expr, gfc_t case AR_UNKNOWN: /* If any of start, end or stride is not integer, there will already have been an error issued. */ - for (n = 0; n < ref->u.ar.as->rank; n++) - { - int errors; - gfc_get_errors (NULL, &errors); - if (((ref->u.ar.start[n] - && ref->u.ar.start[n]->ts.type == BT_UNKNOWN) - || - (ref->u.ar.end[n] - && ref->u.ar.end[n]->ts.type == BT_UNKNOWN) - || - (ref->u.ar.stride[n] - && ref->u.ar.stride[n]->ts.type == BT_UNKNOWN)) - && errors > 0) - break; - } - if (n == ref->u.ar.as->rank) + int errors; + gfc_get_errors (NULL, &errors); + if (errors == 0) gfc_internal_error ("gfc_variable_attr(): Bad array reference"); } fixes the PR without any regression (I have left the comment which may be updated).