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

            Bug ID: 128720
           Summary: Segfault with defined I/O (DTIO) in an asynchronous
                    data transfer statement
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: suvarchal.cheedela at awi dot de
  Target Milestone: ---

Created attachment 66162
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66162&action=edit
program to show dtio issue

An asynchronous WRITE (or READ) of a derived type with a defined
unformatted I/O procedure crashes.  transfer_derived stores the DTIO
procedure in the caller's st_parameter_dt, but the I/O thread works on its
own copy, which never gets it.  Also present on trunk (17.0.0 20261113).

$ gfortran -O2 -pthread dtio_async.f90 && ./a.out
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Expected: OK (a processor may also perform the transfer synchronously).

--- dtio_async.f90 ---
! A derived type with defined (DTIO) I/O in an asynchronous WRITE.
! Stock gfortran crashes with a segmentation fault.
module m
  implicit none
  type :: pt
     real :: x, y
   contains
     procedure :: w => wr
     generic :: write(unformatted) => w
  end type pt
contains
  subroutine wr (d, u, ios, msg)
    class(pt), intent(in) :: d
    integer, intent(in) :: u
    integer, intent(out) :: ios
    character(*), intent(inout) :: msg
    write (u, iostat=ios, iomsg=msg) d%x, d%y
  end subroutine wr
end module m

program dtio_async
  use m
  implicit none
  type(pt), asynchronous :: a
  integer :: id
  a = pt(3.0, 4.0)
  open (10, file='dtio_async.bin', form='unformatted', asynchronous='yes', &
        status='replace')
  write (10, asynchronous='yes', id=id) a
  wait (10, id=id)
  close (10, status='delete')
  print '(a)', 'OK'
end program dtio_async

Reply via email to