[AMDGPU] Test codegen'ing True16 additions.
[llvm-project.git] / flang / test / Lower / call-copy-in-out.f90
blobbcc2f81cf6bee64735e0ef2b1fe537bc73cc944a
1 ! Test copy-in / copy-out of non-contiguous variable passed as F77 array arguments.
2 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
4 ! Nominal test
5 ! CHECK-LABEL: func @_QPtest_assumed_shape_to_array(
6 ! CHECK-SAME: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) {
7 subroutine test_assumed_shape_to_array(x)
8 real :: x(:)
10 ! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
11 ! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) {{.*}}: (!fir.box<none>) -> i1
12 ! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]] -> (!fir.heap<!fir.array<?xf32>>) {
13 ! CHECK: %[[box_addr:.*]] = fir.box_addr %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.heap<!fir.array<?xf32>>
14 ! CHECK: fir.result %[[box_addr]] : !fir.heap<!fir.array<?xf32>>
15 ! CHECK: } else {
16 ! Creating temp
17 ! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x:.*]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
18 ! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1 {uniq_name = ".copyinout"}
20 ! Copy-in
21 ! CHECK-DAG: %[[shape:.*]] = fir.shape %[[dim]]#1 : (index) -> !fir.shape<1>
22 ! CHECK-DAG: %[[temp_box:.*]] = fir.embox %[[temp]](%[[shape]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
23 ! CHECK-DAG: fir.store %[[temp_box]] to %[[temp_box_loc:.*]] : !fir.ref<!fir.box<!fir.array<?xf32>>>
24 ! CHECK-DAG: %[[temp_box_addr:.*]] = fir.convert %[[temp_box_loc]] : (!fir.ref<!fir.box<!fir.array<?xf32>>>) -> !fir.ref<!fir.box<none>>
25 ! CHECK-DAG: %[[arg_box:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
26 ! CHECK-DAG: fir.call @_FortranAAssignTemporary(%[[temp_box_addr]], %[[arg_box]], %{{.*}}, %{{.*}}){{.*}}: (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> none
27 ! CHECK: fir.result %[[temp]] : !fir.heap<!fir.array<?xf32>>
29 ! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
30 ! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
31 ! CHECK: fir.call @_QPbar(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
33 ! Copy-out
34 ! CHECK-DAG: %[[shape:.*]] = fir.shape %[[dim]]#1 : (index) -> !fir.shape<1>
35 ! CHECK-DAG: %[[temp_box:.*]] = fir.embox %[[addr]](%[[shape]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
36 ! CHECK-DAG: fir.store %[[x]] to %[[arg_box_loc:.*]] : !fir.ref<!fir.box<!fir.array<?xf32>>>
37 ! CHECK-DAG: %[[skipToInit:.*]] = arith.constant true
38 ! CHECK-DAG: %[[arg_box_addr:.*]] = fir.convert %[[arg_box_loc]] : (!fir.ref<!fir.box<!fir.array<?xf32>>>) -> !fir.ref<!fir.box<none>>
39 ! CHECK-DAG: %[[temp_box_cast:.*]] = fir.convert %[[temp_box]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
40 ! CHECK-DAG: fir.call @_FortranACopyOutAssign(%[[arg_box_addr]], %[[temp_box_cast]], %[[skipToInit]], %{{.*}}, %{{.*}}){{.*}}: (!fir.ref<!fir.box<none>>, !fir.box<none>, i1, !fir.ref<i8>, i32) -> none
41 ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf32>>
43 call bar(x)
44 end subroutine
46 ! Test that copy-in/copy-out does not trigger the re-evaluation of
47 ! the designator expression.
48 ! CHECK-LABEL: func @_QPeval_expr_only_once(
49 ! CHECK-SAME: %[[x:.*]]: !fir.ref<!fir.array<200xf32>>{{.*}}) {
50 subroutine eval_expr_only_once(x)
51 integer :: only_once
52 real :: x(200)
53 ! CHECK: fir.call @_QPonly_once()
54 ! CHECK: %[[x_section:.*]] = fir.embox %[[x]](%{{.*}}) [%{{.*}}] : (!fir.ref<!fir.array<200xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
55 ! CHECK: %[[box_none:.*]] = fir.convert %[[x_section]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
56 ! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) {{.*}}: (!fir.box<none>) -> i1
57 ! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]] -> (!fir.heap<!fir.array<?xf32>>) {
59 ! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>
60 ! CHECK-NOT: fir.call @_QPonly_once()
61 ! CHECK: fir.call @_FortranAAssignTemporary
62 ! CHECK-NOT: fir.call @_QPonly_once()
64 ! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
65 ! CHECK: fir.call @_QPbar(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
66 call bar(x(1:200:only_once()))
68 ! CHECK-NOT: fir.call @_QPonly_once()
69 ! CHECK: fir.call @_FortranACopyOutAssign
70 ! CHECK-NOT: fir.call @_QPonly_once()
72 ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf32>>
73 end subroutine
75 ! Test no copy-in/copy-out is generated for contiguous assumed shapes.
76 ! CHECK-LABEL: func @_QPtest_contiguous(
77 ! CHECK-SAME: %[[x:.*]]: !fir.box<!fir.array<?xf32>>
78 subroutine test_contiguous(x)
79 real, contiguous :: x(:)
80 ! CHECK: %[[addr:.*]] = fir.box_addr %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
81 ! CHECK-NOT: fir.call @_FortranAAssignTemporary
82 ! CHECK: fir.call @_QPbar(%[[addr]]) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
83 call bar(x)
84 ! CHECK-NOT: fir.call @_FortranACopyOutAssign
85 ! CHECK: return
86 end subroutine
88 ! Test the parenthesis are preventing copy-out.
89 ! CHECK: func @_QPtest_parenthesis(
90 ! CHECK: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) {
91 subroutine test_parenthesis(x)
92 real :: x(:)
93 ! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
94 ! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1 {uniq_name = ".array.expr"}
95 ! CHECK: fir.array_merge_store %{{.*}}, %{{.*}} to %[[temp]]
96 ! CHECK: %[[cast:.*]] = fir.convert %[[temp]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
97 ! CHECK: fir.call @_QPbar(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
98 call bar((x))
99 ! CHECK-NOT: fir.call @_FortranACopyOutAssign
100 ! CHECK: fir.freemem %[[temp]] : !fir.heap<!fir.array<?xf32>>
101 ! CHECK: return
102 end subroutine
104 ! Test copy-in in is skipped for intent(out) arguments.
105 ! CHECK: func @_QPtest_intent_out(
106 ! CHECK: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) {
107 subroutine test_intent_out(x)
108 real :: x(:)
109 interface
110 subroutine bar_intent_out(x)
111 real, intent(out) :: x(100)
112 end subroutine
113 end interface
114 ! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
115 ! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) {{.*}}: (!fir.box<none>) -> i1
116 ! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]]
117 ! CHECK: } else {
118 ! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
119 ! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1
120 ! CHECK-NOT: fir.call @_FortranAAssignTemporary
121 ! CHECK: %[[not_contiguous:.*]] = arith.cmpi eq, %[[is_contiguous]], %false{{.*}} : i1
122 ! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>>
123 ! CHECK: fir.call @_QPbar_intent_out(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<100xf32>>) -> ()
124 call bar_intent_out(x)
126 ! CHECK: fir.if %[[not_contiguous]]
127 ! CHECK: fir.call @_FortranACopyOutAssign
128 ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf32>>
129 ! CHECK: return
130 end subroutine
132 ! Test copy-out is skipped for intent(out) arguments.
133 ! CHECK-LABEL: func.func @_QPtest_intent_in(
134 ! CHECK: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) {
135 subroutine test_intent_in(x)
136 real :: x(:)
137 interface
138 subroutine bar_intent_in(x)
139 real, intent(in) :: x(100)
140 end subroutine
141 end interface
142 ! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
143 ! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) {{.*}}: (!fir.box<none>) -> i1
144 ! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]]
145 ! CHECK: } else {
146 ! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
147 ! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1
148 ! CHECK: %[[temp_shape:.*]] = fir.shape %[[dim]]#1 : (index) -> !fir.shape<1>
149 ! CHECK: %[[temp_box:.*]] = fir.embox %[[temp]](%[[temp_shape]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
150 ! CHECK: fir.store %[[temp_box]] to %[[temp_box_loc:.*]] : !fir.ref<!fir.box<!fir.array<?xf32>>>
151 ! CHECK: %[[temp_box_addr:.*]] = fir.convert %[[temp_box_loc]] : (!fir.ref<!fir.box<!fir.array<?xf32>>>) -> !fir.ref<!fir.box<none>>
152 ! CHECK: fir.call @_FortranAAssignTemporary(%[[temp_box_addr]],
153 ! CHECK: %[[not_contiguous:.*]] = arith.cmpi eq, %[[is_contiguous]], %false{{.*}} : i1
154 ! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>>
155 ! CHECK: fir.call @_QPbar_intent_in(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<100xf32>>) -> ()
156 call bar_intent_in(x)
157 ! CHECK: fir.if %[[not_contiguous]]
158 ! CHECK-NOT: fir.call @_FortranACopyOutAssign
159 ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf32>>
160 ! CHECK: return
161 end subroutine
163 ! Test copy-in/copy-out is done for intent(inout)
164 ! CHECK: func @_QPtest_intent_inout(
165 ! CHECK: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) {
166 subroutine test_intent_inout(x)
167 real :: x(:)
168 interface
169 subroutine bar_intent_inout(x)
170 real, intent(inout) :: x(100)
171 end subroutine
172 end interface
173 ! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
174 ! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) {{.*}}: (!fir.box<none>) -> i1
175 ! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]]
176 ! CHECK: } else {
177 ! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
178 ! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1
179 ! CHECK: fir.call @_FortranAAssign
180 ! CHECK: %[[not_contiguous:.*]] = arith.cmpi eq, %[[is_contiguous]], %false{{.*}} : i1
181 ! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>>
182 ! CHECK: fir.call @_QPbar_intent_inout(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<100xf32>>) -> ()
183 call bar_intent_inout(x)
184 ! CHECK: fir.if %[[not_contiguous]]
185 ! CHECK: fir.call @_FortranACopyOutAssign
186 ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf32>>
187 ! CHECK: return
188 end subroutine
190 ! Test characters are handled correctly
191 ! CHECK-LABEL: func @_QPtest_char(
192 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.char<1,10>>>{{.*}}) {
193 subroutine test_char(x)
194 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.box<!fir.array<?x!fir.char<1,10>>>
195 ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.box<!fir.array<?x!fir.char<1,10>>>
196 ! CHECK: %[[VAL_3:.*]] = arith.constant 10 : index
197 ! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.box<none>
198 ! CHECK: %[[VAL_5:.*]] = fir.call @_FortranAIsContiguous(%[[VAL_4]]) fastmath<contract> : (!fir.box<none>) -> i1
199 ! CHECK: %[[VAL_6:.*]] = fir.if %[[VAL_5]] -> (!fir.heap<!fir.array<?x!fir.char<1,10>>>) {
200 ! CHECK: %[[VAL_7:.*]] = fir.box_addr %[[VAL_0]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.heap<!fir.array<?x!fir.char<1,10>>>
201 ! CHECK: fir.result %[[VAL_7]] : !fir.heap<!fir.array<?x!fir.char<1,10>>>
202 ! CHECK: } else {
203 ! CHECK: %[[VAL_8:.*]] = arith.constant 0 : index
204 ! CHECK: %[[VAL_9:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_8]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>, index) -> (index, index, index)
205 ! CHECK: %[[VAL_10:.*]] = fir.allocmem !fir.array<?x!fir.char<1,10>>, %[[VAL_9]]#1 {uniq_name = ".copyinout"}
206 ! CHECK: %[[VAL_11:.*]] = fir.shape %[[VAL_9]]#1 : (index) -> !fir.shape<1>
207 ! CHECK: %[[VAL_12:.*]] = fir.embox %[[VAL_10]](%[[VAL_11]]) : (!fir.heap<!fir.array<?x!fir.char<1,10>>>, !fir.shape<1>) -> !fir.box<!fir.array<?x!fir.char<1,10>>>
208 ! CHECK: fir.store %[[VAL_12]] to %[[VAL_2]] : !fir.ref<!fir.box<!fir.array<?x!fir.char<1,10>>>>
209 ! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.box<!fir.array<?x!fir.char<1,10>>>>) -> !fir.ref<!fir.box<none>>
210 ! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.box<none>
211 ! CHECK: %[[VAL_18:.*]] = fir.call @_FortranAAssignTemporary(%[[VAL_15]], %[[VAL_16]], %{{.*}}, %{{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> none
212 ! CHECK: fir.result %[[VAL_10]] : !fir.heap<!fir.array<?x!fir.char<1,10>>>
213 ! CHECK: }
214 ! CHECK: %[[VAL_19:.*]] = arith.constant 0 : index
215 ! CHECK: %[[VAL_20:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_19]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>, index) -> (index, index, index)
216 ! CHECK: %[[VAL_21:.*]] = arith.constant false
217 ! CHECK: %[[VAL_22:.*]] = arith.cmpi eq, %[[VAL_5]], %[[VAL_21]] : i1
218 ! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_24:.*]] : (!fir.heap<!fir.array<?x!fir.char<1,10>>>) -> !fir.ref<!fir.char<1,?>>
219 ! CHECK: %[[VAL_25:.*]] = fir.emboxchar %[[VAL_23]], %[[VAL_3]] : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>
220 ! CHECK: fir.call @_QPbar_char(%[[VAL_25]]) fastmath<contract> : (!fir.boxchar<1>) -> ()
221 ! CHECK: fir.if %[[VAL_22]] {
222 ! CHECK: %[[VAL_26:.*]] = fir.shape %[[VAL_20]]#1 : (index) -> !fir.shape<1>
223 ! CHECK: %[[VAL_27:.*]] = fir.embox %[[VAL_24]](%[[VAL_26]]) : (!fir.heap<!fir.array<?x!fir.char<1,10>>>, !fir.shape<1>) -> !fir.box<!fir.array<?x!fir.char<1,10>>>
224 ! CHECK: fir.store %[[VAL_0]] to %[[VAL_1]] : !fir.ref<!fir.box<!fir.array<?x!fir.char<1,10>>>>
225 ! CHECK: %[[VAL_30:.*]] = arith.constant true
226 ! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.box<!fir.array<?x!fir.char<1,10>>>>) -> !fir.ref<!fir.box<none>>
227 ! CHECK: %[[VAL_32:.*]] = fir.convert %[[VAL_27]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.box<none>
228 ! CHECK: %[[VAL_34:.*]] = fir.call @_FortranACopyOutAssign(%[[VAL_31]], %[[VAL_32]], %[[VAL_30]], %{{.*}}, %{{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.box<none>, i1, !fir.ref<i8>, i32) -> none
229 ! CHECK: fir.freemem %[[VAL_24]] : !fir.heap<!fir.array<?x!fir.char<1,10>>>
230 ! CHECK: }
232 character(10) :: x(:)
233 call bar_char(x)
234 ! CHECK: return
235 ! CHECK: }
236 end subroutine test_char
238 ! CHECK-LABEL: func @_QPtest_scalar_substring_does_no_trigger_copy_inout
239 ! CHECK-SAME: %[[arg0:.*]]: !fir.boxchar<1>
240 subroutine test_scalar_substring_does_no_trigger_copy_inout(c, i, j)
241 character(*) :: c
242 integer :: i, j
243 ! CHECK: %[[unbox:.*]]:2 = fir.unboxchar %[[arg0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
244 ! CHECK: %[[c:.*]] = fir.convert %[[unbox]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.array<?x!fir.char<1>>>
245 ! CHECK: %[[coor:.*]] = fir.coordinate_of %[[c]], %{{.*}} : (!fir.ref<!fir.array<?x!fir.char<1>>>, index) -> !fir.ref<!fir.char<1>>
246 ! CHECK: %[[substr:.*]] = fir.convert %[[coor]] : (!fir.ref<!fir.char<1>>) -> !fir.ref<!fir.char<1,?>>
247 ! CHECK: %[[boxchar:.*]] = fir.emboxchar %[[substr]], %{{.*}} : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>
248 ! CHECK: fir.call @_QPbar_char_2(%[[boxchar]]) {{.*}}: (!fir.boxchar<1>) -> ()
249 call bar_char_2(c(i:j))
250 end subroutine
252 ! CHECK-LABEL: func @_QPissue871(
253 ! CHECK-SAME: %[[p:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.type<_QFissue871Tt{i:i32}>>>>{{.*}})
254 subroutine issue871(p)
255 ! Test passing implicit derived from scalar pointer (no copy-in/out).
256 type t
257 integer :: i
258 end type t
259 type(t), pointer :: p
260 ! CHECK: %[[box_load:.*]] = fir.load %[[p]]
261 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box_load]]
262 ! CHECK: %[[cast:.*]] = fir.convert %[[addr]]
263 ! CHECK: fir.call @_QPbar_derived(%[[cast]])
264 call bar_derived(p)
265 end subroutine
267 ! CHECK-LABEL: func @_QPissue871_array(
268 ! CHECK-SAME: %[[p:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QFissue871_arrayTt{i:i32}>>>>>
269 subroutine issue871_array(p)
270 ! Test passing implicit derived from contiguous pointer (no copy-in/out).
271 type t
272 integer :: i
273 end type t
274 type(t), pointer, contiguous :: p(:)
275 ! CHECK: %[[box_load:.*]] = fir.load %[[p]]
276 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box_load]]
277 ! CHECK: %[[cast:.*]] = fir.convert %[[addr]]
278 ! CHECK: fir.call @_QPbar_derived_array(%[[cast]])
279 call bar_derived_array(p)
280 end subroutine
282 ! CHECK-LABEL: func @_QPwhole_components()
283 subroutine whole_components()
284 ! Test no copy is made for whole components.
285 type t
286 integer :: i(100)
287 end type
288 ! CHECK: %[[a:.*]] = fir.alloca !fir.type<_QFwhole_componentsTt{i:!fir.array<100xi32>}>
289 type(t) :: a
290 ! CHECK: %[[field:.*]] = fir.field_index i, !fir.type<_QFwhole_componentsTt{i:!fir.array<100xi32>}>
291 ! CHECK: %[[addr:.*]] = fir.coordinate_of %[[a]], %[[field]] : (!fir.ref<!fir.type<_QFwhole_componentsTt{i:!fir.array<100xi32>}>>, !fir.field) -> !fir.ref<!fir.array<100xi32>>
292 ! CHECK: fir.call @_QPbar_integer(%[[addr]]) {{.*}}: (!fir.ref<!fir.array<100xi32>>) -> ()
293 call bar_integer(a%i)
294 end subroutine
296 ! CHECK-LABEL: func @_QPwhole_component_contiguous_pointer()
297 subroutine whole_component_contiguous_pointer()
298 ! Test no copy is made for whole contiguous pointer components.
299 type t
300 integer, pointer, contiguous :: i(:)
301 end type
302 ! CHECK: %[[a:.*]] = fir.alloca !fir.type<_QFwhole_component_contiguous_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>
303 type(t) :: a
304 ! CHECK: %[[field:.*]] = fir.field_index i, !fir.type<_QFwhole_component_contiguous_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>
305 ! CHECK: %[[coor:.*]] = fir.coordinate_of %[[a]], %[[field]] : (!fir.ref<!fir.type<_QFwhole_component_contiguous_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>, !fir.field) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>
306 ! CHECK: %[[box_load:.*]] = fir.load %[[coor]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>
307 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box_load]] : (!fir.box<!fir.ptr<!fir.array<?xi32>>>) -> !fir.ptr<!fir.array<?xi32>>
308 ! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.ptr<!fir.array<?xi32>>) -> !fir.ref<!fir.array<100xi32>>
309 ! CHECK: fir.call @_QPbar_integer(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<100xi32>>) -> ()
310 call bar_integer(a%i)
311 end subroutine
313 ! CHECK-LABEL: func @_QPwhole_component_contiguous_char_pointer()
314 subroutine whole_component_contiguous_char_pointer()
315 ! Test no copy is made for whole contiguous character pointer components.
316 type t
317 character(:), pointer, contiguous :: i(:)
318 end type
319 ! CHECK: %[[a:.*]] = fir.alloca !fir.type<_QFwhole_component_contiguous_char_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>}>
320 type(t) :: a
321 ! CHECK: %[[field:.*]] = fir.field_index i, !fir.type<_QFwhole_component_contiguous_char_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>}>
322 ! CHECK: %[[coor:.*]] = fir.coordinate_of %[[a]], %[[field]] : (!fir.ref<!fir.type<_QFwhole_component_contiguous_char_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>}>>, !fir.field) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>>
323 ! CHECK: %[[box_load:.*]] = fir.load %[[coor]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>>
324 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box_load]] : (!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>) -> !fir.ptr<!fir.array<?x!fir.char<1,?>>>
325 ! CHECK: %[[len:.*]] = fir.box_elesize %[[box_load]] : (!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>) -> index
326 ! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.ptr<!fir.array<?x!fir.char<1,?>>>) -> !fir.ref<!fir.char<1,?>>
327 ! CHECK: %[[embox:.*]] = fir.emboxchar %[[cast]], %[[len]] : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>
328 ! CHECK: fir.call @_QPbar_char_3(%[[embox]]) {{.*}}: (!fir.boxchar<1>) -> ()
329 call bar_char_3(a%i)
330 end subroutine