re PR fortran/91942 (ICE in match_vtag, at fortran/io.c:1485)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Wed, 2 Oct 2019 17:04:57 +0000 (17:04 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Wed, 2 Oct 2019 17:04:57 +0000 (17:04 +0000)
2019-10-02  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/91942
* io.c (match_vtag): Check for non-NULL result->symtree.
(match_out_tag): Check for invalid constant due to inquiry parameter.
(match_filepos): Instead of a syntax error, go to cleanup to get better
error messages.

2019-10-02  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/91942
* gfortran.dg/pr91587.f90: Update dg-error regex.
* gfortran.dg/pr91942.f90: New test.

From-SVN: r276472

gcc/fortran/ChangeLog
gcc/fortran/io.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr91587.f90
gcc/testsuite/gfortran.dg/pr91942.f90 [new file with mode: 0644]

index f225ff2..476973d 100644 (file)
@@ -1,5 +1,13 @@
 2019-10-02  Steven G. Kargl  <kargl@gcc.gnu.org>
 
+       PR fortran/91942
+       * io.c (match_vtag): Check for non-NULL result->symtree.
+       (match_out_tag): Check for invalid constant due to inquiry parameter.
+       (match_filepos): Instead of a syntax error, go to cleanup to get better
+       error messages.
+
+2019-10-02  Steven G. Kargl  <kargl@gcc.gnu.org>
+
        PR fortran/91943
        * match.c (gfc_match_call): BOZ cannot be an actual argument in
        a subroutine reference.
index 9ae06b1..b969a1a 100644 (file)
@@ -1482,24 +1482,29 @@ match_vtag (const io_tag *tag, gfc_expr **v)
       return MATCH_ERROR;
     }
 
-  if (result->symtree->n.sym->attr.intent == INTENT_IN)
+  if (result->symtree)
     {
-      gfc_error ("Variable %s cannot be INTENT(IN) at %C", tag->name);
-      gfc_free_expr (result);
-      return MATCH_ERROR;
-    }
+      bool impure;
 
-  bool impure = gfc_impure_variable (result->symtree->n.sym);
-  if (impure && gfc_pure (NULL))
-    {
-      gfc_error ("Variable %s cannot be assigned in PURE procedure at %C",
-                tag->name);
-      gfc_free_expr (result);
-      return MATCH_ERROR;
-    }
+      if (result->symtree->n.sym->attr.intent == INTENT_IN)
+       {
+         gfc_error ("Variable %s cannot be INTENT(IN) at %C", tag->name);
+         gfc_free_expr (result);
+         return MATCH_ERROR;
+       }
+
+      impure = gfc_impure_variable (result->symtree->n.sym);
+      if (impure && gfc_pure (NULL))
+       {
+         gfc_error ("Variable %s cannot be assigned in PURE procedure at %C",
+                    tag->name);
+         gfc_free_expr (result);
+         return MATCH_ERROR;
+       }
 
-  if (impure)
-    gfc_unset_implicit_pure (NULL);
+      if (impure)
+       gfc_unset_implicit_pure (NULL);
+    }
 
   *v = result;
   return MATCH_YES;
@@ -1515,7 +1520,16 @@ match_out_tag (const io_tag *tag, gfc_expr **result)
 
   m = match_vtag (tag, result);
   if (m == MATCH_YES)
-    gfc_check_do_variable ((*result)->symtree);
+    {
+      if ((*result)->symtree)
+       gfc_check_do_variable ((*result)->symtree);
+
+      if ((*result)->expr_type == EXPR_CONSTANT)
+       {
+         gfc_error ("Expecting a variable at %L", &(*result)->where);
+         return MATCH_ERROR;
+       }
+    }
 
   return m;
 }
@@ -2845,7 +2859,7 @@ match_filepos (gfc_statement st, gfc_exec_op op)
 
   m = match_file_element (fp);
   if (m == MATCH_ERROR)
-    goto syntax;
+    goto cleanup;
   if (m == MATCH_NO)
     {
       m = gfc_match_expr (&fp->unit);
index 3256a02..88e4d32 100644 (file)
@@ -1,5 +1,11 @@
 2019-10-02  Steven G. Kargl  <kargl@gcc.gnu.org>
 
+       PR fortran/91942
+       * gfortran.dg/pr91587.f90: Update dg-error regex.
+       * gfortran.dg/pr91942.f90: New test.
+
+2019-10-02  Steven G. Kargl  <kargl@gcc.gnu.org>
+
        PR fortran/91943
        gfortran.dg/pr91943.f90
 
index c07735d..c304be1 100644 (file)
@@ -2,9 +2,9 @@
 ! PR fortran/91587
 ! Code contributed by Gerhard Steinmetz
 program p
-   backspace(err=!)  ! { dg-error "Syntax error in" }
-   flush(err=!)      ! { dg-error "Syntax error in" }
-   rewind(err=!)     ! { dg-error "Syntax error in" }
+   backspace(err=!)  ! { dg-error "Invalid value for" }
+   flush(err=!)      ! { dg-error "Invalid value for" }
+   rewind(err=!)     ! { dg-error "Invalid value for" }
 end
 
 subroutine bar       ! An other matcher runs, and gives a different error.
diff --git a/gcc/testsuite/gfortran.dg/pr91942.f90 b/gcc/testsuite/gfortran.dg/pr91942.f90
new file mode 100644 (file)
index 0000000..cd237d3
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! PR fortran/91942
+! Code contributed by Gerhard Steinmetz
+program p
+   integer :: i
+   backspace (iostat=i%kind) ! { dg-error "Expecting a variable at" }
+   endfile (iostat=i%kind) ! { dg-error "Expecting END PROGRAM" }
+   flush (iostat=i%kind) ! { dg-error "Expecting a variable at" }
+   rewind (iostat=i%kind) ! { dg-error "Expecting a variable at" }
+end