Skip to content

[flang] DTIO: Illegal instruction when reading stream access file from a specified position #168959

@DanielCChen

Description

@DanielCChen

Consider the following code:

module m1
   type, abstract :: base
      character(3) :: c = ''
      contains
         procedure, pass :: setC
   end type

   type, extends(base) :: child
      character(3) :: cc = ''
   end type

contains
   subroutine setC (a, char)
      class(base), intent(inout) :: a
      character(3), intent(in) :: char
      a%c = char
   end subroutine
end module


program array001a
   use m1
   interface read(unformatted)
      subroutine readUnformatted (dtv, unit, iostat, iomsg)
         import base
         class(base), intent(inout) :: dtv
         integer,  intent(in) :: unit
         integer,  intent(out) :: iostat
         character(*),  intent(inout) :: iomsg
      end subroutine
   end interface

   class(base) , allocatable :: b1(:)
   integer :: stat
   character(200) :: msg

   allocate ( b1(4), source = (/ child('xxx','XXX'), child('xxx','XXX'), child('xxx','XXX'), child('xxx','XXX') /) )

   open (unit = 1, file ='array001a.data', form='unformatted', access='stream')

   write (1, iostat=stat, iomsg=msg, pos=31 )             'ghiGHIdefDEFjklJKLabcABC'
   write (1, iostat=stat, iomsg=msg, pos=19 )             'ABCabcDEFdef'
   write (1, iostat=stat, iomsg=msg, pos=13 )             'stuSTU'
   write (1, iostat=stat, iomsg=msg, pos=1  )             'MNOmnoSTUstu'

   read (1, iostat=stat, iomsg=msg, pos=31 )              b1((/3,2,4,1/))
   close ( 1, status ='delete' )

end program

subroutine readUnformatted (dtv, unit, iostat, iomsg)
use m1
   class(base), intent(inout) :: dtv
   integer, intent(in) :: unit
   integer, intent(out) :: iostat
   character(*), intent(inout) :: iomsg

   character(3) :: temp

   read (unit, iostat=iostat ) temp

   call dtv%setC(temp)

   select type (dtv)
      type is (child)
         read (unit, iostat=iostat ) dtv%cc
   end select
end subroutine

Flang failed at the read statement with

> a.out
Illegal instruction(coredump)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions