1 ! RUN: bbc -emit-fir -hlfir=false -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"}
8 ! CHECK: fir.store %c0{{.*}} to %[[V_1]] : !fir.ref<i32>
10 ! CHECK: %[[V_3:[0-9]+]] = llvm.intr.stacksave : !llvm.ptr
11 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
13 ! CHECK: ^bb1: // 2 preds: ^bb0, ^bb16
14 ! CHECK: cond_br %{{.*}}, ^bb2, ^bb17
15 ! CHECK: ^bb2: // pred: ^bb1
16 ! CHECK: %[[V_11:[0-9]+]] = llvm.intr.stacksave : !llvm.ptr
17 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
18 ! CHECK: cond_br %{{.*}}, ^bb3, ^bb4
19 ! CHECK: ^bb3: // pred: ^bb2
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
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: llvm.intr.stackrestore %[[V_11]] : !llvm.ptr
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: llvm.intr.stackrestore %[[V_11]] : !llvm.ptr
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: llvm.intr.stackrestore %[[V_11]] : !llvm.ptr
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: llvm.intr.stackrestore %[[V_11]] : !llvm.ptr
49 ! CHECK: llvm.intr.stackrestore %[[V_3]] : !llvm.ptr
51 ! CHECK: ^bb14: // 2 preds: ^bb5, ^bb12
52 ! CHECK: llvm.intr.stackrestore %[[V_11]] : !llvm.ptr
54 ! CHECK: ^bb15: // 2 preds: ^bb7, ^bb14
56 ! CHECK: ^bb16: // 2 preds: ^bb9, ^bb15
58 ! CHECK: ^bb17: // pred: ^bb1
59 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
61 ! CHECK: ^bb18: // 2 preds: ^bb11, ^bb17
62 ! CHECK: llvm.intr.stackrestore %[[V_3]] : !llvm.ptr
64 ! CHECK: ^bb19: // 2 preds: ^bb13, ^bb18
66 i
= i
+ 1 ! 1 increment
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
76 10 i
= i
+ 1 ! 3 increments
78 i
= i
+ 1 ! 0 increments
80 100 print*, i
! expect 21
82 ! CHECK: %[[V_51:[0-9]+]] = llvm.intr.stacksave : !llvm.ptr
83 ! CHECK: fir.store %c5{{.*}} to %[[V_0]] : !fir.ref<i32>
84 ! CHECK: fir.call @ss(%[[V_0]]) proc_attrs<bind_c> fastmath<contract> : (!fir.ref<i32>) -> ()
85 ! CHECK: llvm.intr.stackrestore %[[V_51]] : !llvm.ptr
88 subroutine ss(n
) bind(c
)
96 subroutine ss(n
) bind(c
)