[Flang] Wrong result for formatted write to internal file for empty derived type
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Flang does not blank-fill an internal character record after a formatted list-directed write of an empty derived type. Per Fortran standard, unused positions in the record should be filled with blanks.
Expected Behavior: After write(str, *) of an empty derived type, str is all blanks; program prints T and exits normally.
Actual Behavior: str retains non-blank characters; program stops with Fortran STOP: expecting all blanks.
Reproducer:
```Fortran
program test
implicit none
type empty
end type empty
integer, parameter :: n = 3
integer :: rst(n), expect(n)
type(empty), parameter :: e1 = empty()
type(empty), parameter :: e3(3) = [empty(), empty(), e1]
rst = 0
expect(1) = 1
expect(2) = 2
expect(3) = 3
rst(1) = func([empty()])
rst(2) = func([empty(), e1])
rst(3) = func(e3)
Print *, All(rst .eq. expect)
contains
integer function func(a)
type(empty), intent(in) :: a(:)
character(10) :: str = 'abcdefghij'
write(str, *) a ! 12.4 ,para 2, filled with blanks
if (str /= '') STOP "expecting all blanks"
func = size(a)
end
end program
```
Contributor guide
Assessment
This issue has not been assessed yet.