From: Paul Thomas Date: Mon, 19 Oct 2015 19:32:52 +0000 (+0000) Subject: re PR fortran/56852 (ICE on invalid: "Bad array reference" for an undeclared loop... X-Git-Tag: releases/gcc-4.9.4~549 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4b18d9683dd16c64bea5921ad57b50041093f2c;p=thirdparty%2Fgcc.git re PR fortran/56852 (ICE on invalid: "Bad array reference" for an undeclared loop variable) 2013-10-19 Paul Thomas PR fortran/56852 * primary.c (gfc_variable_attr): Avoid ICE on AR_UNKNOWN if any of the index variables are untyped and errors are present. 2013-10-19 Paul Thomas PR fortran/56852 * gfortran.dg/pr56852.f90 : New test From-SVN: r229000 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 40b2dc38f8ad..337bd32eaf87 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2013-10-19 Paul Thomas + + Backport from trunk + PR fortran/56852 + * primary.c (gfc_variable_attr): Avoid ICE on AR_UNKNOWN if any + of the index variables are untyped and errors are present. + 2015-10-18 Thomas Koenig Backport from trunk diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index e2eb46748fe5..c73a4da773ee 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -2133,7 +2133,7 @@ check_substring: symbol_attribute gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts) { - int dimension, codimension, pointer, allocatable, target; + int dimension, codimension, pointer, allocatable, target, n; symbol_attribute attr; gfc_ref *ref; gfc_symbol *sym; @@ -2190,7 +2190,25 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts) break; case AR_UNKNOWN: - gfc_internal_error ("gfc_variable_attr(): Bad array reference"); + /* 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) + gfc_internal_error ("gfc_variable_attr(): Bad array reference"); } break; @@ -3138,7 +3156,8 @@ gfc_match_rvalue (gfc_expr **result) break; default: - gfc_error ("Symbol at %C is not appropriate for an expression"); + gfc_error ("Symbol '%s' at %C is not appropriate for an expression", + sym->name); return MATCH_ERROR; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0849fd4e4cc4..c08758f38afe 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2013-10-19 Paul Thomas + + Backport from trunk + PR fortran/56852 + * gfortran.dg/pr56852.f90 : New test + 2015-10-18 Thomas Koenig Backport from trunk diff --git a/gcc/testsuite/gfortran.dg/pr56852.f90 b/gcc/testsuite/gfortran.dg/pr56852.f90 new file mode 100644 index 000000000000..bdf76e1f5218 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr56852.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! Test the fix for pr56852, where an ICE would occur after the error. +! +! Contributed by Lorenz Huedepohl +! +program test + implicit none + real :: a(4) + ! integer :: i + read(0) (a(i),i=1,4) ! { dg-error "has no IMPLICIT type" } +end program