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()
8 ! CHECK: fir.alloca !fir.char<1,10> {{{.*}}uniq_name = "_QFscalar_cst_lenEc"}
11 ! CHECK-LABEL: func @_QPscalar_dyn_len
12 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32>
13 subroutine scalar_dyn_len(l
)
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"}
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"}
28 ! CHECK-LABEL: func @_QPcst_array_dyn_len
29 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32>
30 subroutine cst_array_dyn_len(l
)
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"}
39 ! CHECK-LABEL: func @_QPdyn_array_cst_len
40 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32>
41 subroutine dyn_array_cst_len(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"}
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
)
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"}
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"}
72 ! CHECK-LABEL: func @_QPcst_array_dyn_len_lb
73 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i64>
74 subroutine cst_array_dyn_len_lb(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"}
83 ! CHECK-LABEL: func @_QPdyn_array_cst_len_lb
84 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i64>
85 subroutine dyn_array_cst_len_lb(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"}
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
)
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"}
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"/)
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()
128 ! CHECK: fir.alloca !fir.char<1,0> {{{.*}}uniq_name = "_QFscalar_cst_neg_lenEc"}