<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/144363>144363</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] DTIO: Flang generates code to reference DTIO routines even there is not READ or WRITE in source code.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DanielCChen
</td>
</tr>
</table>
<pre>
Consider the following reducer:
```
module m1
type :: base
! empty type
end type
interface read(unformatted)
subroutine readUnformattedbase (dtv, unit, iostat, iomsg)
import base
class(base), intent(inout) :: dtv
integer, intent(in) :: unit
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
end subroutine
end interface
interface write(unformatted)
subroutine writeUnformattedbase (dtv, unit, iostat, iomsg)
import base
class(base), intent(in) :: dtv
integer, intent(in) :: unit
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
end subroutine
end interface
end module
program test
use m1
type(base), allocatable :: b1
allocate ( b1 )
open ( 2, file = 'test.data', form='unformatted', access='sequential' )
inquire ( iolength = length1 ) b1
close ( 2, status ='delete' )
end program
```
There is not READ or WRITE in the code, but Flang has
```
ld: 0711-317 ERROR: Undefined symbol: readunformattedbase_
ld: 0711-317 ERROR: Undefined symbol: writeunformattedbase_
```
Further more, if I provide the following implementation of the DTIO routines,
```
subroutine readUnformattedbase (dtv, myunit, iostat, iomsg)
use m1, only: base
class(base), intent(inout) :: dtv
integer, intent(in) :: myunit
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
integer :: length1
select type (dtv)
type is (base)
inquire ( iolength = length1 ) dtv
end select
end subroutine
subroutine writeUnformattedbase (dtv, myunit, iostat, iomsg)
use m1, only: base
class(base), intent(in) :: dtv
integer, intent(in) :: myunit
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
integer :: length1
select type (dtv)
type is (base)
inquire ( iolength = length1 ) dtv
end select
end subroutine
```
Flang coredumps at runtime at the `inquire` statement
```
fatal Fortran runtime error(t.f:39): Defined unformatted I/O without an external unit
IOT/Abort trap(coredump)
```
All ifort, gfortran and XLF compiles and executes the code successfully.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVktr5DgQ_jXqSzGNLffz0AdvegyBhUDIsHtbZLtsa5Elj1TKTP_7RbL7OUkmM-S40NB2ValeX9UnC-dkqxF3bPkHW-5nwlNn7G4vtER1d9ehnpWmPuzujHayRgvUITRGKfNN6hYs1r5Cy7KcJTlbJdMvyXtTe4XQp0Ge5ABAhwEhGGY5lMLhKAUAxlPAfqBDNBnFqOvj2yiQmtA2okKwKGrGN143xvaCCGvGtydnzpfWeJJ6NPxytgoxgfFNTc-M34HXksK_NI7E9NS79tJXCNsPxtIp30oJ5xjfxHe-jac0oSbGN1IbT4xvjzWGOJeeNGGLNhy5PHNxIGaU5C9bXvuekr5wX3XCiorCsQ3j-ZTc69mNxR4dhHafO3eG4NT1F3D4ZiXhu4CIlh-MxKnuNxH5EY73w_AmcK_B8cEwvIpEEI0rNr4P1rRW9EDopuS9-2H7rtsklDKVIFGq81qe7SdtxAnKFEY0Rp0ZUEc5D34aGR3sgfF1CD-vBQnG11FnbM-yPePrqymJOlFV6NyodfjVoyYpFOPrq1hSf_XSjmlIo1C31MVo42NMDC4Tr5QZp2vMLgDjHYxhalQYZvYiRGjk1LwbBmNJ_tShRZAOtCF4_JzvwVj46_H-6TNIHZmwMjWGMKUnKJTQLXTC3ThSdehtsk7TT1m6hs-Pjw-PQfJF19hIjTW4Q18aFWSBs_z1pvzziy7itr3g46a2wlvq0EJvbKxANnAfOvEsa7whedkPCnvUJEgaDaaJ-v3T_QNMo-qCh5sY72bi_vAmA0yDzO_AaHW4vj1-i48vFvplBpgSetX4dS5-ef1_uv1XoY7KacBPaocKK5qu0al5Z4aMYungohlXHPaOLTo1KNJQjHbekVtaugb4Jwz_2wj_Krv_D-4HgHvDE5HVKhO-9PrBgSCwXpPsMTw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