1 ! Test lowering of statement functions to HLFIR
2 ! RUN: bbc -emit-fir -hlfir -o - %s 2>&1 | FileCheck %s
4 subroutine numeric_test(x
)
5 integer :: x(:), i
, stmt_func
7 call bar(stmt_func(42))
9 ! CHECK-LABEL: func.func @_QPnumeric_test(
10 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0:[^)]*]] {{.*}}x"
11 ! CHECK: %[[VAL_6:.*]] = arith.constant 42 : i32
12 ! CHECK: %[[VAL_7:.*]]:3 = hlfir.associate %[[VAL_6]] {uniq_name = "i"} : (i32) -> (!fir.ref<i32>, !fir.ref<i32>, i1)
13 ! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_7]]#0 : !fir.ref<i32>
14 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i32) -> i64
15 ! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_9]]) : (!fir.box<!fir.array<?xi32>>, i64) -> !fir.ref<i32>
16 ! CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>
18 subroutine char_test(c
, n
)
20 character(n
) :: char_stmt_func_dummy_arg
21 character(10) :: stmt_func
22 stmt_func(char_stmt_func_dummy_arg
) = char_stmt_func_dummy_arg
23 call bar2(stmt_func(c
))
25 ! CHECK-LABEL: func.func @_QPchar_test(
26 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_3:.*]]#0 typeparams %[[VAL_3]]#1 {{.*}}c"
27 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_2:[^ ]*]] {{.*}}n"
28 ! CHECK: %[[VAL_13:.*]]:2 = fir.unboxchar %[[VAL_4]]#0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
29 ! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i32>
30 ! CHECK: %[[VAL_15:.*]] = arith.constant 0 : i32
31 ! CHECK: %[[VAL_16:.*]] = arith.cmpi sgt, %[[VAL_14]], %[[VAL_15]] : i32
32 ! CHECK: %[[VAL_17:.*]] = arith.select %[[VAL_16]], %[[VAL_14]], %[[VAL_15]] : i32
33 ! CHECK: %[[VAL_18:.*]]:2 = hlfir.declare %[[VAL_13]]#0 typeparams %[[VAL_17]] {uniq_name = "_QFstmt_funcEchar_stmt_func_dummy_arg"} : (!fir.ref<!fir.char<1,?>>, i32) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>)
34 ! CHECK: %[[VAL_19:.*]] = arith.constant 10 : i64
35 ! CHECK: %[[VAL_20:.*]] = hlfir.set_length %[[VAL_18]]#0 len %[[VAL_19]] : (!fir.boxchar<1>, i64) -> !hlfir.expr<!fir.char<1,10>>