https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128720

--- Comment #3 from Suvarchal Cheedela (AWI) <suvarchal.cheedela at awi dot de> 
---
On 11/16/26 22:03, jvdelisle at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128720
>
> Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:
>
>             What    |Removed                     |Added
> ----------------------------------------------------------------------------
>       Ever confirmed|0                           |1
>               Status|UNCONFIRMED                 |NEW
>     Last reconfirmed|                            |2026-11-16
>                   CC|                            |jvdelisle at gcc dot gnu.org
>
> --- Comment #2 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
> The crash is real; trunk segfaults in 3 out of 3 runs. But the program is
> invalid: F2023 12.6.4.8.3 ¶19 forbids an async parent statement. So this is a
> crash on invalid code. Suvarchal, was this your intent with the reproducer?
No, I missed that; you are right, the reproducer is not conforming.
A segfault still seems worse than a defined behaviour, so the patch
completes such a statement synchronously (transfer_derived reports an
error as a fallback).  If you prefer an error over the synchronous 
completion, I can
change that in the next version.  The commit message there says "as the
standard permits", which is wrong; I will say that the program is not
conforming.

>
> The patch also fixes this the following which is valid I think:
Thanks, I can reproduce it: gfortran 15.2 prints 1.0 2.0 and FAIL, and
with my patch (2/4 of the series) it prints 1.0 3.0.  On trunk,
st_read_done did nothing for a synchronous READ on a unit opened with
ASYNCHRONOUS='yes', so st_read_done_worker was never called and the
statement did not move to the next record.  The patch calls it in that
case, which is the valid-code part of the fix.  I have changed its
commit message to say both: the original program is not conforming,
and the patch fixes wrong code for valid programs.
Perhaps the summary could become "Synchronous READ on an asynchronous
unit does not advance the record; defined I/O in an asynchronous
statement crashes".

Shall I post a v2 of this patch with the updated commit message to
gcc-patches, or wait for your review of the series?
>
> program p
>    implicit none
>    real :: x, y, z(2)
>    open (10, file='syncread.dat', form='unformatted', asynchronous='yes',
> status='replace')
>    write (10) 1.0, 2.0
>    write (10) 3.0, 4.0
>    rewind (10)
>    read (10) x          ! partial record, synchronous
>    read (10) y          ! must be 3.0
>    print *, x, y
>    if (y /= 3.0) print *, 'FAIL: record not advanced'
>    rewind (10)
>    read (10, asynchronous='yes') z
>    wait (10)
>    print *, z
>    close (10, status='delete')
> end program p
Thanks a ton,
Suvarchal

Reply via email to