1 ! RUN: bbc -hlfir=false %s -o - | FileCheck %s
2 ! RUN: bbc -hlfir=false --enable-constant-argument-globalisation %s -o - \
3 ! RUN: | FileCheck %s --check-prefix=CHECK-CONST
5 ! Test lowering of local character variables
7 ! CHECK-LABEL: func @_QPscalar_cst_len
8 subroutine scalar_cst_len()
10 ! CHECK: fir.alloca !fir.char<1,10> {{{.*}}uniq_name = "_QFscalar_cst_lenEc"}
13 ! CHECK-LABEL: func @_QPscalar_dyn_len
14 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32>
15 subroutine scalar_dyn_len(l
)
18 ! CHECK: %[[lexpr:.*]] = fir.load %[[arg0]] : !fir.ref<i32>
19 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i32
20 ! CHECK: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i32
21 ! CHECK: fir.alloca !fir.char<1,?>(%[[l]] : i32) {{{.*}}uniq_name = "_QFscalar_dyn_lenEc"}
24 ! CHECK-LABEL: func @_QPcst_array_cst_len
25 subroutine cst_array_cst_len()
26 character(10) :: c(20)
27 ! CHECK: fir.alloca !fir.array<20x!fir.char<1,10>> {{{.*}}uniq_name = "_QFcst_array_cst_lenEc"}
30 ! CHECK-LABEL: func @_QPcst_array_dyn_len
31 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32>
32 subroutine cst_array_dyn_len(l
)
35 ! CHECK: %[[lexpr:.*]] = fir.load %[[arg0]] : !fir.ref<i32>
36 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i32
37 ! CHECK: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i32
38 ! CHECK: fir.alloca !fir.array<10x!fir.char<1,?>>(%[[l]] : i32) {{{.*}}uniq_name = "_QFcst_array_dyn_lenEc"}
41 ! CHECK-LABEL: func @_QPdyn_array_cst_len
42 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32>
43 subroutine dyn_array_cst_len(n
)
46 ! CHECK: %[[n:.*]] = fir.load %[[arg0]] : !fir.ref<i32>
47 ! CHECK: %[[ni:.*]] = fir.convert %[[n]] : (i32) -> index
48 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[ni]], %c0{{.*}} : index
49 ! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[ni]], %c0{{.*}} : index
50 ! CHECK: fir.alloca !fir.array<?x!fir.char<1,10>>, %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_cst_lenEc"}
53 ! CHECK: func @_QPdyn_array_dyn_len
54 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32>{{.*}}, %[[arg1:.*]]: !fir.ref<i32>
55 subroutine dyn_array_dyn_len(l
, n
)
58 ! CHECK-DAG: %[[lexpr:.*]] = fir.load %[[arg0]] : !fir.ref<i32>
59 ! CHECK-DAG: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i32
60 ! CHECK-DAG: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i32
61 ! CHECK-DAG: %[[n:.*]] = fir.load %[[arg1]] : !fir.ref<i32>
62 ! CHECK: %[[ni:.*]] = fir.convert %[[n]] : (i32) -> index
63 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[ni]], %c0{{.*}} : index
64 ! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[ni]], %c0{{.*}} : index
65 ! CHECK: fir.alloca !fir.array<?x!fir.char<1,?>>(%[[l]] : i32), %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_dyn_lenEc"}
68 ! CHECK-LABEL: func @_QPcst_array_cst_len_lb
69 subroutine cst_array_cst_len_lb()
70 character(10) :: c(11:30)
71 ! CHECK: fir.alloca !fir.array<20x!fir.char<1,10>> {{{.*}}uniq_name = "_QFcst_array_cst_len_lbEc"}
74 ! CHECK-LABEL: func @_QPcst_array_dyn_len_lb
75 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i64>
76 subroutine cst_array_dyn_len_lb(l
)
78 character(l
) :: c(11:20)
79 ! CHECK: %[[lexpr:.*]] = fir.load %[[arg0]] : !fir.ref<i64>
80 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i64
81 ! CHECK: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i64
82 ! CHECK: fir.alloca !fir.array<10x!fir.char<1,?>>(%[[l]] : i64) {{{.*}}uniq_name = "_QFcst_array_dyn_len_lbEc"}
85 ! CHECK-LABEL: func @_QPdyn_array_cst_len_lb
86 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i64>
87 subroutine dyn_array_cst_len_lb(n
)
89 character(10) :: c(11:n
)
90 ! CHECK-DAG: %[[cm10:.*]] = arith.constant -10 : index
91 ! CHECK-DAG: %[[n:.*]] = fir.load %[[arg0]] : !fir.ref<i64>
92 ! CHECK-DAG: %[[ni:.*]] = fir.convert %[[n]] : (i64) -> index
93 ! CHECK: %[[raw_extent:.*]] = arith.addi %[[ni]], %[[cm10]] : index
94 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[raw_extent]], %c0{{.*}} : index
95 ! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[raw_extent]], %c0{{.*}} : index
96 ! CHECK: fir.alloca !fir.array<?x!fir.char<1,10>>, %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_cst_len_lbEc"}
99 ! CHECK-LABEL: func @_QPdyn_array_dyn_len_lb
100 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i64>{{.*}}, %[[arg1:.*]]: !fir.ref<i64>
101 subroutine dyn_array_dyn_len_lb(l
, n
)
103 character(l
) :: c(11:n
)
104 ! CHECK-DAG: %[[cm10:.*]] = arith.constant -10 : index
105 ! CHECK-DAG: %[[lexpr:.*]] = fir.load %[[arg0]] : !fir.ref<i64>
106 ! CHECK-DAG: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i64
107 ! CHECK-DAG: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i64
108 ! CHECK-DAG: %[[n:.*]] = fir.load %[[arg1]] : !fir.ref<i64>
109 ! CHECK-DAG: %[[ni:.*]] = fir.convert %[[n]] : (i64) -> index
110 ! CHECK: %[[raw_extent:.*]] = arith.addi %[[ni]], %[[cm10]] : index
111 ! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[raw_extent]], %c0{{.*}} : index
112 ! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[raw_extent]], %c0{{.*}} : index
113 ! CHECK: fir.alloca !fir.array<?x!fir.char<1,?>>(%[[l]] : i64), %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_dyn_len_lbEc"}
116 ! Test that the length of assumed length parameter is correctly deduced in lowering.
117 ! CHECK-LABEL: func @_QPassumed_length_param
118 subroutine assumed_length_param(n
)
119 character(*), parameter :: c(1)=(/"abcd"/)
121 ! CHECK: %[[c4:.*]] = arith.constant 4 : i64
122 ! CHECK: fir.store %[[c4]] to %[[tmp:.*]] : !fir.ref<i64>
123 ! CHECK-CONST: %[[tmp:.*]] = fir.address_of(@_global_const_.{{.*}}) : !fir.ref<i64>
124 ! CHECK-CONST: fir.call @_QPtake_int(%[[tmp]]) {{.*}}: (!fir.ref<i64>) -> ()
125 call take_int(len(c(n
), kind
=8))
128 ! CHECK-LABEL: func @_QPscalar_cst_neg_len
129 subroutine scalar_cst_neg_len()
131 ! CHECK: fir.alloca !fir.char<1,0> {{{.*}}uniq_name = "_QFscalar_cst_neg_lenEc"}