[flang][openacc] Use OpenACC terminator instead of fir.unreachable after Stop stmt...
[llvm-project.git] / flang / test / Lower / io-statement-2.f90
blob8634c14ca4c9c5cfe3b89955fcb8b5fc46b6d0c7
1 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
2 ! UNSUPPORTED: system-windows
4 character*10 :: exx
5 character*30 :: m
6 integer*2 :: s
7 exx = 'AA'
8 m = 'CCCCCC'
9 s = -13
10 ! CHECK: call {{.*}}BeginExternalFormattedInput
11 ! CHECK: call {{.*}}EnableHandlers
12 ! CHECK: call {{.*}}SetAdvance
13 ! CHECK: call {{.*}}InputReal
14 ! CHECK: call {{.*}}GetIoMsg
15 ! CHECK: call {{.*}}EndIoStatement
16 ! CHECK: fir.select %{{.*}} : index [-2, ^bb4, -1, ^bb3, 0, ^bb1, unit, ^bb2]
17 read(*, '(A)', ADVANCE='NO', ERR=10, END=20, EOR=30, IOSTAT=s, IOMSG=m) f
18 ! CHECK-LABEL: ^bb1:
19 exx = 'Zip'; goto 90
20 10 exx = 'Err'; goto 90
21 20 exx = 'End'; goto 90
22 30 exx = 'Eor'; goto 90
23 90 print*, exx, c, m, s
24 end
26 ! CHECK-LABEL: func @_QPcontrol0
27 subroutine control0(n) ! no I/O condition specifier control flow
28 dimension c(n), d(n,n), e(n,n), f(n)
29 ! CHECK-NOT: fir.if
30 ! CHECK: BeginExternalFormattedInput
31 ! CHECK-NOT: fir.if
32 ! CHECK: SetAdvance
33 ! CHECK-NOT: fir.if
34 ! CHECK: InputReal32
35 ! CHECK-NOT: fir.if
36 ! CHECK: InputReal32
37 ! CHECK-NOT: fir.if
38 ! CHECK: fir.do_loop
39 ! CHECK-NOT: fir.if
40 ! CHECK: InputReal32
41 ! CHECK-NOT: fir.if
42 ! CHECK: fir.do_loop
43 ! CHECK-NOT: fir.if
44 ! CHECK: InputReal32
45 ! CHECK-NOT: fir.if
46 ! CHECK: InputReal32
47 ! CHECK-NOT: fir.if
48 ! CHECK: InputReal32
49 ! CHECK-NOT: fir.if
50 ! CHECK: InputReal32
51 ! CHECK-NOT: fir.if
52 ! CHECK: EndIoStatement
53 ! CHECK-NOT: fir.if
54 read(*,'(F7.2)', advance='no') a, b, (c(j), (d(k,j), e(k,j), k=1,n), f(j), j=1,n), g
55 end
57 ! CHECK-LABEL: func @_QPcontrol1
58 subroutine control1(n) ! I/O condition specifier control flow
59 ! CHECK: BeginExternalFormattedInput
60 ! CHECK: EnableHandlers
61 ! CHECK: SetAdvance
62 ! CHECK: fir.if
63 ! CHECK: InputReal32
64 ! CHECK: fir.if
65 ! CHECK: InputReal32
66 ! CHECK: fir.if
67 ! CHECK: fir.iterate_while
68 ! CHECK: fir.if
69 ! CHECK: InputReal32
70 ! CHECK: fir.if
71 ! CHECK: fir.iterate_while
72 ! CHECK: fir.if
73 ! CHECK: InputReal32
74 ! CHECK: fir.if
75 ! CHECK: InputReal32
76 ! CHECK: fir.if
77 ! CHECK: InputReal32
78 ! CHECK: fir.if
79 ! CHECK: InputReal32
80 ! CHECK: EndIoStatement
81 dimension c(n), d(n,n), e(n,n), f(n)
82 read(*,'(F7.2)', iostat=mm, advance='no') a, b, (c(j), (d(k,j), e(k,j), k=1,n), f(j), j=1,n), g
83 end
85 ! CHECK-LABEL: func @_QPcontrol2
86 subroutine control2() ! I/O condition specifier control flow (use index result)
87 c = 1; d = 9
88 ! CHECK: BeginExternalFormattedOutput
89 ! CHECK: EnableHandlers
90 ! CHECK: :2 = fir.iterate_while
91 ! CHECK: = fir.if
92 ! CHECK: OutputReal
93 ! CHECK: = fir.if
94 ! CHECK: OutputReal
95 ! CHECK: fir.result
96 ! CHECK: else
97 ! CHECK: fir.result %false
98 ! CHECK: fir.result
99 ! CHECK: else
100 ! CHECK: fir.result %false
101 ! CHECK: = arith.addi %arg0, %c1
102 ! CHECK: = arith.select
103 ! CHECK: fir.result
104 ! CHECK: fir.if %{{[0-9]*}}#1
105 ! CHECK: OutputInteger
106 ! CHECK: EndIoStatement
107 write(*,'(8F4.1,I5)',iostat=m) (c,d,j=11,14), j
110 ! CHECK-LABEL: func @_QPcontrol3
111 subroutine control3 ! I/O condition specifier control flow
112 character(10) :: internal(2) = ['aaa','bbb']
113 integer stat, k(3)
114 ! CHECK: BeginInternalArrayListInput
115 ! CHECK: EnableHandlers
116 ! CHECK: InputDescriptor
117 ! CHECK: %[[V_15:[0-9]+]] = fir.call @_FortranAioEndIoStatement
118 ! CHECK: %[[V_16:[0-9]+]] = fir.convert %[[V_15]] : (i32) -> index
119 ! CHECK: fir.select %[[V_16]] : index [-2, ^bb1, -1, ^bb1, 0, ^bb1, unit, ^bb2]
120 read(internal,*,err=666,iostat=stat) k ! set stat to IOSTAT_END (-1)
121 ! CHECK: ^bb1: // 3 preds: ^bb0, ^bb0, ^bb0
122 ! CHECK: StopStatementText
123 ! CHECK: fir.unreachable
124 stop 'fallthrough -> ok'
125 ! CHECK: ^bb2: // pred: ^bb0
126 ! CHECK: BeginExternalListOutput
127 ! CHECK: OutputAscii
128 ! CHECK: EndIoStatement
129 666 print*, 'FAIL'
132 ! CHECK-LABEL: func @_QPloopnest
133 subroutine loopnest
134 integer :: aa(3,3)
135 aa = 10
136 ! CHECK: BeginExternalListOutput
137 ! CHECK: EnableHandlers
138 ! CHECK: {{.*}}:2 = fir.iterate_while ({{.*}} = {{.*}} to {{.*}} step {{.*}}) and ({{.*}} = {{.*}}) -> (index, i1) {
139 ! CHECK: fir.if {{.*}} -> (i1) {
140 ! CHECK: {{.*}}:2 = fir.iterate_while ({{.*}} = {{.*}} to {{.*}} step {{.*}}) and ({{.*}} = {{.*}}) -> (index, i1) {
141 ! CHECK: fir.if {{.*}} -> (i1) {
142 ! CHECK: OutputInteger32
143 ! CHECK: fir.result {{.*}} : i1
144 ! CHECK: } else {
145 ! CHECK: fir.result {{.*}} : i1
146 ! CHECK: }
147 ! CHECK: fir.result {{.*}}, {{.*}} : index, i1
148 ! CHECK: }
149 ! CHECK: fir.result {{.*}}#1 : i1
150 ! CHECK: } else {
151 ! CHECK: fir.result {{.*}} : i1
152 ! CHECK: }
153 ! CHECK: fir.result {{.*}}, {{.*}} : index, i1
154 ! CHECK: }
155 ! CHECK: EndIoStatement
156 write(*,*,err=66) ((aa(j,k)+j+k,j=1,3),k=1,3)
157 66 continue
160 ! CHECK-LABEL: func @_QPimpliedformat
161 subroutine impliedformat
162 ! CHECK: BeginExternalListInput(%c-1
163 ! CHECK: InputReal32
164 ! CHECK: EndIoStatement(%3) {{.*}}: (!fir.ref<i8>) -> i32
165 read*, x
166 ! CHECK: BeginExternalListOutput(%c-1
167 ! CHECK: OutputReal32
168 ! CHECK: EndIoStatement
169 print*, x