[flang][openacc] Use OpenACC terminator instead of fir.unreachable after Stop stmt...
[llvm-project.git] / flang / test / Lower / block.f90
blobed2603cec0f1516a83c90944230058314cfd91d9
1 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
3 ! CHECK-LABEL: func @_QQmain
4 program bb ! block stack management and exits
5 ! CHECK: %[[V_0:[0-9]+]] = fir.alloca i32 {adapt.valuebyref}
6 ! CHECK: %[[V_1:[0-9]+]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
7 integer :: i, j
8 ! CHECK: fir.store %c0{{.*}} to %[[V_1]] : !fir.ref<i32>
9 i = 0
10 ! CHECK: %[[V_3:[0-9]+]] = fir.call @llvm.stacksave.p0()
11 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
12 ! CHECK: br ^bb1
13 ! CHECK: ^bb1: // 2 preds: ^bb0, ^bb16
14 ! CHECK: cond_br %{{.*}}, ^bb2, ^bb17
15 ! CHECK: ^bb2: // pred: ^bb1
16 ! CHECK: %[[V_11:[0-9]+]] = fir.call @llvm.stacksave.p0()
17 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
18 ! CHECK: cond_br %{{.*}}, ^bb3, ^bb4
19 ! CHECK: ^bb3: // pred: ^bb2
20 ! CHECK: br ^bb10
21 ! CHECK: ^bb4: // pred: ^bb2
22 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
23 ! CHECK: cond_br %{{.*}}, ^bb5, ^bb6
24 ! CHECK: ^bb5: // pred: ^bb4
25 ! CHECK: br ^bb14
26 ! CHECK: ^bb6: // pred: ^bb4
27 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
28 ! CHECK: cond_br %{{.*}}, ^bb7, ^bb8
29 ! CHECK: ^bb7: // pred: ^bb6
30 ! CHECK: fir.call @llvm.stackrestore.p0(%[[V_11]])
31 ! CHECK: br ^bb15
32 ! CHECK: ^bb8: // pred: ^bb6
33 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
34 ! CHECK: cond_br %{{.*}}, ^bb9, ^bb10
35 ! CHECK: ^bb9: // pred: ^bb8
36 ! CHECK: fir.call @llvm.stackrestore.p0(%[[V_11]])
37 ! CHECK: br ^bb16
38 ! CHECK: ^bb10: // 2 preds: ^bb3, ^bb8
39 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
40 ! CHECK: cond_br %{{.*}}, ^bb11, ^bb12
41 ! CHECK: ^bb11: // pred: ^bb10
42 ! CHECK: fir.call @llvm.stackrestore.p0(%[[V_11]])
43 ! CHECK: br ^bb18
44 ! CHECK: ^bb12: // pred: ^bb10
45 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
46 ! CHECK: cond_br %{{.*}}, ^bb13, ^bb14
47 ! CHECK: ^bb13: // pred: ^bb12
48 ! CHECK: fir.call @llvm.stackrestore.p0(%[[V_11]])
49 ! CHECK: fir.call @llvm.stackrestore.p0(%[[V_3]])
50 ! CHECK: br ^bb19
51 ! CHECK: ^bb14: // 2 preds: ^bb5, ^bb12
52 ! CHECK: fir.call @llvm.stackrestore.p0(%[[V_11]])
53 ! CHECK: br ^bb15
54 ! CHECK: ^bb15: // 2 preds: ^bb7, ^bb14
55 ! CHECK: br ^bb16
56 ! CHECK: ^bb16: // 2 preds: ^bb9, ^bb15
57 ! CHECK: br ^bb1
58 ! CHECK: ^bb17: // pred: ^bb1
59 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
60 ! CHECK: cf.br ^bb18
61 ! CHECK: ^bb18: // 2 preds: ^bb11, ^bb17
62 ! CHECK: fir.call @llvm.stackrestore.p0(%[[V_3]])
63 ! CHECK: br ^bb19
64 ! CHECK: ^bb19: // 2 preds: ^bb13, ^bb18
65 block
66 i = i + 1 ! 1 increment
67 do j = 1, 5
68 block
69 i = i + 1; if (j == 1) goto 1 ! inner block - 5 increments, 1 goto
70 i = i + 1; if (j == 2) goto 2 ! inner block - 4 increments, 1 goto
71 i = i + 1; if (j == 3) goto 10 ! outer block - 3 increments, 1 goto
72 i = i + 1; if (j == 4) goto 11 ! outer block - 2 increments, 1 goto
73 1 i = i + 1; if (j == 5) goto 12 ! outer block - 2 increments, 1 goto
74 i = i + 1; if (j == 6) goto 100 ! program - 1 increment
75 2 end block
76 10 i = i + 1 ! 3 increments
77 11 end do
78 i = i + 1 ! 0 increments
79 12 end block
80 100 print*, i ! expect 21
82 ! CHECK: %[[V_51:[0-9]+]] = fir.call @llvm.stacksave.p0() fastmath<contract> : () -> !fir.ref<i8>
83 ! CHECK: fir.store %c5{{.*}} to %[[V_0]] : !fir.ref<i32>
84 ! CHECK: fir.call @ss(%[[V_0]]) fastmath<contract> : (!fir.ref<i32>) -> ()
85 ! CHECK: fir.call @llvm.stackrestore.p0(%[[V_51]]) fastmath<contract> : (!fir.ref<i8>) -> ()
86 block
87 interface
88 subroutine ss(n) bind(c)
89 integer :: n
90 end subroutine
91 end interface
92 call ss(5)
93 end block
94 end
96 subroutine ss(n) bind(c)
97 print*, n
98 end subroutine