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 ! Test intrinsic module procedure c_associated
6 ! CHECK-LABEL: func.func @_QPtest_c_ptr(
7 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>> {fir.bindc_name = "cptr1"},
8 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>> {fir.bindc_name = "cptr2"}) {
9 ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z1", uniq_name = "_QFtest_c_ptrEz1"}
10 ! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z2", uniq_name = "_QFtest_c_ptrEz2"}
11 ! CHECK: %[[VAL_4:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
12 ! CHECK: %[[VAL_5:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_4]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
13 ! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref<i64>
14 ! CHECK: %[[VAL_7:.*]] = arith.constant 0 : i64
15 ! CHECK: %[[VAL_8:.*]] = arith.cmpi ne, %[[VAL_6]], %[[VAL_7]] : i64
16 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i1) -> !fir.logical<4>
17 ! CHECK: fir.store %[[VAL_9]] to %[[VAL_2]] : !fir.ref<!fir.logical<4>>
18 ! CHECK: %[[VAL_10:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
19 ! CHECK: %[[VAL_11:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_10]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
20 ! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_11]] : !fir.ref<i64>
21 ! CHECK: %[[VAL_13:.*]] = arith.constant 0 : i64
22 ! CHECK: %[[VAL_14:.*]] = arith.cmpi ne, %[[VAL_12]], %[[VAL_13]] : i64
23 ! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>) -> i64
24 ! CHECK: %[[VAL_16:.*]] = arith.constant 0 : i64
25 ! CHECK: %[[VAL_17:.*]] = arith.cmpi eq, %[[VAL_15]], %[[VAL_16]] : i64
26 ! CHECK: %[[VAL_18:.*]] = fir.if %[[VAL_17]] -> (i1) {
27 ! CHECK: fir.result %[[VAL_14]] : i1
29 ! CHECK: %[[VAL_19:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
30 ! CHECK: %[[VAL_20:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_19]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
31 ! CHECK: %[[VAL_21:.*]] = fir.load %[[VAL_20]] : !fir.ref<i64>
32 ! CHECK: %[[VAL_22:.*]] = arith.cmpi eq, %[[VAL_12]], %[[VAL_21]] : i64
33 ! CHECK: %[[VAL_23:.*]] = arith.andi %[[VAL_14]], %[[VAL_22]] : i1
34 ! CHECK: fir.result %[[VAL_23]] : i1
36 ! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_25:.*]] : (i1) -> !fir.logical<4>
37 ! CHECK: fir.store %[[VAL_24]] to %[[VAL_3]] : !fir.ref<!fir.logical<4>>
41 subroutine test_c_ptr(cptr1
, cptr2
)
43 type(c_ptr
) :: cptr1
, cptr2
46 z1
= c_associated(cptr1
)
48 z2
= c_associated(cptr1
, cptr2
)
51 ! CHECK-LABEL: func.func @_QPtest_c_funptr(
52 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>> {fir.bindc_name = "cptr1"},
53 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>> {fir.bindc_name = "cptr2"}) {
54 ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z1", uniq_name = "_QFtest_c_funptrEz1"}
55 ! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z2", uniq_name = "_QFtest_c_funptrEz2"}
56 ! CHECK: %[[VAL_4:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>
57 ! CHECK: %[[VAL_5:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_4]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
58 ! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref<i64>
59 ! CHECK: %[[VAL_7:.*]] = arith.constant 0 : i64
60 ! CHECK: %[[VAL_8:.*]] = arith.cmpi ne, %[[VAL_6]], %[[VAL_7]] : i64
61 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i1) -> !fir.logical<4>
62 ! CHECK: fir.store %[[VAL_9]] to %[[VAL_2]] : !fir.ref<!fir.logical<4>>
63 ! CHECK: %[[VAL_10:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>
64 ! CHECK: %[[VAL_11:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_10]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
65 ! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_11]] : !fir.ref<i64>
66 ! CHECK: %[[VAL_13:.*]] = arith.constant 0 : i64
67 ! CHECK: %[[VAL_14:.*]] = arith.cmpi ne, %[[VAL_12]], %[[VAL_13]] : i64
68 ! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>>) -> i64
69 ! CHECK: %[[VAL_16:.*]] = arith.constant 0 : i64
70 ! CHECK: %[[VAL_17:.*]] = arith.cmpi eq, %[[VAL_15]], %[[VAL_16]] : i64
71 ! CHECK: %[[VAL_18:.*]] = fir.if %[[VAL_17]] -> (i1) {
72 ! CHECK: fir.result %[[VAL_14]] : i1
74 ! CHECK: %[[VAL_19:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>
75 ! CHECK: %[[VAL_20:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_19]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
76 ! CHECK: %[[VAL_21:.*]] = fir.load %[[VAL_20]] : !fir.ref<i64>
77 ! CHECK: %[[VAL_22:.*]] = arith.cmpi eq, %[[VAL_12]], %[[VAL_21]] : i64
78 ! CHECK: %[[VAL_23:.*]] = arith.andi %[[VAL_14]], %[[VAL_22]] : i1
79 ! CHECK: fir.result %[[VAL_23]] : i1
81 ! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_25:.*]] : (i1) -> !fir.logical<4>
82 ! CHECK: fir.store %[[VAL_24]] to %[[VAL_3]] : !fir.ref<!fir.logical<4>>
86 subroutine test_c_funptr(cptr1
, cptr2
)
88 type(c_funptr
) :: cptr1
, cptr2
91 z1
= c_associated(cptr1
)
93 z2
= c_associated(cptr1
, cptr2
)
96 ! CHECK-LABEL: func.func @_QPtest_optional_argument(
97 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>> {fir.bindc_name = "cptr1"},
98 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>> {fir.bindc_name = "cptr2", fir.optional},
99 ! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>> {fir.bindc_name = "cfunptr1"},
100 ! CHECK-SAME: %[[VAL_3:.*]]: !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>> {fir.bindc_name = "cfunptr2", fir.optional}) {
101 ! CHECK: %[[VAL_4:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z1", uniq_name = "_QFtest_optional_argumentEz1"}
102 ! CHECK: %[[VAL_5:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z2", uniq_name = "_QFtest_optional_argumentEz2"}
103 ! CHECK: %[[VAL_6:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
104 ! CHECK: %[[VAL_7:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_6]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
105 ! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_7]] : !fir.ref<i64>
106 ! CHECK: %[[VAL_9:.*]] = arith.constant 0 : i64
107 ! CHECK: %[[VAL_10:.*]] = arith.cmpi ne, %[[VAL_8]], %[[VAL_9]] : i64
108 ! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>) -> i64
109 ! CHECK: %[[VAL_12:.*]] = arith.constant 0 : i64
110 ! CHECK: %[[VAL_13:.*]] = arith.cmpi eq, %[[VAL_11]], %[[VAL_12]] : i64
111 ! CHECK: %[[VAL_14:.*]] = fir.if %[[VAL_13]] -> (i1) {
112 ! CHECK: fir.result %[[VAL_10]] : i1
114 ! CHECK: %[[VAL_15:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
115 ! CHECK: %[[VAL_16:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_15]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
116 ! CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_16]] : !fir.ref<i64>
117 ! CHECK: %[[VAL_18:.*]] = arith.cmpi eq, %[[VAL_8]], %[[VAL_17]] : i64
118 ! CHECK: %[[VAL_19:.*]] = arith.andi %[[VAL_10]], %[[VAL_18]] : i1
119 ! CHECK: fir.result %[[VAL_19]] : i1
121 ! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_21:.*]] : (i1) -> !fir.logical<4>
122 ! CHECK: fir.store %[[VAL_20]] to %[[VAL_4]] : !fir.ref<!fir.logical<4>>
123 ! CHECK: %[[VAL_22:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>
124 ! CHECK: %[[VAL_23:.*]] = fir.coordinate_of %[[VAL_2]], %[[VAL_22]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
125 ! CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_23]] : !fir.ref<i64>
126 ! CHECK: %[[VAL_25:.*]] = arith.constant 0 : i64
127 ! CHECK: %[[VAL_26:.*]] = arith.cmpi ne, %[[VAL_24]], %[[VAL_25]] : i64
128 ! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>>) -> i64
129 ! CHECK: %[[VAL_28:.*]] = arith.constant 0 : i64
130 ! CHECK: %[[VAL_29:.*]] = arith.cmpi eq, %[[VAL_27]], %[[VAL_28]] : i64
131 ! CHECK: %[[VAL_30:.*]] = fir.if %[[VAL_29]] -> (i1) {
132 ! CHECK: fir.result %[[VAL_26]] : i1
134 ! CHECK: %[[VAL_31:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>
135 ! CHECK: %[[VAL_32:.*]] = fir.coordinate_of %[[VAL_3]], %[[VAL_31]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
136 ! CHECK: %[[VAL_33:.*]] = fir.load %[[VAL_32]] : !fir.ref<i64>
137 ! CHECK: %[[VAL_34:.*]] = arith.cmpi eq, %[[VAL_24]], %[[VAL_33]] : i64
138 ! CHECK: %[[VAL_35:.*]] = arith.andi %[[VAL_26]], %[[VAL_34]] : i1
139 ! CHECK: fir.result %[[VAL_35]] : i1
141 ! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_37:.*]] : (i1) -> !fir.logical<4>
142 ! CHECK: fir.store %[[VAL_36]] to %[[VAL_5]] : !fir.ref<!fir.logical<4>>
146 subroutine test_optional_argument(cptr1
, cptr2
, cfunptr1
, cfunptr2
)
149 type(c_ptr
), optional
:: cptr2
150 type(c_funptr
) :: cfunptr1
151 type(c_funptr
), optional
:: cfunptr2
154 z1
= c_associated(cptr1
, cptr2
)
156 z2
= c_associated(cfunptr1
, cfunptr2
)