<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/154130>154130</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] Fail to select the more specific type guard statement within DTIO.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DanielCChen
</td>
</tr>
</table>
<pre>
Consider the following reducer:
```
module m
type, abstract :: abstractdata
end type
type, extends(abstractdata) :: data
integer(4) :: i = -999
end type
type :: base
character(3) :: c = 'xxx'
class(abstractdata), allocatable :: d
end type
interface read(formatted)
subroutine readformatted(dtv, unit, iotype, v_list, iostat, iomsg )
import base
class(base), intent(inout) :: dtv
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
end subroutine
subroutine readformatteddata(dtv, unit, iotype, v_list, iostat, iomsg )
import data
class(abstractdata), intent(inout) :: dtv
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
end subroutine
end interface
end module m
program main
use m
type(base) :: b1(2)
type(base), allocatable :: b2(:)
namelist /nml1/ b1
integer :: stat
character(200) :: msg = ''
open (1, file = 'data.1', form='formatted', access='sequential' )
b1 = (/ base(d=data()), base(d=data()) /)
read (1,NML=nml1, iostat=stat, iomsg=msg)
if ( stat /= 0 ) error stop 1
end program main
subroutine readformatted (dtv, unit, iotype, v_list, iostat, iomsg)
use m, only: base, abstractdata, read(formatted), readformatteddata
class(base), intent(inout) :: dtv
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
class(abstractdata), allocatable :: x1
namelist /dtio/ x1 !! Nested namelist
read (unit, *, iostat=iostat, iomsg=iomsg ) dtv%c
allocate ( x1, source = dtv%d )
read (unit, dtio, iostat=iostat, iomsg = iomsg )
end subroutine
subroutine readformatteddata (dtv, unit, iotype, v_list, iostat, iomsg)
use m, only: abstractdata, data
class(abstractdata), intent(inout) :: dtv
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
select type ( dtv )
class is (abstractdata)
error stop 22
type is (data)
read (unit, *, iostat=iostat, iomsg=iomsg ) dtv%i
end select
end subroutine
```
Flang failed at:
```
> a.out
Fortran ERROR STOP: code 22
```
`dtv` has dynamic type `data`. It seems Flang failed to choose the more specific type guard statement of `type is (data)` within an DTIO procedure.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzcV1GP4rYT_zTmZXTIcQgkDzzwh0M66d_banvvlRM74CqJqe3ssd--GjuBhA3dK7cPVaPVAvbMeOY385uJubXq0Ei5Jsn_SLKb8dYdtVnveKNktd0eZTPLtXhdb3VjlZAG3FFCqatKf1fNAYwUbSENiTeEbsiSdn90U2vRVhJqXKYbAHCvJ0nYFnhuneGFA9SJN5ffgjuOkrIRQfZWUZ6dbIQlLB2psKy31Fvwj2qcPEhDWLoYiCgg8Q4-ZVkWBCcP64VzbuXFXnHkeKS3GA8sQuFNErY6n8-ErVChqLid8NNHX1W64I7n1eUYMeVKWMMgTMkLCUZyQVhaalNz56RAc71rts2Nbp1qgthAJhXuBU9tG-XwU-kezJffK2W7Net49622BxhaRhfqkzZujAXC0YXo10No6GzjCEtVo1s3zIt7GVnsM7OFoc5Awbs7PGyAPWGbt-cNM6w7EKfOu1HBp1Pr8Ujx9w0CE_rjADsI3_X4PkQe-r76r_l8N8Whsj4uzSMKDdI8Uckfn-5_TZp_Ns_vp9k_U7nGtQvrQx_ApXE3JXRzMvpgeA01V03QbG3Yv3TMnpuX4POIsJRdwh5L3WlOORuCFRQbXkuEEQjbN3UVEbZH28OmdZCmt9BDNoSKUTpAxZdj6KGhgQY7-i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