Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / io-statement-2.f90
blob58c8ce3d02a61c444b5a81602a7833fa8475f375
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 @_QPloopnest
111 subroutine loopnest
112 integer :: aa(3,3)
113 aa = 10
114 ! CHECK: BeginExternalListOutput
115 ! CHECK: EnableHandlers
116 ! CHECK: {{.*}}:2 = fir.iterate_while ({{.*}} = {{.*}} to {{.*}} step {{.*}}) and ({{.*}} = {{.*}}) -> (index, i1) {
117 ! CHECK: fir.if {{.*}} -> (i1) {
118 ! CHECK: {{.*}}:2 = fir.iterate_while ({{.*}} = {{.*}} to {{.*}} step {{.*}}) and ({{.*}} = {{.*}}) -> (index, i1) {
119 ! CHECK: fir.if {{.*}} -> (i1) {
120 ! CHECK: OutputInteger32
121 ! CHECK: fir.result {{.*}} : i1
122 ! CHECK: } else {
123 ! CHECK: fir.result {{.*}} : i1
124 ! CHECK: }
125 ! CHECK: fir.result {{.*}}, {{.*}} : index, i1
126 ! CHECK: }
127 ! CHECK: fir.result {{.*}}#1 : i1
128 ! CHECK: } else {
129 ! CHECK: fir.result {{.*}} : i1
130 ! CHECK: }
131 ! CHECK: fir.result {{.*}}, {{.*}} : index, i1
132 ! CHECK: }
133 ! CHECK: EndIoStatement
134 write(*,*,err=66) ((aa(j,k)+j+k,j=1,3),k=1,3)
135 66 continue
138 ! CHECK-LABEL: func @_QPimpliedformat
139 subroutine impliedformat
140 ! CHECK: BeginExternalListInput(%c-1
141 ! CHECK: InputReal32
142 ! CHECK: EndIoStatement(%3) {{.*}}: (!fir.ref<i8>) -> i32
143 read*, x
144 ! CHECK: BeginExternalListOutput(%c-1
145 ! CHECK: OutputReal32
146 ! CHECK: EndIoStatement
147 print*, x