Skip to content

[flang][runtime] DTIO failure with T, TL edit. #160365

@DanielCChen

Description

@DanielCChen

Consider the following code

module m

   type base
      integer(4)   :: id
      character(3) :: name = ''
   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

   integer(4) :: intres1, intres2
   character(3) :: charres1, charres2
end module

program position101
   use m

   integer :: stat
   character(200) :: msg = ''
   type (base)              :: b3

   namelist /nml/  b3

   b3 = base ( 303, 'FTN')

   open (1, file = 'position101.1', form='formatted', access='sequential' )

   read (1,NML=nml, iostat=stat, iomsg=msg)
print*, intres1
print*, charres1
print*, intres2
print*, charres2
print*, intres1
print*, charres1
print*, intres2
print*, charres2
   if ( stat /=  0 ) ERROR STOP 1

end program


subroutine readformatted (dtv, unit, iotype, v_list, iostat, iomsg)
   use m, only: base, intres1, intres2, charres1, charres2

   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

   read ( unit, "(T9,I4,TL8,A3,/)", iostat = iostat, iomsg=iomsg )      dtv%id, dtv%name
print*, iostat
print*, iomsg
   intres1 = dtv%id
   charres1 = dtv%name

   ! read one more time in reverse order
   read ( unit, "(T1, I4, TR1, 1X, A3)", iostat = iostat ) dtv%id, dtv%name
   intres2 = dtv%id
   charres2 = dtv%name

end subroutine

The input file position101.1 is as:

 &NML
 b3= xxx,-999
 103, ghi
 /

Flang failed at the first read statement in the DTIO procedure and outputs

> a.out
 -2
 End of record during non-advancing input

 303
 FTN
 303
 FTN
 303
 FTN
 303
 FTN
Fortran ERROR STOP: code 1

The expected output:

> a.out
 0
 xxx
 103
 ghi
 0
 xxx
 103
 ghi

This seems a recent regression as the full test case had passed a couple of weeks ago.

Metadata

Metadata

Assignees

Labels

flang:runtimequestionA 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