1 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
3 ! CHECK-LABEL: sinteger
7 ! CHECK: fir.select_case {{.*}} : i32
8 ! CHECK-SAME: upper, %c1
9 ! CHECK-SAME: point, %c2
10 ! CHECK-SAME: point, %c3
11 ! CHECK-SAME: interval, %c4{{.*}} %c5
12 ! CHECK-SAME: point, %c6
13 ! CHECK-SAME: point, %c7
14 ! CHECK-SAME: interval, %c8{{.*}} %c15
15 ! CHECK-SAME: lower, %c21
36 ! CHECK-LABEL: slogical
37 subroutine slogical(L
)
52 ! CHECK: cmpi eq, {{.*}} %false
59 ! CHECK: cmpi eq, {{.*}} %true
71 ! CHECK: cmpi eq, {{.*}} %false
75 ! CHECK: cmpi eq, {{.*}} %true
82 ! CHECK: cmpi eq, {{.*}} %false
91 ! CHECK: cmpi eq, {{.*}} %true
100 ! CHECK: cmpi eq, {{.*}} %false
104 ! CHECK: cmpi eq, {{.*}} %true
108 ! CHECK-NOT: constant 888
113 print*, n1
, n2
, n3
, n4
, n5
, n6
, n7
, n8
116 ! CHECK-LABEL: scharacter
117 subroutine scharacter(c
)
123 ! CHECK: CharacterCompareScalar1
124 ! CHECK-NEXT: constant 0
125 ! CHECK-NEXT: cmpi sle, {{.*}} %c0
126 ! CHECK-NEXT: cond_br
129 ! CHECK: CharacterCompareScalar1
130 ! CHECK-NEXT: constant 0
131 ! CHECK-NEXT: cmpi sge, {{.*}} %c0
132 ! CHECK-NEXT: cond_br
133 ! CHECK: CharacterCompareScalar1
134 ! CHECK-NEXT: constant 0
135 ! CHECK-NEXT: cmpi sle, {{.*}} %c0
136 ! CHECK-NEXT: cond_br
139 ! CHECK: CharacterCompareScalar1
140 ! CHECK-NEXT: constant 0
141 ! CHECK-NEXT: cmpi eq, {{.*}} %c0
142 ! CHECK-NEXT: cond_br
145 ! CHECK: CharacterCompareScalar1
146 ! CHECK-NEXT: constant 0
147 ! CHECK-NEXT: cmpi eq, {{.*}} %c0
148 ! CHECK-NEXT: cond_br
151 ! CHECK: CharacterCompareScalar1
152 ! CHECK-NEXT: constant 0
153 ! CHECK-NEXT: cmpi sge, {{.*}} %c0
154 ! CHECK-NEXT: cond_br
161 ! CHECK-LABEL: func @_QPscharacter1
162 subroutine scharacter1(s
)
163 ! CHECK-DAG: %[[V_0:[0-9]+]] = fir.alloca !fir.box<!fir.heap<!fir.char<1,?>>>
164 character(len
=3) :: s
165 ! CHECK-DAG: %[[V_1:[0-9]+]] = fir.alloca i32 {bindc_name = "n", uniq_name = "_QFscharacter1En"}
166 ! CHECK: fir.store %c0{{.*}} to %[[V_1]] : !fir.ref<i32>
169 ! CHECK: %[[V_8:[0-9]+]] = fir.call @_FortranACharacterCompareScalar1
170 ! CHECK: %[[V_9:[0-9]+]] = arith.cmpi sge, %[[V_8]], %c0{{.*}} : i32
171 ! CHECK: cond_br %[[V_9]], ^bb1, ^bb16
172 ! CHECK: ^bb1: // pred: ^bb0
173 if (lge(s
,'00')) then
175 ! CHECK: %[[V_18:[0-9]+]] = fir.load %[[V_0]] : !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>
176 ! CHECK: %[[V_20:[0-9]+]] = fir.box_addr %[[V_18]] : (!fir.box<!fir.heap<!fir.char<1,?>>>) -> !fir.heap<!fir.char<1,?>>
177 ! CHECK: %[[V_42:[0-9]+]] = fir.call @_FortranACharacterCompareScalar1
178 ! CHECK: %[[V_43:[0-9]+]] = arith.cmpi eq, %[[V_42]], %c0{{.*}} : i32
179 ! CHECK: fir.if %[[V_43]] {
180 ! CHECK: fir.freemem %[[V_20]] : !fir.heap<!fir.char<1,?>>
182 ! CHECK: cond_br %[[V_43]], ^bb3, ^bb2
183 ! CHECK: ^bb2: // pred: ^bb1
191 ! CHECK: %[[V_48:[0-9]+]] = fir.call @_FortranACharacterCompareScalar1
192 ! CHECK: %[[V_49:[0-9]+]] = arith.cmpi eq, %[[V_48]], %c0{{.*}} : i32
193 ! CHECK: fir.if %[[V_49]] {
194 ! CHECK: fir.freemem %[[V_20]] : !fir.heap<!fir.char<1,?>>
196 ! CHECK: cond_br %[[V_49]], ^bb6, ^bb5
197 ! CHECK: ^bb3: // pred: ^bb1
198 ! CHECK: fir.store %c1{{.*}} to %[[V_1]] : !fir.ref<i32>
199 ! CHECK: ^bb4: // pred: ^bb13
200 ! CHECK: ^bb5: // pred: ^bb2
204 ! CHECK: %[[V_54:[0-9]+]] = fir.call @_FortranACharacterCompareScalar1
205 ! CHECK: %[[V_55:[0-9]+]] = arith.cmpi eq, %[[V_54]], %c0{{.*}} : i32
206 ! CHECK: fir.if %[[V_55]] {
207 ! CHECK: fir.freemem %[[V_20]] : !fir.heap<!fir.char<1,?>>
209 ! CHECK: cond_br %[[V_55]], ^bb8, ^bb7
210 ! CHECK: ^bb6: // pred: ^bb2
211 ! CHECK: fir.store %c2{{.*}} to %[[V_1]] : !fir.ref<i32>
212 ! CHECK: ^bb7: // pred: ^bb5
216 case('44':'55','66':'77','88':)
218 ! CHECK: %[[V_60:[0-9]+]] = fir.call @_FortranACharacterCompareScalar1
219 ! CHECK: %[[V_61:[0-9]+]] = arith.cmpi sge, %[[V_60]], %c0{{.*}} : i32
220 ! CHECK: cond_br %[[V_61]], ^bb9, ^bb10
221 ! CHECK: ^bb8: // pred: ^bb5
222 ! CHECK: fir.store %c3{{.*}} to %[[V_1]] : !fir.ref<i32>
223 ! CHECK: ^bb9: // pred: ^bb7
224 ! CHECK: %[[V_66:[0-9]+]] = fir.call @_FortranACharacterCompareScalar1
225 ! CHECK: %[[V_67:[0-9]+]] = arith.cmpi sle, %[[V_66]], %c0{{.*}} : i32
226 ! CHECK: fir.if %[[V_67]] {
227 ! CHECK: fir.freemem %[[V_20]] : !fir.heap<!fir.char<1,?>>
229 ! CHECK: cond_br %[[V_67]], ^bb14, ^bb10
230 ! CHECK: ^bb10: // 2 preds: ^bb7, ^bb9
231 ! CHECK: %[[V_72:[0-9]+]] = fir.call @_FortranACharacterCompareScalar1
232 ! CHECK: %[[V_73:[0-9]+]] = arith.cmpi sge, %[[V_72]], %c0{{.*}} : i32
233 ! CHECK: cond_br %[[V_73]], ^bb11, ^bb12
234 ! CHECK: ^bb11: // pred: ^bb10
235 ! CHECK: %[[V_78:[0-9]+]] = fir.call @_FortranACharacterCompareScalar1
236 ! CHECK: %[[V_79:[0-9]+]] = arith.cmpi sle, %[[V_78]], %c0{{.*}} : i32
237 ! CHECK: fir.if %[[V_79]] {
238 ! CHECK: fir.freemem %[[V_20]] : !fir.heap<!fir.char<1,?>>
240 ! CHECK: ^bb12: // 2 preds: ^bb10, ^bb11
241 ! CHECK: %[[V_84:[0-9]+]] = fir.call @_FortranACharacterCompareScalar1
242 ! CHECK: %[[V_85:[0-9]+]] = arith.cmpi sge, %[[V_84]], %c0{{.*}} : i32
243 ! CHECK: fir.freemem %[[V_20]] : !fir.heap<!fir.char<1,?>>
244 ! CHECK: cond_br %[[V_85]], ^bb14, ^bb13
245 ! CHECK: ^bb13: // pred: ^bb12
246 ! CHECK: ^bb14: // 3 preds: ^bb9, ^bb11, ^bb12
247 ! CHECK: fir.store %c4{{.*}} to %[[V_1]] : !fir.ref<i32>
248 ! CHECK: ^bb15: // 5 preds: ^bb3, ^bb4, ^bb6, ^bb8, ^bb14
251 ! CHECK: %[[V_89:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<i32>
255 ! CHECK-LABEL: func @_QPscharacter2
256 subroutine scharacter2(s
)
257 ! CHECK-DAG: %[[V_0:[0-9]+]] = fir.alloca !fir.box<!fir.heap<!fir.char<1,?>>>
258 ! CHECK: %[[V_1:[0-9]+]] = fir.alloca !fir.box<!fir.heap<!fir.char<1,?>>>
259 character(len
=3) :: s
262 ! CHECK: %[[V_12:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>
263 ! CHECK: %[[V_13:[0-9]+]] = fir.box_addr %[[V_12]] : (!fir.box<!fir.heap<!fir.char<1,?>>>) -> !fir.heap<!fir.char<1,?>>
264 ! CHECK: fir.freemem %[[V_13]] : !fir.heap<!fir.char<1,?>>
266 ! CHECK: ^bb1: // pred: ^bb0
275 ! CHECK: ^bb2: // pred: ^bb1
276 ! CHECK: %[[V_28:[0-9]+]] = fir.load %[[V_0]] : !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>
277 ! CHECK: %[[V_29:[0-9]+]] = fir.box_addr %[[V_28]] : (!fir.box<!fir.heap<!fir.char<1,?>>>) -> !fir.heap<!fir.char<1,?>>
278 ! CHECK: fir.freemem %[[V_29]] : !fir.heap<!fir.char<1,?>>
280 ! CHECK: ^bb3: // pred: ^bb2
287 ! CHECK-LABEL: func @_QPsempty
288 ! empty select case blocks
290 ! CHECK: %[[selectI1:[0-9]+]] = fir.load %arg0 : !fir.ref<i32>
291 ! CHECK: fir.select_case %[[selectI1]] : i32 [#fir.point, %c1{{.*}}, ^bb1, #fir.point, %c2{{.*}}, ^bb2, unit, ^bb3]
292 ! CHECK: ^bb1: // pred: ^bb0
293 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
295 ! CHECK: ^bb2: // pred: ^bb0
297 ! CHECK: ^bb3: // pred: ^bb0
298 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
302 print*, n
, 'i:case 1'
304 ! print*, n, 'i:case 2'
306 print*, n
, 'i:case default'
308 ! CHECK: ^bb4: // 3 preds: ^bb1, ^bb2, ^bb3
309 ! CHECK: %[[cmpC1:[0-9]+]] = fir.call @_FortranACharacterCompareScalar1
310 ! CHECK: %[[selectC1:[0-9]+]] = arith.cmpi eq, %[[cmpC1]], %c0{{.*}} : i32
311 ! CHECK: cond_br %[[selectC1]], ^bb6, ^bb5
312 ! CHECK: ^bb5: // pred: ^bb4
313 ! CHECK: %[[cmpC2:[0-9]+]] = fir.call @_FortranACharacterCompareScalar1
314 ! CHECK: %[[selectC2:[0-9]+]] = arith.cmpi eq, %[[cmpC2]], %c0{{.*}} : i32
315 ! CHECK: cond_br %[[selectC2]], ^bb8, ^bb7
316 ! CHECK: ^bb6: // pred: ^bb4
317 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
318 ! print*, n, 'c:case 2'
320 ! CHECK: ^bb7: // pred: ^bb5
322 ! CHECK: ^bb8: // pred: ^bb5
324 ! CHECK: ^bb9: // pred: ^bb7
325 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
327 ! CHECK: ^bb10: // 3 preds: ^bb6, ^bb8, ^bb9
328 select
case (char(ichar('0')+n
))
330 print*, n
, 'c:case 1'
332 ! print*, n, 'c:case 2'
334 print*, n
, 'c:case default'
339 ! CHECK-LABEL: func @_QPsgoto
340 ! select case with goto exit
344 ! CHECK: %[[i:[0-9]+]] = fir.alloca {{.*}} "_QFsgotoEi"
345 ! CHECK: ^bb2: // pred: ^bb1
346 ! CHECK: %[[selector:[0-9]+]] = fir.load %[[i]] : !fir.ref<i32>
347 ! CHECK: fir.select_case %[[selector]] : i32 [#fir.upper, %c2{{.*}}, ^bb3, #fir.lower, %c5{{.*}}, ^bb4, unit, ^bb7]
348 ! CHECK: ^bb3: // pred: ^bb2
349 ! CHECK: arith.muli %c10{{[^0]}}
351 ! CHECK: ^bb4: // pred: ^bb2
352 ! CHECK: arith.muli %c1000{{[^0]}}
353 ! CHECK: cond_br {{.*}}, ^bb5, ^bb6
354 ! CHECK: ^bb5: // pred: ^bb4
356 ! CHECK: ^bb6: // pred: ^bb4
357 ! CHECK: arith.muli %c10000{{[^0]}}
359 ! CHECK: ^bb7: // pred: ^bb2
360 ! CHECK: arith.muli %c100{{[^0]}}
362 ! CHECK: ^bb8: // 4 preds: ^bb3, ^bb5, ^bb6, ^bb7
363 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
365 ! CHECK: ^bb9: // pred: ^bb1
381 ! CHECK-LABEL: func @_QPswhere
382 subroutine swhere(num
)
385 integer, intent(in
) :: num
386 real, dimension(1) :: array
391 ! CHECK: ^bb1: // pred: ^bb0
397 ! CHECK: ^bb2: // pred: ^bb0
402 ! CHECK: ^bb3: // 2 preds: ^bb1, ^bb2
404 end subroutine swhere
406 ! CHECK-LABEL: func @_QPsforall
407 subroutine sforall(num
)
410 integer, intent(in
) :: num
411 real, dimension(1) :: array
416 ! CHECK: ^bb1: // pred: ^bb0
422 ! CHECK: ^bb2: // pred: ^bb0
427 ! CHECK: ^bb3: // 2 preds: ^bb1, ^bb2
429 end subroutine sforall
433 integer sinteger
, v(10)
441 ! expected output: 1 1 1 1 1 1 1 1 1 1
442 ! 1 2 3 4 4 6 7 7 7 7
443 ! 7 7 7 7 7 0 0 0 0 0
444 ! 7 7 7 7 7 7 7 7 7 7
449 call slogical(.false
.) ! expected output: 0 1 0 3 1 1 3 1
450 call slogical(.true
.) ! expected output: 0 0 2 3 2 3 2 2
453 call scharacter('aa') ! expected output: 10
454 call scharacter('d') ! expected output: 10
455 call scharacter('f') ! expected output: -1
456 call scharacter('ff') ! expected output: 20
457 call scharacter('fff') ! expected output: 20
458 call scharacter('ffff') ! expected output: 20
459 call scharacter('fffff') ! expected output: -1
460 call scharacter('jj') ! expected output: -1
461 call scharacter('m') ! expected output: 30
462 call scharacter('q') ! expected output: -1
463 call scharacter('qq') ! expected output: 40
464 call scharacter('qqq') ! expected output: -1
465 call scharacter('vv') ! expected output: -1
466 call scharacter('xx') ! expected output: 50
467 call scharacter('zz') ! expected output: 50
470 call scharacter1('99 ') ! expected output: 4
471 call scharacter1('88 ') ! expected output: 4
472 call scharacter1('77 ') ! expected output: 4
473 call scharacter1('66 ') ! expected output: 4
474 call scharacter1('55 ') ! expected output: 4
475 call scharacter1('44 ') ! expected output: 4
476 call scharacter1('33 ') ! expected output: 3
477 call scharacter1('22 ') ! expected output: 2
478 call scharacter1('11 ') ! expected output: 1
479 call scharacter1('00 ') ! expected output: 0
480 call scharacter1('. ') ! expected output: 0
481 call scharacter1(' ') ! expected output: 0
484 call scharacter2('99 ') ! expected output: 9 -2
485 call scharacter2('22 ') ! expected output: 9 -2
486 call scharacter2('. ') ! expected output: 9 -2
487 call scharacter2(' ') ! expected output: 9 -2
490 call sempty(0) ! expected output: 0 i:case default 0; c:case default
491 call sempty(1) ! expected output: 1 i:case 1; 1 c:case 1
492 call sempty(2) ! no output
493 call sempty(3) ! expected output: 3 i:case default; 3 c:case default
496 call sgoto
! expected output: 10 20 300 400 5000 6000 70000 80000
499 call swhere(1) ! expected output: 42.
500 call sforall(1) ! expected output: 42.