1 ! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s
4 ! CHECK-LABEL: func @_QPmerge_test(
5 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.char<1>>{{.*}}, %[[arg1:.*]]: index{{.*}}, %[[arg2:[^:]+]]: !fir.boxchar<1>{{.*}}, %[[arg3:[^:]+]]: !fir.boxchar<1>{{.*}}, %[[arg4:.*]]: !fir.ref<!fir.logical<4>>{{.*}}) -> !fir.boxchar<1> {
6 function merge_test(o1
, o2
, mask
)
7 character :: o1
, o2
, merge_test
9 merge_test
= merge(o1
, o2
, mask
)
10 ! CHECK: %[[a0:.*]]:2 = fir.unboxchar %[[arg2]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
11 ! CHECK: %[[a0_cast:.*]] = fir.convert %[[a0]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.char<1>>
12 ! CHECK: %[[a1:.*]]:2 = fir.unboxchar %[[arg3]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
13 ! CHECK: %[[a1_cast:.*]] = fir.convert %[[a1]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.char<1>>
14 ! CHECK: %[[a2:.*]] = fir.load %[[arg4]] : !fir.ref<!fir.logical<4>>
15 ! CHECK: %[[a3:.*]] = fir.convert %[[a2]] : (!fir.logical<4>) -> i1
16 ! CHECK: %[[a4:.*]] = arith.select %[[a3]], %[[a0_cast]], %[[a1_cast]] : !fir.ref<!fir.char<1>>
17 ! CHECK: %{{.*}} = fir.load %[[a4]] : !fir.ref<!fir.char<1>>
20 ! CHECK-LABEL: func @_QPmerge_test2(
21 ! CHECK-SAME: %[[arg0:[^:]+]]: !fir.ref<i32>{{.*}}, %[[arg1:[^:]+]]: !fir.ref<i32>{{.*}}, %[[arg2:.*]]: !fir.ref<!fir.logical<4>>{{.*}}) -> i32 {
22 function merge_test2(o1
, o2
, mask
)
23 integer :: o1
, o2
, merge_test2
25 merge_test2
= merge(o1
, o2
, mask
)
26 ! CHECK: %[[a1:.*]] = fir.load %[[arg0]] : !fir.ref<i32>
27 ! CHECK: %[[a2:.*]] = fir.load %[[arg1]] : !fir.ref<i32>
28 ! CHECK: %[[a3:.*]] = fir.load %[[arg2]] : !fir.ref<!fir.logical<4>>
29 ! CHECK: %[[a4:.*]] = fir.convert %[[a3]] : (!fir.logical<4>) -> i1
30 ! CHECK: %{{.*}} = arith.select %[[a4]], %[[a1]], %[[a2]] : i32
33 ! CHECK-LABEL: func @_QPmerge_test3(
34 ! CHECK-SAME: %[[arg0:[^:]+]]: !fir.ref<!fir.array<10x!fir.type<_QFmerge_test3Tt{i:i32}>>>{{.*}}, %[[arg1:[^:]+]]: !fir.ref<!fir.type<_QFmerge_test3Tt{i:i32}>>{{.*}}, %[[arg2:[^:]+]]: !fir.ref<!fir.type<_QFmerge_test3Tt{i:i32}>>{{.*}}, %[[arg3:.*]]: !fir.ref<!fir.logical<4>>{{.*}}) {
35 subroutine merge_test3(result
, o1
, o2
, mask
)
39 type(t
) :: result(10), o1
, o2
41 result
= merge(o1
, o2
, mask
)
42 ! CHECK: %[[mask:.*]] = fir.load %[[arg3]] : !fir.ref<!fir.logical<4>>
43 ! CHECK: %[[mask_cast:.*]] = fir.convert %[[mask]] : (!fir.logical<4>) -> i1
44 ! CHECK: = arith.select %[[mask_cast]], %[[arg1]], %[[arg2]] : !fir.ref<!fir.type<_QFmerge_test3Tt{i:i32}>>
47 ! CHECK-LABEL: func @_QPmerge_logical_var_and_expr(
48 subroutine merge_logical_var_and_expr(l1
, l2
)
49 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.logical<4>> {fir.bindc_name = "l1"},
50 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.logical<4>> {fir.bindc_name = "l2"}) {
52 call bar(merge(l1
, .true
., l2
))
53 ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.logical<4>
54 ! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.logical<4>>
55 ! CHECK: %[[VAL_4:.*]] = arith.constant true
56 ! CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.logical<4>>
57 ! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (!fir.logical<4>) -> i1
58 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_4]] : (i1) -> !fir.logical<4>
59 ! CHECK: %[[VAL_8:.*]] = arith.select %[[VAL_6]], %[[VAL_3]], %[[VAL_7]] : !fir.logical<4>
60 ! CHECK: fir.store %[[VAL_8]] to %[[VAL_2]] : !fir.ref<!fir.logical<4>>
61 ! CHECK: fir.call @_QPbar(%[[VAL_2]]) {{.*}}: (!fir.ref<!fir.logical<4>>) -> ()
64 ! CHECK-LABEL: func @_QPmerge_cst_and_dyn_char(
65 subroutine merge_cst_and_dyn_char(dyn
, l
)
66 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1> {fir.bindc_name = "dyn"},
67 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.logical<4>> {fir.bindc_name = "l"}) {
68 character(4) :: cst
= "abcde"
71 print *, merge(cst
, dyn
, l
)
72 ! CHECK: %[[VAL_2:.*]] = fir.address_of(@_QFmerge_cst_and_dyn_charEcst) : !fir.ref<!fir.char<1,4>>
73 ! CHECK: %[[VAL_3:.*]] = arith.constant 4 : index
74 ! CHECK: %[[VAL_4:.*]]:2 = fir.unboxchar %[[VAL_0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
75 ! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.logical<4>>
76 ! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (!fir.logical<4>) -> i1
77 ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_4]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.char<1,4>>
78 ! CHECK: %[[VAL_13:.*]] = arith.select %[[VAL_11]], %[[VAL_2]], %[[VAL_12]] : !fir.ref<!fir.char<1,4>>
79 ! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (!fir.ref<!fir.char<1,4>>) -> !fir.ref<i8>
80 ! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_3]] : (index) -> i64
81 ! CHECK: fir.call @_FortranAioOutputAscii(%{{.*}}, %[[VAL_14]], %[[VAL_15]]) {{.*}}: (!fir.ref<i8>, !fir.ref<i8>, i64) -> i1