re PR fortran/69910 (ICE with NEWUNIT)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sat, 27 Feb 2016 19:07:13 +0000 (19:07 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sat, 27 Feb 2016 19:07:13 +0000 (19:07 +0000)
2016-02-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
    Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/69110
* io.c (gfc_match_open): Check that open status is an expression
constant before comparing string to 'scratch' with NEWUNIT.

* gfortran.dg/newunit_4.f90: New test.

Co-Authored-By: Steven G. Kargl <kargl@gcc.gnu.org>
From-SVN: r233782

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

index 5f1bc4f..80ec195 100644 (file)
@@ -1,3 +1,10 @@
+2016-02-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+           Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/69110
+       * io.c (gfc_match_open): Check that open status is an expression
+       constant before comparing string to 'scratch' with NEWUNIT.
+
 2016-02-27  Alessandro Fanfarillo  <fanfarillo.gcc@gmail.com>
 
        * trans.c (gfc_allocate_allocatable): size conversion
index fddd36b..da0e1c5 100644 (file)
@@ -1890,13 +1890,16 @@ gfc_match_open (void)
          goto cleanup;
        }
 
-      if (!(open->file || (open->status
-          && gfc_wide_strncasecmp (open->status->value.character.string,
-                                  "scratch", 7) == 0)))
-       {
-         gfc_error ("NEWUNIT specifier must have FILE= "
-                    "or STATUS='scratch' at %C");
-         goto cleanup;
+      if (!open->file && open->status)
+        {
+         if (open->status->expr_type == EXPR_CONSTANT
+            && gfc_wide_strncasecmp (open->status->value.character.string,
+                                      "scratch", 7) != 0)
+          {
+            gfc_error ("NEWUNIT specifier must have FILE= "
+                       "or STATUS='scratch' at %C");
+            goto cleanup;
+          }
        }
     }
   else if (!open->unit)
index ab6c1db..f64a07d 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR fortran/69110
+       * gfortran.dg/newunit_4.f90: New test.
+
 2016-02-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/69613
diff --git a/gcc/testsuite/gfortran.dg/newunit_4.f90 b/gcc/testsuite/gfortran.dg/newunit_4.f90
new file mode 100644 (file)
index 0000000..4d7d738
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! PR69110 ICE with NEWUNIT 
+subroutine open_file_safe(fname, fstatus, faction, fposition, funit)
+  character(*), intent(in)  :: fname, fstatus, faction, fposition
+  integer, intent(out)      :: funit
+  open(newunit=funit, status=fstatus)
+end subroutine open_file_safe