]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/56852 (ICE on invalid: "Bad array reference" for an undeclared loop...
authorPaul Thomas <pault@gcc.gnu.org>
Mon, 19 Oct 2015 19:32:52 +0000 (19:32 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Mon, 19 Oct 2015 19:32:52 +0000 (19:32 +0000)
2013-10-19  Paul Thomas  <pault@gcc.gnu.org>

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  <pault@gcc.gnu.org>

PR fortran/56852
* gfortran.dg/pr56852.f90 : New test

From-SVN: r229000

gcc/fortran/ChangeLog
gcc/fortran/primary.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr56852.f90 [new file with mode: 0644]

index 40b2dc38f8ad6134c288a26d8a45bb52f8121207..337bd32eaf8733ceeafd522e3a968a22a34ad65c 100644 (file)
@@ -1,3 +1,10 @@
+2013-10-19  Paul Thomas  <pault@gcc.gnu.org>
+
+       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  <tkoenig@gcc.gnu.org>
 
        Backport from trunk
index e2eb46748fe5a5784fd4617a4046a6066c6b5275..c73a4da773eef8daf8fa9dbcd8760f8163f972e1 100644 (file)
@@ -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;
     }
 
index 0849fd4e4cc46ab89148eee50d723cf8a0dc1937..c08758f38afe0f73a51fd727822ea1998ca7fcb2 100644 (file)
@@ -1,3 +1,9 @@
+2013-10-19  Paul Thomas  <pault@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/56852
+       * gfortran.dg/pr56852.f90 : New test
+
 2015-10-18  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        Backport from trunk
diff --git a/gcc/testsuite/gfortran.dg/pr56852.f90 b/gcc/testsuite/gfortran.dg/pr56852.f90
new file mode 100644 (file)
index 0000000..bdf76e1
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! Test the fix for pr56852, where an ICE would occur after the error.
+!
+! Contributed by Lorenz Huedepohl  <bugs@stellardeath.org>
+!
+program test
+  implicit none
+  real :: a(4)
+  ! integer :: i
+  read(0) (a(i),i=1,4) ! { dg-error "has no IMPLICIT type" }
+end program