[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / infinite_loop.f90
blob7bca44f17413cf35d26ece68f6fb55f206b1edbc
1 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir -o - %s | FileCheck %s
4 ! Tests for infinite loop.
6 subroutine empty_infinite()
7 do
8 end do
9 end subroutine
10 ! CHECK-LABEL: empty_infinite
11 ! CHECK: cf.br ^[[BODY:.*]]
12 ! CHECK: ^[[BODY]]:
13 ! CHECK: cf.br ^[[BODY]]
15 subroutine simple_infinite(i)
16 integer :: i
18 if (i .gt. 100) exit
19 end do
20 end subroutine
21 ! CHECK-LABEL: simple_infinite
22 ! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
23 ! CHECK: cf.br ^[[BODY1:.*]]
24 ! CHECK: ^[[BODY1]]:
25 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
26 ! CHECK: %[[C100:.*]] = arith.constant 100 : i32
27 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C100]] : i32
28 ! CHECK: cf.cond_br %[[COND]], ^[[EXIT:.*]], ^[[BODY1:.*]]
29 ! CHECK: ^[[EXIT]]:
30 ! CHECK: cf.br ^[[RETURN:.*]]
31 ! CHECK: ^[[RETURN]]:
32 ! CHECK: return
33 ! CHECK: }
35 subroutine infinite_with_two_body_blocks(i)
36 integer :: i
38 i = i + 1
39 if (i .gt. 100) exit
40 i = i * 2
41 end do
42 end subroutine
43 ! CHECK-LABEL: infinite_with_two_body_blocks
44 ! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
45 ! CHECK: cf.br ^[[BODY1:.*]]
46 ! CHECK: ^[[BODY1]]:
47 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
48 ! CHECK: %[[C1:.*]] = arith.constant 1 : i32
49 ! CHECK: %[[I_NEXT:.*]] = arith.addi %[[I]], %[[C1]] : i32
50 ! CHECK: fir.store %[[I_NEXT]] to %[[I_REF]] : !fir.ref<i32>
51 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
52 ! CHECK: %[[C100:.*]] = arith.constant 100 : i32
53 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C100]] : i32
54 ! CHECK: cf.cond_br %[[COND]], ^[[EXIT:.*]], ^[[BODY2:.*]]
55 ! CHECK: ^[[EXIT]]:
56 ! CHECK: cf.br ^[[RETURN:.*]]
57 ! CHECK: ^[[BODY2]]:
58 ! CHECK: %[[C2:.*]] = arith.constant 2 : i32
59 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
60 ! CHECK: %[[I_NEXT:.*]] = arith.muli %[[C2]], %[[I]] : i32
61 ! CHECK: fir.store %[[I_NEXT]] to %[[I_REF]] : !fir.ref<i32>
62 ! CHECK: cf.br ^[[BODY1]]
63 ! CHECK: ^[[RETURN]]:
64 ! CHECK: return
65 ! CHECK: }
67 subroutine structured_loop_in_infinite(i)
68 integer :: i
69 integer :: j
71 if (i .gt. 100) exit
72 do j=1,10
73 end do
74 end do
75 end subroutine
76 ! CHECK-LABEL: structured_loop_in_infinite
77 ! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
78 ! CHECK: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFstructured_loop_in_infiniteEj"}
79 ! CHECK: cf.br ^[[BODY1:.*]]
80 ! CHECK: ^[[BODY1]]:
81 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
82 ! CHECK: %[[C100:.*]] = arith.constant 100 : i32
83 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C100]] : i32
84 ! CHECK: cf.cond_br %[[COND]], ^[[EXIT:.*]], ^[[BODY2:.*]]
85 ! CHECK: ^[[EXIT]]:
86 ! CHECK: cf.br ^[[RETURN:.*]]
87 ! CHECK: ^[[BODY2:.*]]:
88 ! CHECK: %[[C1:.*]] = arith.constant 1 : i32
89 ! CHECK: %[[C1_INDEX:.*]] = fir.convert %[[C1]] : (i32) -> index
90 ! CHECK: %[[C10:.*]] = arith.constant 10 : i32
91 ! CHECK: %[[C10_INDEX:.*]] = fir.convert %[[C10]] : (i32) -> index
92 ! CHECK: %[[C1_1:.*]] = arith.constant 1 : index
93 ! CHECK: %[[J_LB:.*]] = fir.convert %[[C1_INDEX]] : (index) -> i32
94 ! CHECK: %[[J_FINAL:.*]]:2 = fir.do_loop %[[J:[^ ]*]] =
95 ! CHECK-SAME: %[[C1_INDEX]] to %[[C10_INDEX]] step %[[C1_1]]
96 ! CHECK-SAME: iter_args(%[[J_IV:.*]] = %[[J_LB]]) -> (index, i32) {
97 ! CHECK: fir.store %[[J_IV]] to %[[J_REF]] : !fir.ref<i32>
98 ! CHECK: %[[J_NEXT:.*]] = arith.addi %[[J]], %[[C1_1]] : index
99 ! CHECK: %[[J_STEPCAST:.*]] = fir.convert %[[C1_1]] : (index) -> i32
100 ! CHECK: %[[J_IVLOAD:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
101 ! CHECK: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST]] : i32
102 ! CHECK: fir.result %[[J_NEXT]], %[[J_IVINC]] : index, i32
103 ! CHECK: }
104 ! CHECK: fir.store %[[J_FINAL]]#1 to %[[J_REF]] : !fir.ref<i32>
105 ! CHECK: cf.br ^[[BODY1]]
106 ! CHECK: ^[[RETURN]]:
107 ! CHECK: return
109 subroutine empty_infinite_in_while(i)
110 integer :: i
111 do while (i .gt. 50)
113 end do
114 end do
115 end subroutine
117 ! CHECK-LABEL: empty_infinite_in_while
118 ! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
119 ! CHECK: cf.br ^bb1
120 ! CHECK: ^bb1:
121 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
122 ! CHECK: %[[C50:.*]] = arith.constant 50 : i32
123 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C50]] : i32
124 ! CHECK: cf.cond_br %[[COND]], ^[[INF_HEADER:.*]], ^[[EXIT:.*]]
125 ! CHECK: ^[[INF_HEADER]]:
126 ! CHECK: cf.br ^[[INF_BODY:.*]]
127 ! CHECK: ^[[INF_BODY]]:
128 ! CHECK: cf.br ^[[INF_HEADER]]
129 ! CHECK: ^[[EXIT]]:
130 ! CHECK: return