Fortran: Fix ICE after error regression [PR99060].
authorPaul Thomas <pault@gcc.gnu.org>
Thu, 11 Feb 2021 10:38:23 +0000 (10:38 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Thu, 11 Feb 2021 10:38:23 +0000 (10:38 +0000)
2021-02-11  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/99060
* primary.c (gfc_match_varspec): Test for non-null 'previous'
before using its name in the error message.

gcc/testsuite/
PR fortran/99060
* gfortran.dg/pr99060.f90: New test.

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

index d0610d02ebdc03ee9262eea325837375a8460217..7633e77909f204160a10189931cf23a77a725160 100644 (file)
@@ -2407,11 +2407,15 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
        component = NULL;
 
       if (intrinsic && !inquiry)
-       {
-         gfc_error ("%qs at %C is not an inquiry reference to an intrinsic "
-                    "type component %qs", name, previous->name);
+       {
+         if (previous)
+           gfc_error ("%qs at %C is not an inquiry reference to an intrinsic "
+                       "type component %qs", name, previous->name);
+         else
+           gfc_error ("%qs at %C is not an inquiry reference to an intrinsic "
+                       "type component", name);
          return MATCH_ERROR;
-       }
+       }
       else if (component == NULL && !inquiry)
        return MATCH_ERROR;
 
diff --git a/gcc/testsuite/gfortran.dg/pr99060.f90 b/gcc/testsuite/gfortran.dg/pr99060.f90
new file mode 100644 (file)
index 0000000..fdf3b1a
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+!
+! Test the fix for PR99060 in which the expression caused an ICE after the error.
+!
+! Contributed by Gerhard Steinmetz  <gscfq@t-online.de>
+!
+program p
+   real :: a
+   print *, a%kind%n ! { dg-error "not an inquiry reference" }
+end