[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / character-local-variables.f90
blob305f951ce51f6a1b499366c194c9082953e1ef24
1 ! RUN: bbc %s -o - | FileCheck %s
3 ! Test lowering of local character variables
5 ! CHECK-LABEL: func @_QPscalar_cst_len
6 subroutine scalar_cst_len()
7 character(10) :: c
8 ! CHECK: fir.alloca !fir.char<1,10> {{{.*}}uniq_name = "_QFscalar_cst_lenEc"}
9 end subroutine
11 ! CHECK-LABEL: func @_QPscalar_dyn_len
12 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32>
13 subroutine scalar_dyn_len(l)
14 integer :: l
15 character(l) :: c
16 ! CHECK: %[[lexpr:.*]] = fir.load %[[arg0]] : !fir.ref<i32>
17 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i32
18 ! CHECK: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i32
19 ! CHECK: fir.alloca !fir.char<1,?>(%[[l]] : i32) {{{.*}}uniq_name = "_QFscalar_dyn_lenEc"}
20 end subroutine
22 ! CHECK-LABEL: func @_QPcst_array_cst_len
23 subroutine cst_array_cst_len()
24 character(10) :: c(20)
25 ! CHECK: fir.alloca !fir.array<20x!fir.char<1,10>> {{{.*}}uniq_name = "_QFcst_array_cst_lenEc"}
26 end subroutine
28 ! CHECK-LABEL: func @_QPcst_array_dyn_len
29 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32>
30 subroutine cst_array_dyn_len(l)
31 integer :: l
32 character(l) :: c(10)
33 ! CHECK: %[[lexpr:.*]] = fir.load %[[arg0]] : !fir.ref<i32>
34 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i32
35 ! CHECK: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i32
36 ! CHECK: fir.alloca !fir.array<10x!fir.char<1,?>>(%[[l]] : i32) {{{.*}}uniq_name = "_QFcst_array_dyn_lenEc"}
37 end subroutine
39 ! CHECK-LABEL: func @_QPdyn_array_cst_len
40 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32>
41 subroutine dyn_array_cst_len(n)
42 integer :: n
43 character(10) :: c(n)
44 ! CHECK: %[[n:.*]] = fir.load %[[arg0]] : !fir.ref<i32>
45 ! CHECK: %[[ni:.*]] = fir.convert %[[n]] : (i32) -> index
46 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[ni]], %c0{{.*}} : index
47 ! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[ni]], %c0{{.*}} : index
48 ! CHECK: fir.alloca !fir.array<?x!fir.char<1,10>>, %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_cst_lenEc"}
49 end subroutine
51 ! CHECK: func @_QPdyn_array_dyn_len
52 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32>{{.*}}, %[[arg1:.*]]: !fir.ref<i32>
53 subroutine dyn_array_dyn_len(l, n)
54 integer :: l, n
55 character(l) :: c(n)
56 ! CHECK-DAG: %[[lexpr:.*]] = fir.load %[[arg0]] : !fir.ref<i32>
57 ! CHECK-DAG: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i32
58 ! CHECK-DAG: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i32
59 ! CHECK-DAG: %[[n:.*]] = fir.load %[[arg1]] : !fir.ref<i32>
60 ! CHECK: %[[ni:.*]] = fir.convert %[[n]] : (i32) -> index
61 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[ni]], %c0{{.*}} : index
62 ! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[ni]], %c0{{.*}} : index
63 ! CHECK: fir.alloca !fir.array<?x!fir.char<1,?>>(%[[l]] : i32), %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_dyn_lenEc"}
64 end subroutine
66 ! CHECK-LABEL: func @_QPcst_array_cst_len_lb
67 subroutine cst_array_cst_len_lb()
68 character(10) :: c(11:30)
69 ! CHECK: fir.alloca !fir.array<20x!fir.char<1,10>> {{{.*}}uniq_name = "_QFcst_array_cst_len_lbEc"}
70 end subroutine
72 ! CHECK-LABEL: func @_QPcst_array_dyn_len_lb
73 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i64>
74 subroutine cst_array_dyn_len_lb(l)
75 integer(8) :: l
76 character(l) :: c(11:20)
77 ! CHECK: %[[lexpr:.*]] = fir.load %[[arg0]] : !fir.ref<i64>
78 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i64
79 ! CHECK: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i64
80 ! CHECK: fir.alloca !fir.array<10x!fir.char<1,?>>(%[[l]] : i64) {{{.*}}uniq_name = "_QFcst_array_dyn_len_lbEc"}
81 end subroutine
83 ! CHECK-LABEL: func @_QPdyn_array_cst_len_lb
84 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i64>
85 subroutine dyn_array_cst_len_lb(n)
86 integer(8) :: n
87 character(10) :: c(11:n)
88 ! CHECK-DAG: %[[cm10:.*]] = arith.constant -10 : index
89 ! CHECK-DAG: %[[n:.*]] = fir.load %[[arg0]] : !fir.ref<i64>
90 ! CHECK-DAG: %[[ni:.*]] = fir.convert %[[n]] : (i64) -> index
91 ! CHECK: %[[raw_extent:.*]] = arith.addi %[[ni]], %[[cm10]] : index
92 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[raw_extent]], %c0{{.*}} : index
93 ! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[raw_extent]], %c0{{.*}} : index
94 ! CHECK: fir.alloca !fir.array<?x!fir.char<1,10>>, %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_cst_len_lbEc"}
95 end subroutine
97 ! CHECK-LABEL: func @_QPdyn_array_dyn_len_lb
98 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i64>{{.*}}, %[[arg1:.*]]: !fir.ref<i64>
99 subroutine dyn_array_dyn_len_lb(l, n)
100 integer(8) :: l, n
101 character(l) :: c(11:n)
102 ! CHECK-DAG: %[[cm10:.*]] = arith.constant -10 : index
103 ! CHECK-DAG: %[[lexpr:.*]] = fir.load %[[arg0]] : !fir.ref<i64>
104 ! CHECK-DAG: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i64
105 ! CHECK-DAG: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i64
106 ! CHECK-DAG: %[[n:.*]] = fir.load %[[arg1]] : !fir.ref<i64>
107 ! CHECK-DAG: %[[ni:.*]] = fir.convert %[[n]] : (i64) -> index
108 ! CHECK: %[[raw_extent:.*]] = arith.addi %[[ni]], %[[cm10]] : index
109 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[raw_extent]], %c0{{.*}} : index
110 ! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[raw_extent]], %c0{{.*}} : index
111 ! CHECK: fir.alloca !fir.array<?x!fir.char<1,?>>(%[[l]] : i64), %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_dyn_len_lbEc"}
112 end subroutine
114 ! Test that the length of assumed length parameter is correctly deduced in lowering.
115 ! CHECK-LABEL: func @_QPassumed_length_param
116 subroutine assumed_length_param(n)
117 character(*), parameter :: c(1)=(/"abcd"/)
118 integer :: n
119 ! CHECK: %[[c4:.*]] = arith.constant 4 : i64
120 ! CHECK: fir.store %[[c4]] to %[[tmp:.*]] : !fir.ref<i64>
121 ! CHECK: fir.call @_QPtake_int(%[[tmp]]) {{.*}}: (!fir.ref<i64>) -> ()
122 call take_int(len(c(n), kind=8))
125 ! CHECK-LABEL: func @_QPscalar_cst_neg_len
126 subroutine scalar_cst_neg_len()
127 character(-1) :: c
128 ! CHECK: fir.alloca !fir.char<1,0> {{{.*}}uniq_name = "_QFscalar_cst_neg_lenEc"}
129 end subroutine