llvm / llvm/llvm-project

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

Open
#168,959 4 comments 0 reactions 0 assignees View on GitHub
flang:runtime
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

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)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.