1 // Test hlfir.get_length code generation
2 // RUN: fir-opt %s --bufferize-hlfir | FileCheck %s
4 func.func @_QPtest_char_get_length(%arg0: !fir.boxchar<1> {fir.bindc_name = "ch"}) -> index {
5 %c3 = arith.constant 3 : index
6 %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
7 %1:2 = hlfir.declare %0#0 typeparams %0#1 {uniq_name = "_QFtest_char_get_lengthEch"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>)
8 %2 = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFtest_char_get_lengthEx"}
9 %3:2 = hlfir.declare %2 {uniq_name = "_QFtest_char_get_lengthEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
10 %4 = fir.address_of(@_QQcl.616263) : !fir.ref<!fir.char<1,3>>
11 %5:2 = hlfir.declare %4 typeparams %c3 {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "_QQcl.616263"} : (!fir.ref<!fir.char<1,3>>, index) -> (!fir.ref<!fir.char<1,3>>, !fir.ref<!fir.char<1,3>>)
12 %6 = arith.addi %0#1, %c3 : index
13 %7 = hlfir.concat %5#0, %1#0 len %6 : (!fir.ref<!fir.char<1,3>>, !fir.boxchar<1>, index) -> !hlfir.expr<!fir.char<1,?>>
14 %8:3 = hlfir.associate %7 typeparams %6 {uniq_name = ".tmp.assign"} : (!hlfir.expr<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>, i1)
15 %9 = hlfir.as_expr %8#0 : (!fir.boxchar<1>) -> !hlfir.expr<!fir.char<1,?>>
16 %10 = hlfir.get_length %9 : (!hlfir.expr<!fir.char<1,?>>) -> index
17 hlfir.destroy %9 : !hlfir.expr<!fir.char<1,?>>
18 hlfir.end_associate %8#1, %8#2 : !fir.ref<!fir.char<1,?>>, i1
21 fir.global linkonce @_QQcl.616263 constant : !fir.char<1,3> {
22 %0 = fir.string_lit "abc"(3) : !fir.char<1,3>
23 fir.has_value %0 : !fir.char<1,3>
25 // CHECK-LABEL: func.func @_QPtest_char_get_length(
26 // CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1> {fir.bindc_name = "ch"}) -> index {
27 // CHECK: %[[VAL_1:.*]] = arith.constant 3 : index
28 // CHECK: %[[VAL_2:.*]]:2 = fir.unboxchar %[[VAL_0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
29 // CHECK: %[[VAL_9:.*]] = arith.addi %[[VAL_1]], %[[VAL_2]]#1 : index
30 // CHECK: %[[VAL_33:.*]]:2 = hlfir.declare %[[VAL_31:.*]] typeparams %[[VAL_9]] {uniq_name = ".tmp"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>)
31 // CHECK: return %[[VAL_9]] : index