Skip to content

[flang] Failure when reading 3 level of nested namelist. #154843

@DanielCChen

Description

@DanielCChen

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions