1 ! Test handling of intrinsics and BIND(C) functions returning CHARACTER(1).
2 ! This is a special case because characters are always returned
3 ! or handled in memory otherwise.
5 ! RUN: bbc -emit-fir -hlfir -o - %s | FileCheck %s
7 subroutine scalar_char(c
, i
)
12 ! CHECK-LABEL: func.func @_QPscalar_char(
13 ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.char<1>
14 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %{{.*}}#0 typeparams %{{.*}} {{.*}}Ec
15 ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %{{.*}} {{.*}}Ei
16 ! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_6]]#1 : !fir.ref<i64>
17 ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> i8
18 ! CHECK: %[[VAL_9:.*]] = fir.undefined !fir.char<1>
19 ! CHECK: %[[VAL_10:.*]] = fir.insert_value %[[VAL_9]], %[[VAL_8]], [0 : index] : (!fir.char<1>, i8) -> !fir.char<1>
20 ! CHECK: fir.store %[[VAL_10]] to %[[VAL_2]] : !fir.ref<!fir.char<1>>
21 ! CHECK: %[[VAL_11:.*]] = arith.constant false
22 ! CHECK: %[[VAL_12:.*]] = hlfir.as_expr %[[VAL_2]] move %[[VAL_11]] : (!fir.ref<!fir.char<1>>, i1) -> !hlfir.expr<!fir.char<1>>
23 ! CHECK: hlfir.assign %[[VAL_12]] to %[[VAL_5]]#0 : !hlfir.expr<!fir.char<1>>, !fir.boxchar<1>
25 subroutine scalar_bindc(c
)
28 character(1) function bar() bind(c
)
33 ! CHECK-LABEL: func.func @_QPscalar_bindc(
34 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.char<1>
35 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %{{.*}}#0 typeparams %{{.*}} {{.*}}Ec
36 ! CHECK: %[[VAL_5:.*]] = fir.call @bar() fastmath<contract> : () -> !fir.char<1>
37 ! CHECK: fir.store %[[VAL_5]] to %[[VAL_1]] : !fir.ref<!fir.char<1>>
38 ! CHECK: %[[VAL_6:.*]] = arith.constant false
39 ! CHECK: %[[VAL_7:.*]] = hlfir.as_expr %[[VAL_1]] move %[[VAL_6]] : (!fir.ref<!fir.char<1>>, i1) -> !hlfir.expr<!fir.char<1>>
40 ! CHECK: hlfir.assign %[[VAL_7]] to %[[VAL_4]]#0 : !hlfir.expr<!fir.char<1>>, !fir.boxchar<1>
42 subroutine array_char(c
, i
)
43 character(1) :: c(100)
47 ! CHECK-LABEL: func.func @_QParray_char(
48 ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.char<1>
49 ! CHECK: %[[VAL_13:.*]] = hlfir.elemental %{{.*}} typeparams %{{.*}} : (!fir.shape<1>, index) -> !hlfir.expr<100x!fir.char<1>> {
50 ! CHECK: ^bb0(%[[VAL_14:.*]]: index):
51 ! CHECK: %[[VAL_19:.*]] = fir.insert_value {{.*}} -> !fir.char<1>
52 ! CHECK: fir.store %[[VAL_19]] to %[[VAL_2]] : !fir.ref<!fir.char<1>>
53 ! CHECK: %[[VAL_20:.*]] = arith.constant false
54 ! CHECK: %[[VAL_21:.*]] = hlfir.as_expr %[[VAL_2]] move %[[VAL_20]] : (!fir.ref<!fir.char<1>>, i1) -> !hlfir.expr<!fir.char<1>>
55 ! CHECK: hlfir.yield_element %[[VAL_21]] : !hlfir.expr<!fir.char<1>>
57 ! CHECK: hlfir.assign %[[VAL_13]] to %{{.*}} : !hlfir.expr<100x!fir.char<1>>, !fir.ref<!fir.array<100x!fir.char<1>>>