Skip to content

[flang][NML] Flang failed reading nested namelist #153416

@DanielCChen

Description

@DanielCChen

Consider the following reducer:

module m

   type data
      integer(4) :: i = -999
   end type

   type :: base
      character(3) ::  c = 'xxx'
      class(data), 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(data), 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)
print*, "iostat=", stat
print*, "iomsg=", msg
   if ( stat /=  0 ) error stop 1

end program main

subroutine readformatted (dtv, unit, iotype, v_list, iostat, iomsg)
   use m, only: base, data, 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(data), allocatable :: x1
   namelist /dtio/ x1                      !! Nested namelist
   read (unit, *, iostat=iostat, iomsg=iomsg )        dtv%c
print*, "dtv%c=", dtv%c

   allocate ( x1, source = dtv%d )
   read (unit, dtio, iostat=iostat, iomsg = iomsg )
print*, "dtio=", x1%i

end subroutine

subroutine readformatteddata (dtv, unit, iotype, v_list, iostat, iomsg)
   use m, only: data

   class(data), 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 (data)
         error stop 22
      type is (data)
         read (unit, *, iostat=iostat, iomsg=iomsg )        dtv%i
   end select

end subroutine

The input data file data.1 is

 &NML1
 B1= b11 &DTIO
 X1=1001
 / b12 &DTIO
 X1=1002
 /
 /

Those print statements are to show what the expected output should be.

Flang failed at execution when reading the nested namelist namelist /dtio/ x1 as

> a.out
 dtv%c=b11
 dtio= -999
 iostat= 1001
 iomsg=No '/' found after NAMELIST group 'dtio'


Fortran ERROR STOP: code 1

Expected output:

> a.out
 dtv%c=b11
 dtio=        1001
 dtv%c=b12
 dtio=        1002
 iostat=           0
 iomsg=

Both gfortran and XLF produce the correct result.

Metadata

Metadata

Assignees

Labels

flang:frontendquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions