xref: /llvm-project/flang/test/Lower/io-asynchronous.f90 (revision 4679132a85c6c4cced2a71ef6422b793ae39598c)
1! Test lowering of ASYNCHRONOUS variables and IO statements.
2! RUN: bbc -emit-hlfir -o - %s | FileCheck %s
3
4module test_async
5contains
6subroutine test(x, iounit, idvar, pending)
7  real, asynchronous :: x(10)
8  integer :: idvar, iounit
9  logical :: pending
10! CHECK-LABEL:   func.func @_QMtest_asyncPtest(
11! CHECK:           %[[VAL_4:.*]]:2 = hlfir.declare %{{.*}}idvar
12! CHECK:           %[[VAL_5:.*]]:2 = hlfir.declare %{{.*}}iounit
13! CHECK:           %[[VAL_6:.*]]:2 = hlfir.declare %{{.*}}pending
14! CHECK:           hlfir.declare %{{.*}}fir.var_attrs<asynchronous>{{.*}}x
15
16  open(unit=iounit, asynchronous='yes')
17! CHECK:           %[[VAL_10:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i32>
18! CHECK:           %[[VAL_14:.*]] = fir.call @_FortranAioBeginOpenUnit(%[[VAL_10]]
19! CHECK:           %[[VAL_20:.*]] = fir.call @_FortranAioSetAsynchronous(%[[VAL_14]]
20! CHECK:           %[[VAL_21:.*]] = fir.call @_FortranAioEndIoStatement(%[[VAL_14]])
21
22  write(unit=iounit,id=idvar, asynchronous='yes', fmt=*) x
23! CHECK:           %[[VAL_22:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i32>
24! CHECK:           %[[VAL_26:.*]] = fir.call @_FortranAioBeginExternalListOutput(%[[VAL_22]],
25! CHECK:           %[[VAL_32:.*]] = fir.call @_FortranAioSetAsynchronous(%[[VAL_26]],
26! CHECK:           %[[VAL_36:.*]] = fir.call @_FortranAioOutputDescriptor(%[[VAL_26]],
27! CHECK:           %[[VAL_37:.*]] = fir.call @_FortranAioGetAsynchronousId(%[[VAL_26]])
28! CHECK:           fir.store %[[VAL_37]] to %[[VAL_4]]#1 : !fir.ref<i32>
29! CHECK:           %[[VAL_38:.*]] = fir.call @_FortranAioEndIoStatement(%[[VAL_26]])
30
31  inquire(unit=iounit, id=idvar, pending=pending)
32! CHECK:           %[[VAL_39:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i32>
33! CHECK:           %[[VAL_43:.*]] = fir.call @_FortranAioBeginInquireUnit(%[[VAL_39]],
34! CHECK:           %[[VAL_44:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i32>
35! CHECK:           %[[VAL_46:.*]] = fir.convert %[[VAL_6]]#1 : (!fir.ref<!fir.logical<4>>) -> !fir.ref<i1>
36! CHECK:           %[[VAL_47:.*]] = fir.call @_FortranAioInquirePendingId(%[[VAL_43]], %[[VAL_44]], %[[VAL_46]])
37! CHECK:           %[[VAL_48:.*]] = fir.convert %[[VAL_6]]#1 : (!fir.ref<!fir.logical<4>>) -> !fir.ref<i1>
38! CHECK:           %[[VAL_49:.*]] = fir.load %[[VAL_48]] : !fir.ref<i1>
39! CHECK:           %[[VAL_50:.*]] = fir.convert %[[VAL_49]] : (i1) -> !fir.logical<4>
40! CHECK:           fir.store %[[VAL_50]] to %[[VAL_6]]#1 : !fir.ref<!fir.logical<4>>
41! CHECK:           %[[VAL_51:.*]] = fir.call @_FortranAioEndIoStatement(%[[VAL_43]])
42
43  wait(unit=iounit, id=idvar)
44! CHECK:           %[[VAL_52:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i32>
45! CHECK:           %[[VAL_53:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i32>
46! CHECK:           %[[VAL_57:.*]] = fir.call @_FortranAioBeginWait(%[[VAL_52]], %[[VAL_53]]
47! CHECK:           %[[VAL_58:.*]] = fir.call @_FortranAioEndIoStatement(%[[VAL_57]])
48end subroutine
49end module
50
51  use test_async
52  real :: x(10) = 1.
53  integer :: iounit = 100
54  integer :: idvar
55  logical :: pending = .true.
56  call test(x, iounit, idvar, pending)
57  print *, idvar, pending
58end
59