]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fixes a hang on an invalid ID in a WAIT statement.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 23 May 2020 17:01:43 +0000 (19:01 +0200)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Wed, 27 May 2020 14:39:11 +0000 (16:39 +0200)
gcc/fortran/ChangeLog:

2020-05-23  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR libfortran/95191
* libgfortran.h (libgfortran_error_codes): Add
LIBERROR_BAD_WAIT_ID.

libgfortran/ChangeLog:

2020-05-23  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR libfortran/95191
* io/async.c (async_wait_id): Generate error if ID is higher
than the highest current ID.
* runtime/error.c (translate_error): Handle LIBERROR_BAD_WAIT_ID.

libgomp/ChangeLog:

2020-05-23  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR libfortran/95191
* testsuite/libgomp.fortran/async_io_9.f90: New test.

(cherry picked from commit 8df7ee67f6fdc780e9453f2baa8d1bf62c000761)

gcc/fortran/libgfortran.h
libgfortran/io/async.c
libgfortran/runtime/error.c
libgomp/testsuite/libgomp.fortran/async_io_9.f90 [new file with mode: 0644]

index 581b2f529dbf13ed2c1af47b9f27f9906add77f3..02250fab4be33f903eb6e35514dd1949dfe12e67 100644 (file)
@@ -122,6 +122,7 @@ typedef enum
   LIBERROR_SHORT_RECORD,
   LIBERROR_CORRUPT_FILE,
   LIBERROR_INQUIRE_INTERNAL_UNIT, /* Must be different from STAT_STOPPED_IMAGE.  */
+  LIBERROR_BAD_WAIT_ID,
   LIBERROR_LAST                        /* Not a real error, the last error # + 1.  */
 }
 libgfortran_error_codes;
index 28b84f6613ae62bebdfd9dc4ffe07eeee640b531..5af919bd71c893f5af4ac03eec18378661841e51 100644 (file)
@@ -424,6 +424,13 @@ async_wait_id (st_parameter_common *cmp, async_unit *au, int i)
     }
 
   LOCK (&au->lock);
+  if (i > au->id.high)
+    {
+      generate_error_common (cmp, LIBERROR_BAD_WAIT_ID, NULL);
+      UNLOCK (&au->lock);
+      return true;
+    }
+
   NOTE ("Waiting for id %d", i);
   if (au->id.waiting < i)
     au->id.waiting = i;
index 0335a165edc7cd4afa6544cb80d0dc28539a93ed..1dea2f0e5f85fd105d34dbff3588e52f09726d17 100644 (file)
@@ -616,6 +616,10 @@ translate_error (int code)
       p = "Inquire statement identifies an internal file";
       break;
 
+    case LIBERROR_BAD_WAIT_ID:
+      p = "Bad ID in WAIT statement";
+      break;
+
     default:
       p = "Unknown error code";
       break;
diff --git a/libgomp/testsuite/libgomp.fortran/async_io_9.f90 b/libgomp/testsuite/libgomp.fortran/async_io_9.f90
new file mode 100644 (file)
index 0000000..2dc111c
--- /dev/null
@@ -0,0 +1,20 @@
+! { dg-do run }
+! PR 95191 - this used to hang.
+! Original test case by Bill Long.
+program test
+  real a(10000)
+  integer my_id
+  integer bad_id
+  integer :: iostat
+  character (len=100) :: iomsg
+  data my_id /1/
+  data bad_id /2/
+  a = 1.
+  open (unit=10, file='test.dat', form='unformatted', &
+       &                asynchronous='yes')
+  write (unit=10, asynchronous='yes', id=my_id) a
+  iomsg = ""
+  wait (unit=10, id=bad_id, iostat=iostat, iomsg=iomsg)
+  if (iostat == 0 .or. iomsg /= "Bad ID in WAIT statement") stop 1
+  close (unit=10, status='delete')
+end program test