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

    <tr>
        <th>Summary</th>
        <td>
            [flang] Runtime DTIO lacking support for `-fdefault-integer-8`
        </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 code
```
module m

   type base
      sequence
 integer(4) :: i
   end type

end module

program scalar007
use m

 type(base), allocatable :: b1

   integer :: stat = 0
   character(150) :: msg = "original"

   interface write(formatted)
      subroutine writeformatted(dtv, unit, iotype, v_list, iostat, iomsg )
         import base
         type(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
      end subroutine
   end interface

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

   allocate ( b1, source = base(4) )

   write ( 1, *, iostat = stat, iomsg = msg ) b1
end program

subroutine writeformatted (dtv, unit, iotype, v_list, iostat, iomsg)
use m!, only: base, data

   type(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

   print*, unit
   !write ( unit=unit, fmt=* ) ' Data not using DTIO: v_list is:', v_list
end subroutine
```

When compile the code with `-fdefault-integer-8`, Flang failed at runtime as
```
> a.out
 4563402751

fatal Fortran runtime error(t.f:48): UNIT number 4563402751 is out of range
IOT/Abort trap(coredump)
```

It worked fine if I removed the `-fdefault-integer-8` option. 
It seems the runtime routine `_FortranAioCheckUnitNumberInRange64` isn't expecting a `i64` UNIT number.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycltFu6jgTx5_G3Iy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