<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/154843>154843</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] Failure when reading 3 level of nested namelist.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:runtime
</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 data
integer :: k
end type
type container
integer :: j
type(data) :: d
end type
type base
integer :: i
type(container) :: c
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
end interface
end module
program position102kl
use m
integer :: stat
character(200) :: msg = ''
type(base) :: b1
type(base) :: b2
namelist /nml/ b1, b2
open (1, file = 'position102kl.1', form='formatted', access='sequential' )
read (1,NML=nml, iostat=stat, iomsg=msg)
if ( stat /= 0 ) ERROR STOP 1
end program
subroutine readformatted (dtv, unit, iotype, v_list, iostat, iomsg)
use m, only: base, container
interface read(formatted)
subroutine containerreadformatted(dtv, unit, iotype, v_list, iostat, iomsg )
import container
class(container), 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
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
type(container) :: c1
namelist /basedtio/ c1
read (unit, "(TL100, I4)", iostat=iostat, iomsg=iomsg) dtv%i
if ( iostat /= 0 ) ERROR STOP 6
read (unit, basedtio, iostat=iostat, iomsg=iomsg)
if ( iostat /= 0 ) ERROR STOP 7
end subroutine
subroutine containerreadformatted(dtv, unit, iotype, v_list, iostat, iomsg )
use m, only: container, data
interface read(formatted)
subroutine datareadformatted(dtv, unit, iotype, v_list, iostat, iomsg )
import data
class(data), intent(inout) :: dtv ! tcx: (4)
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
class(container), intent(inout) :: dtv ! tcx: (4,4)
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
type(data) :: d1
namelist /containerdtio/ d1
read (unit, "(TR10, T1,I4)", iostat=iostat) dtv%j
if ( iostat /= 0 ) ERROR STOP 10
read (unit, containerdtio, iostat=iostat, iomsg=iomsg)
end subroutine
subroutine datareadformatted(dtv, unit, iotype, v_list, iostat, iomsg )
use m, only: data
class(data), intent(inout) :: dtv ! tcx: (4)
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
read (unit, "(5X, TL99, I4)", iostat=iostat ) dtv%k
end subroutine
```
The input file `position102kl.1` is:
```
&NML
B1=1001 &BASEDTIO
C1=1002 &CONTAINERDTIO
D1=1003
/
/ B2=2001 &BASEDTIO
C1=2002 &CONTAINERDTIO
D1=2003
/
/
/
```
Flang failed at
```
> a.out
Fortran ERROR STOP: code 6
```
When both gfortran and XLF executed passed this point.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsmEtv2zgQgH8NfRnUoEaWLR98UKQYKJBtFmmA7W1BS5TNViK9IpW2_34xetjyq4mzyWIPWxhVxOEMh_P4RElYq9ZaygULbliQjETtNqZaJEIrWcTxRurRymQ_F7HRVmWyAreRkJuiMN-VXkMlszqVFfMjxiM25d2PR6XJ6kJCyXgEAO7nVkImnGhvAUBpJ9eyAtL0I_hGAqmzZiaZ2qulRjuhtKwu6X7dC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