Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / alternate-return.f90
blob15934e242adcdd21fbe87cc8664c50e241f3d888
1 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
3 ! CHECK-LABEL: func @_QPss
4 subroutine ss(n)
5 print*, n
6 ! CHECK: return{{$}}
7 return
8 ! CHECK-LABEL: func @_QPee
9 entry ee(n,*)
10 print*, n
11 ! CHECK: return %{{.}} : index
12 return 1
13 end
15 ! CHECK-LABEL: func @_QQmain
16 call ss(7)
17 call ee(2, *3)
18 print*, 'default'
19 3 print*, 3
21 print*, k(10,20)
22 print*, k(15,15)
23 print*, k(20,10)
24 end
26 ! CHECK-LABEL: func @_QPk
27 function k(n1, n2)
28 ! CHECK-NOT: ^bb
29 ! CHECK: [[selector:%[0-9]+]] = fir.call @_QPs
30 ! CHECK-NEXT: fir.select [[selector]] : index [1, ^[[block1:bb[0-9]+]], 2, ^[[block2:bb[0-9]+]], unit, ^[[blockunit:bb[0-9]+]]
31 call s(n1, *5, n2, *7)
32 ! CHECK: ^[[blockunit]]: // pred: ^bb0
33 k = 0; return;
34 ! CHECK: ^[[block1]]: // pred: ^bb0
35 5 k = -1; return;
36 ! CHECK: ^[[block2]]: // pred: ^bb0
37 7 k = 1; return
38 end
40 ! CHECK-LABEL: func @_QPs
41 subroutine s(n1, *, n2, *)
42 ! CHECK: [[retval:%[0-9]+]] = fir.alloca index {{{.*}}bindc_name = "s"}
43 ! CHECK-COUNT-3: fir.store {{.*}} to [[retval]] : !fir.ref<index>
44 if (n1 < n2) return 1
45 if (n1 > n2) return 2
46 ! CHECK: {{.*}} = fir.load [[retval]] : !fir.ref<index>
47 ! CHECK-NEXT: return {{.*}} : index
48 return
49 end