[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / loops.f90
blobfebae0e8a0dd66d5832da737a9755e2810ca38cf
1 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
3 ! CHECK-LABEL: loop_test
4 subroutine loop_test
5 ! CHECK: %[[VAL_2:.*]] = fir.alloca i16 {bindc_name = "i"}
6 ! CHECK: %[[VAL_3:.*]] = fir.alloca i16 {bindc_name = "i"}
7 ! CHECK: %[[VAL_4:.*]] = fir.alloca i16 {bindc_name = "i"}
8 ! CHECK: %[[VAL_5:.*]] = fir.alloca i8 {bindc_name = "k"}
9 ! CHECK: %[[VAL_6:.*]] = fir.alloca i8 {bindc_name = "j"}
10 ! CHECK: %[[VAL_7:.*]] = fir.alloca i8 {bindc_name = "i"}
11 ! CHECK: %[[VAL_8:.*]] = fir.alloca i32 {bindc_name = "k"}
12 ! CHECK: %[[VAL_9:.*]] = fir.alloca i32 {bindc_name = "j"}
13 ! CHECK: %[[VAL_10:.*]] = fir.alloca i32 {bindc_name = "i"}
14 ! CHECK: %[[VAL_11:.*]] = fir.alloca !fir.array<5x5x5xi32> {bindc_name = "a", uniq_name = "_QFloop_testEa"}
15 ! CHECK: %[[VAL_12:.*]] = fir.alloca i32 {bindc_name = "asum", uniq_name = "_QFloop_testEasum"}
16 ! CHECK: %[[VAL_13:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFloop_testEi"}
17 ! CHECK: %[[VAL_14:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFloop_testEj"}
18 ! CHECK: %[[VAL_15:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFloop_testEk"}
19 ! CHECK: %[[VAL_16:.*]] = fir.alloca f32 {bindc_name = "x", uniq_name = "_QFloop_testEx"}
20 ! CHECK: %[[VAL_17:.*]] = fir.alloca i32 {bindc_name = "xsum", uniq_name = "_QFloop_testExsum"}
22 integer(4) :: a(5,5,5), i, j, k, asum, xsum
24 i = 100
25 j = 200
26 k = 300
28 ! CHECK-COUNT-3: fir.do_loop {{.*}} unordered
29 do concurrent (i=1:5, j=1:5, k=1:5) ! shared(a)
30 ! CHECK: fir.coordinate_of
31 a(i,j,k) = 0
32 enddo
33 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
34 print*, 'A:', i, j, k
36 ! CHECK-COUNT-3: fir.do_loop {{.*}} unordered
37 ! CHECK: fir.if
38 do concurrent (integer(1)::i=1:5, j=1:5, k=1:5, i.ne.j .and. k.ne.3) shared(a)
39 ! CHECK-COUNT-2: fir.coordinate_of
40 a(i,j,k) = a(i,j,k) + 1
41 enddo
43 ! CHECK-COUNT-3: fir.do_loop {{[^un]*}} -> (index, i32)
44 asum = 0
45 do i=1,5
46 do j=1,5
47 do k=1,5
48 ! CHECK: fir.coordinate_of
49 asum = asum + a(i,j,k)
50 enddo
51 enddo
52 enddo
53 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
54 print*, 'B:', i, j, k, '-', asum
56 ! CHECK: fir.do_loop {{.*}} unordered
57 ! CHECK-COUNT-2: fir.if
58 do concurrent (integer(2)::i=1:5, i.ne.3)
59 if (i.eq.2 .or. i.eq.4) goto 5 ! fir.if
60 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
61 print*, 'C:', i
62 5 continue
63 enddo
65 ! CHECK: fir.do_loop {{.*}} unordered
66 ! CHECK-COUNT-2: fir.if
67 do concurrent (integer(2)::i=1:5, i.ne.3)
68 if (i.eq.2 .or. i.eq.4) then ! fir.if
69 goto 6
70 endif
71 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
72 print*, 'D:', i
73 6 continue
74 enddo
76 ! CHECK-NOT: fir.do_loop
77 ! CHECK-NOT: fir.if
78 do concurrent (integer(2)::i=1:5, i.ne.3)
79 goto (7, 7) i+1
80 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
81 print*, 'E:', i
82 7 continue
83 enddo
85 xsum = 0.0
86 ! CHECK-NOT: fir.do_loop
87 do x = 1.5, 3.5, 0.3
88 xsum = xsum + 1
89 enddo
90 ! CHECK: fir.call @_FortranAioBeginExternalFormattedOutput
91 print '(" F:",X,F3.1,A,I2)', x, ' -', xsum
92 end subroutine loop_test
94 ! CHECK-LABEL: print_nothing
95 subroutine print_nothing(k1, k2)
96 if (k1 > 0) then
97 ! CHECK: br [[header:\^bb[0-9]+]]
98 ! CHECK: [[header]]
99 do while (k1 > k2)
100 print*, k1, k2 ! no output
101 k2 = k2 + 1
102 ! CHECK: br [[header]]
103 end do
104 end if
107 call loop_test
108 call print_nothing(2, 2)