<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/155277>155277</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang] Missing blank separator between components when DTIO is used for one of the derived type component
        </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 base
      character(3) :: c = 'xxx'
      contains
         procedure, pass :: write => writeb
 generic :: write(formatted) => write
   end type

   type container
 integer :: i = -999
      type(base) :: b = base()
   end type

 contains

      subroutine writeb (dtv, unit, iotype, v_list, iostat, iomsg)
         class(base), intent(in) :: dtv
         integer, intent(in) :: unit
         character(*), intent(in) :: iotype
         integer, intent(in)  :: v_list(:)
         integer, intent(out) :: iostat
 character(*), intent(inout) :: iomsg

         write (unit, "(A3)", iostat=iostat, iomsg=iomsg) dtv%c

      end subroutine

end module

program array002
   use m

   type(container), allocatable :: b1(:)
   integer :: stat
   character(200) :: msg

   allocate ( b1(3), source = (/ container( 101, base('abc') ), container( 102, base('def') ), container( 103, base('ghi') ) /) )

   write ( 6, *, iostat = stat, iomsg = msg )             b1((/1,2,3/))
   if ( stat /= 0 ) ERROR STOP 1

end program
```

Flang outputs:
```
> a.out
 101abc 102def 103ghi
```

If I removed the DTIO for type `base`, as:
```
module m

 type base
      character(3) :: c = 'xxx'
   end type

   type container
      integer :: i = -999
      type(base) :: b = base()
   end type

end module

program array002
   use m

   type(container), allocatable :: b1(:)
   integer :: stat
   character(200) :: msg

 allocate ( b1(3), source = (/ container( 101, base('abc') ), container( 102, base('def') ), container( 103, base('ghi') ) /) )

   write ( 6, *, iostat = stat, iomsg = msg )             b1((/1,2,3/))
   if ( stat /= 0 ) ERROR STOP 1

end program
```

Flang outputs 
```
> a.out
 101 abc 102 def 103 ghi
```

The expected behavior is to have a blank between the components.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVs2OqzYUfhqzOZrImJCQBQs6uZFmUU01nX1l4ABuwUa2ycy8fWWbBJI7vfdKVaVWahSJ-OT8fd_5MdwY0UrEnKQ_kfQY8cl2SudHLgX2j48dyqhU9Uf-qKQRNWqwHUKj-l69CdmCxnqqUJOkILQgOzp_aTGoeuoRBiemBQDYjxGh5AbDEQCqjmteWdSEZQlhB3BekgIqIMkRCNu_v78Ttl_0lbRcSHMVAMCoVYX1pJGwRxi5MRcnb1pYdI5I8iUcSmfXokQtqhstwrJG6YFbi3VIYzEKsVDWPv9bMHM-qJ1MSIst6otj4TE8HA6Ha7beAcs8BQvY0isGYUbY4dOAK-RXd2YqtZqskDjDA8Ky2p4dEZMU1j2FCkEf4fxbL8wsM5bPvwbTXkPOHPfcmCVLryYtSktYJuQqbxdpZTfD_2t9n9I60Kr4hBXfjDXD-KFwF5sL4MydbzF-ZqwmexPQc-SY_16a94aO0lWVAC6dyLJLVQhjhGVF4p2xVU2S431xnCQUyRPO0mrt3HXJ0gbhHycLsxfOo1at5gNwrfkHpSwYT-Z-NAnLln4OKHnfq4pbXvZ47db4jtG7tr_QdltfRumKozVDcwhPT3CezMGNmnSF8ybICDutxo1lENPYaV3nZs_Lyu0KFyY4uFNnt-o1Nt9UT27V204s6kDY6WJ5AXItMuxCiYulrh7ETV29xD9dx64-gV-P1-FzSSch2sJ448MEx-zkPFHv58vLy_ML_Pr6_AvESy_M9b_bzoQWp57LFtRkx8mar_e324B847qbFo5tXlaOxRobx47j4yuPTw08gcZBnbH218Tx9ekZGqXDuiQ76gndUd9cn8S8uzP-5o3xA0t7vQ7-kc39X5rG_2fx3zGL8J1JhHkUYZ5F-HQYXzsEfB-xslhDiR0_C6VBGLAKOn5G4FD2XP4BJdo3ROkHtlLDqCRKazZRnSf1ITnwCPN4n-7ibbqN46jLkyyOt1nSxDXbxaypDzXyZlvF20PV7B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