Issue 168959
Summary [flang] DTIO: Illegal instruction when reading stream access file from a specified position
Labels flang:runtime
Assignees
Reporter 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)
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to