[flang][openacc] Use OpenACC terminator instead of fir.unreachable after Stop stmt...
[llvm-project.git] / flang / test / Lower / dummy-argument-assumed-shape-optional.f90
blob6a5a830fb67a532e9da62cfb7f926169e1125783
1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
2 module tests
3 interface
4 subroutine takes_contiguous(a)
5 real, contiguous :: a(:)
6 end subroutine
7 subroutine takes_contiguous_optional(a)
8 real, contiguous, optional :: a(:)
9 end subroutine
10 end interface
12 contains
14 ! -----------------------------------------------------------------------------
15 ! Test passing assumed shapes to contiguous assumed shapes
16 ! -----------------------------------------------------------------------------
17 ! Base case.
19 subroutine test_assumed_shape_to_contiguous(x)
20 real :: x(:)
21 call takes_contiguous(x)
22 end subroutine
23 ! CHECK-LABEL: func.func @_QMtestsPtest_assumed_shape_to_contiguous(
24 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) {
25 ! CHECK: %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
26 ! CHECK: %[[VAL_2:.*]] = fir.call @_FortranAIsContiguous(%[[VAL_1]]) {{.*}}: (!fir.box<none>) -> i1
27 ! CHECK: %[[VAL_3:.*]] = fir.if %[[VAL_2]] -> (!fir.heap<!fir.array<?xf32>>) {
28 ! CHECK: %[[VAL_4:.*]] = fir.box_addr %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.heap<!fir.array<?xf32>>
29 ! CHECK: fir.result %[[VAL_4]] : !fir.heap<!fir.array<?xf32>>
30 ! CHECK: } else {
31 ! CHECK: %[[VAL_7:.*]] = fir.allocmem !fir.array<?xf32>
32 ! CHECK: fir.call @_FortranAAssign
33 ! CHECK: fir.result %[[VAL_7]] : !fir.heap<!fir.array<?xf32>>
34 ! CHECK: }
35 ! CHECK: %[[VAL_20:.*]] = arith.constant 0 : index
36 ! CHECK: %[[VAL_21:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_20]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
37 ! CHECK: %[[VAL_22:.*]] = arith.constant false
38 ! CHECK: %[[VAL_23:.*]] = arith.cmpi eq, %[[VAL_2]], %[[VAL_22]] : i1
39 ! CHECK: %[[VAL_24:.*]] = fir.shape %[[VAL_21]]#1 : (index) -> !fir.shape<1>
40 ! CHECK: %[[VAL_25:.*]] = fir.embox %[[VAL_3]](%[[VAL_24]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
41 ! CHECK: fir.call @_QPtakes_contiguous(%[[VAL_25]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
42 ! CHECK: fir.if %[[VAL_23]] {
43 ! CHECK: fir.call @_FortranACopyOutAssign
44 ! CHECK: fir.freemem %[[VAL_3]] : !fir.heap<!fir.array<?xf32>>
45 ! CHECK: }
46 ! CHECK: return
47 ! CHECK:}
49 subroutine test_assumed_shape_contiguous_to_contiguous(x)
50 real, contiguous :: x(:)
51 call takes_contiguous(x)
52 end subroutine
53 ! CHECK-LABEL: func.func @_QMtestsPtest_assumed_shape_contiguous_to_contiguous(
54 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x", fir.contiguous}) {
55 ! CHECK: %[[VAL_1:.*]] = fir.box_addr %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
56 ! CHECK: %[[VAL_2:.*]] = arith.constant 0 : index
57 ! CHECK: %[[VAL_3:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_2]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
58 ! CHECK: %[[VAL_4:.*]] = arith.constant 1 : index
59 ! CHECK: %[[VAL_5:.*]] = fir.shape_shift %[[VAL_4]], %[[VAL_3]]#1 : (index, index) -> !fir.shapeshift<1>
60 ! CHECK: %[[VAL_6:.*]] = fir.embox %[[VAL_1]](%[[VAL_5]]) : (!fir.ref<!fir.array<?xf32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<?xf32>>
61 ! CHECK: fir.call @_QPtakes_contiguous(%[[VAL_6]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
62 ! CHECK-NEXT: return
64 subroutine test_assumed_shape_opt_to_contiguous(x)
65 real, optional :: x(:)
66 call takes_contiguous(x)
67 end subroutine
68 ! CHECK-LABEL: func.func @_QMtestsPtest_assumed_shape_opt_to_contiguous(
69 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x", fir.optional}) {
70 ! CHECK: %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
71 ! CHECK: %[[VAL_2:.*]] = fir.call @_FortranAIsContiguous(%[[VAL_1]]) {{.*}}: (!fir.box<none>) -> i1
72 ! CHECK: %[[VAL_3:.*]] = fir.if %[[VAL_2]] -> (!fir.heap<!fir.array<?xf32>>) {
73 ! CHECK: %[[VAL_4:.*]] = fir.box_addr %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.heap<!fir.array<?xf32>>
74 ! CHECK: fir.result %[[VAL_4]] : !fir.heap<!fir.array<?xf32>>
75 ! CHECK: } else {
76 ! CHECK: %[[VAL_7:.*]] = fir.allocmem !fir.array<?xf32>
77 ! CHECK: fir.call @_FortranAAssign
78 ! CHECK: fir.result %[[VAL_7]] : !fir.heap<!fir.array<?xf32>>
79 ! CHECK: }
80 ! CHECK: %[[VAL_20:.*]] = arith.constant 0 : index
81 ! CHECK: %[[VAL_21:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_20]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
82 ! CHECK: %[[VAL_22:.*]] = arith.constant false
83 ! CHECK: %[[VAL_23:.*]] = arith.cmpi eq, %[[VAL_2]], %[[VAL_22]] : i1
84 ! CHECK: %[[VAL_24:.*]] = fir.shape %[[VAL_21]]#1 : (index) -> !fir.shape<1>
85 ! CHECK: %[[VAL_25:.*]] = fir.embox %[[VAL_3]](%[[VAL_24]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
86 ! CHECK: fir.call @_QPtakes_contiguous(%[[VAL_25]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
87 ! CHECK: fir.if %[[VAL_23]] {
88 ! CHECK: fir.call @_FortranACopyOutAssign
89 ! CHECK: fir.freemem %[[VAL_3]] : !fir.heap<!fir.array<?xf32>>
90 ! CHECK: }
91 ! CHECK: return
92 ! CHECK:}
94 subroutine test_assumed_shape_contiguous_opt_to_contiguous(x)
95 real, optional, contiguous :: x(:)
96 call takes_contiguous(x)
97 end subroutine
98 ! CHECK-LABEL: func.func @_QMtestsPtest_assumed_shape_contiguous_opt_to_contiguous(
99 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x", fir.contiguous, fir.optional}) {
100 ! CHECK: fir.call @_QPtakes_contiguous(%[[VAL_0]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
101 ! CHECK-NEXT: return
104 ! -----------------------------------------------------------------------------
105 ! Test passing assumed shapes to contiguous optional assumed shapes
106 ! -----------------------------------------------------------------------------
107 ! The copy-in/out must take into account the actual argument presence (which may
108 ! not be known until runtime).
110 subroutine test_assumed_shape_to_contiguous_opt(x)
111 real :: x(:)
112 call takes_contiguous_optional(x)
113 end subroutine
114 ! CHECK-LABEL: func.func @_QMtestsPtest_assumed_shape_to_contiguous_opt(
115 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) {
116 ! CHECK: %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
117 ! CHECK: %[[VAL_2:.*]] = fir.call @_FortranAIsContiguous(%[[VAL_1]]) {{.*}}: (!fir.box<none>) -> i1
118 ! CHECK: %[[VAL_3:.*]] = fir.if %[[VAL_2]] -> (!fir.heap<!fir.array<?xf32>>) {
119 ! CHECK: %[[VAL_4:.*]] = fir.box_addr %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.heap<!fir.array<?xf32>>
120 ! CHECK: fir.result %[[VAL_4]] : !fir.heap<!fir.array<?xf32>>
121 ! CHECK: } else {
122 ! CHECK: %[[VAL_7:.*]] = fir.allocmem !fir.array<?xf32>
123 ! CHECK: fir.call @_FortranAAssign
124 ! CHECK: fir.result %[[VAL_7]] : !fir.heap<!fir.array<?xf32>>
125 ! CHECK: }
126 ! CHECK: %[[VAL_20:.*]] = arith.constant 0 : index
127 ! CHECK: %[[VAL_21:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_20]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
128 ! CHECK: %[[VAL_22:.*]] = arith.constant false
129 ! CHECK: %[[VAL_23:.*]] = arith.cmpi eq, %[[VAL_2]], %[[VAL_22]] : i1
130 ! CHECK: %[[VAL_24:.*]] = fir.shape %[[VAL_21]]#1 : (index) -> !fir.shape<1>
131 ! CHECK: %[[VAL_25:.*]] = fir.embox %[[VAL_3]](%[[VAL_24]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
132 ! CHECK: fir.call @_QPtakes_contiguous_optional(%[[VAL_25]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
133 ! CHECK: fir.if %[[VAL_23]] {
134 ! CHECK: fir.call @_FortranACopyOutAssign
135 ! CHECK: fir.freemem %[[VAL_3]] : !fir.heap<!fir.array<?xf32>>
136 ! CHECK: }
137 ! CHECK: return
138 ! CHECK:}
140 subroutine test_assumed_shape_contiguous_to_contiguous_opt(x)
141 real, contiguous :: x(:)
142 call takes_contiguous_optional(x)
143 end subroutine
144 ! CHECK-LABEL: func.func @_QMtestsPtest_assumed_shape_contiguous_to_contiguous_opt(
145 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x", fir.contiguous}) {
146 ! CHECK: %[[VAL_1:.*]] = fir.box_addr %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
147 ! CHECK: %[[VAL_2:.*]] = arith.constant 0 : index
148 ! CHECK: %[[VAL_3:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_2]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
149 ! CHECK: %[[VAL_4:.*]] = arith.constant 1 : index
150 ! CHECK: %[[VAL_5:.*]] = fir.shape_shift %[[VAL_4]], %[[VAL_3]]#1 : (index, index) -> !fir.shapeshift<1>
151 ! CHECK: %[[VAL_6:.*]] = fir.embox %[[VAL_1]](%[[VAL_5]]) : (!fir.ref<!fir.array<?xf32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<?xf32>>
152 ! CHECK: fir.call @_QPtakes_contiguous_optional(%[[VAL_6]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
153 ! CHECK-NEXT: return
155 subroutine test_assumed_shape_opt_to_contiguous_opt(x)
156 real, optional :: x(:)
157 call takes_contiguous_optional(x)
158 end subroutine
159 ! CHECK-LABEL: func.func @_QMtestsPtest_assumed_shape_opt_to_contiguous_opt(
160 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x", fir.optional}) {
161 ! CHECK: %[[VAL_1:.*]] = fir.is_present %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> i1
162 ! CHECK: %[[VAL_2:.*]] = fir.zero_bits !fir.ref<!fir.array<?xf32>>
163 ! CHECK: %[[VAL_3:.*]] = arith.constant 0 : index
164 ! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1>
165 ! CHECK: %[[VAL_5:.*]] = fir.embox %[[VAL_2]](%[[VAL_4]]) : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
166 ! CHECK: %[[VAL_6:.*]] = arith.select %[[VAL_1]], %[[VAL_0]], %[[VAL_5]] : !fir.box<!fir.array<?xf32>>
167 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
168 ! CHECK: %[[VAL_8:.*]] = fir.call @_FortranAIsContiguous(%[[VAL_7]]) {{.*}}: (!fir.box<none>) -> i1
169 ! CHECK: %[[VAL_9:.*]] = fir.if %[[VAL_1]] -> (!fir.heap<!fir.array<?xf32>>) {
170 ! CHECK: %[[VAL_10:.*]] = fir.if %[[VAL_8]] -> (!fir.heap<!fir.array<?xf32>>) {
171 ! CHECK: %[[VAL_11:.*]] = fir.box_addr %[[VAL_6]] : (!fir.box<!fir.array<?xf32>>) -> !fir.heap<!fir.array<?xf32>>
172 ! CHECK: fir.result %[[VAL_11]] : !fir.heap<!fir.array<?xf32>>
173 ! CHECK: } else {
174 ! CHECK: %[[VAL_14:.*]] = fir.allocmem !fir.array<?xf32>
175 ! CHECK: fir.call @_FortranAAssign
176 ! CHECK: fir.result %[[VAL_14]] : !fir.heap<!fir.array<?xf32>>
177 ! CHECK: }
178 ! CHECK: fir.result %[[VAL_10]] : !fir.heap<!fir.array<?xf32>>
179 ! CHECK: } else {
180 ! CHECK: %[[VAL_28:.*]] = fir.zero_bits !fir.heap<!fir.array<?xf32>>
181 ! CHECK: fir.result %[[VAL_28]] : !fir.heap<!fir.array<?xf32>>
182 ! CHECK: }
183 ! CHECK: %[[VAL_29:.*]] = arith.constant 0 : index
184 ! CHECK: %[[VAL_30:.*]]:3 = fir.box_dims %[[VAL_6]], %[[VAL_29]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
185 ! CHECK: %[[VAL_31:.*]] = arith.constant false
186 ! CHECK: %[[VAL_32:.*]] = arith.cmpi eq, %[[VAL_8]], %[[VAL_31]] : i1
187 ! CHECK: %[[VAL_33:.*]] = arith.andi %[[VAL_1]], %[[VAL_32]] : i1
188 ! CHECK: %[[VAL_34:.*]] = fir.shape %[[VAL_30]]#1 : (index) -> !fir.shape<1>
189 ! CHECK: %[[VAL_35:.*]] = fir.embox %[[VAL_9]](%[[VAL_34]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
190 ! CHECK: %[[VAL_37:.*]] = fir.absent !fir.box<!fir.array<?xf32>>
191 ! CHECK: %[[VAL_38:.*]] = arith.select %[[VAL_1]], %[[VAL_35]], %[[VAL_37]] : !fir.box<!fir.array<?xf32>>
192 ! CHECK: fir.call @_QPtakes_contiguous_optional(%[[VAL_38]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
193 ! CHECK: fir.if %[[VAL_33]] {
194 ! CHECK: fir.call @_FortranACopyOutAssign
195 ! CHECK: fir.freemem %[[VAL_9]] : !fir.heap<!fir.array<?xf32>>
196 ! CHECK: }
197 ! CHECK: return
198 ! CHECK:}
200 subroutine test_assumed_shape_contiguous_opt_to_contiguous_opt(x)
201 real, contiguous, optional :: x(:)
202 call takes_contiguous_optional(x)
203 end subroutine
204 ! CHECK-LABEL: func.func @_QMtestsPtest_assumed_shape_contiguous_opt_to_contiguous_opt(
205 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x", fir.contiguous, fir.optional}) {
206 ! CHECK: fir.call @_QPtakes_contiguous_optional(%[[VAL_0]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
207 ! CHECK-NEXT: return
209 ! -----------------------------------------------------------------------------
210 ! Test passing pointers to contiguous optional assumed shapes
211 ! -----------------------------------------------------------------------------
212 ! This case is interesting because pointers may be non contiguous, and also because
213 ! a pointer passed to an optional assumed shape dummy is present if and only if the
214 ! pointer is associated (regardless of the pointer optionality).
216 subroutine test_pointer_to_contiguous_opt(x)
217 real, pointer :: x(:)
218 call takes_contiguous_optional(x)
219 end subroutine
220 ! CHECK-LABEL: func.func @_QMtestsPtest_pointer_to_contiguous_opt(
221 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "x"}) {
222 ! CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
223 ! CHECK: %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.ptr<!fir.array<?xf32>>
224 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ptr<!fir.array<?xf32>>) -> i64
225 ! CHECK: %[[VAL_4:.*]] = arith.constant 0 : i64
226 ! CHECK: %[[VAL_5:.*]] = arith.cmpi ne, %[[VAL_3]], %[[VAL_4]] : i64
227 ! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
228 ! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index
229 ! CHECK: %[[VAL_8:.*]]:3 = fir.box_dims %[[VAL_6]], %[[VAL_7]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, index) -> (index, index, index)
230 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_6]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.box<none>
231 ! CHECK: %[[VAL_10:.*]] = fir.call @_FortranAIsContiguous(%[[VAL_9]]) {{.*}}: (!fir.box<none>) -> i1
232 ! CHECK: %[[VAL_11:.*]] = fir.if %[[VAL_5]] -> (!fir.heap<!fir.array<?xf32>>) {
233 ! CHECK: %[[VAL_12:.*]] = fir.if %[[VAL_10]] -> (!fir.heap<!fir.array<?xf32>>) {
234 ! CHECK: %[[VAL_13:.*]] = fir.box_addr %[[VAL_6]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
235 ! CHECK: fir.result %[[VAL_13]] : !fir.heap<!fir.array<?xf32>>
236 ! CHECK: } else {
237 ! CHECK: %[[VAL_16:.*]] = fir.allocmem !fir.array<?xf32>
238 ! CHECK: fir.call @_FortranAAssign
239 ! CHECK: fir.result %[[VAL_16]] : !fir.heap<!fir.array<?xf32>>
240 ! CHECK: }
241 ! CHECK: fir.result %[[VAL_12]] : !fir.heap<!fir.array<?xf32>>
242 ! CHECK: } else {
243 ! CHECK: %[[VAL_31:.*]] = fir.zero_bits !fir.heap<!fir.array<?xf32>>
244 ! CHECK: fir.result %[[VAL_31]] : !fir.heap<!fir.array<?xf32>>
245 ! CHECK: }
246 ! CHECK: %[[VAL_32:.*]] = arith.constant 0 : index
247 ! CHECK: %[[VAL_33:.*]]:3 = fir.box_dims %[[VAL_6]], %[[VAL_32]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, index) -> (index, index, index)
248 ! CHECK: %[[VAL_34:.*]] = arith.constant false
249 ! CHECK: %[[VAL_35:.*]] = arith.cmpi eq, %[[VAL_10]], %[[VAL_34]] : i1
250 ! CHECK: %[[VAL_36:.*]] = arith.andi %[[VAL_5]], %[[VAL_35]] : i1
251 ! CHECK: %[[VAL_37:.*]] = fir.shape_shift %[[VAL_8]]#0, %[[VAL_33]]#1 : (index, index) -> !fir.shapeshift<1>
252 ! CHECK: %[[VAL_38:.*]] = fir.embox %[[VAL_11]](%[[VAL_37]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<?xf32>>
253 ! CHECK: %[[VAL_40:.*]] = fir.absent !fir.box<!fir.array<?xf32>>
254 ! CHECK: %[[VAL_41:.*]] = arith.select %[[VAL_5]], %[[VAL_38]], %[[VAL_40]] : !fir.box<!fir.array<?xf32>>
255 ! CHECK: fir.call @_QPtakes_contiguous_optional(%[[VAL_41]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
256 ! CHECK: fir.if %[[VAL_36]] {
257 ! CHECK: fir.call @_FortranACopyOutAssign
258 ! CHECK: fir.freemem %[[VAL_11]] : !fir.heap<!fir.array<?xf32>>
259 ! CHECK: }
260 ! CHECK: return
261 ! CHECK:}
263 subroutine test_pointer_contiguous_to_contiguous_opt(x)
264 real, pointer, contiguous :: x(:)
265 call takes_contiguous_optional(x)
266 end subroutine
267 ! CHECK-LABEL: func.func @_QMtestsPtest_pointer_contiguous_to_contiguous_opt(
268 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "x", fir.contiguous}) {
269 ! CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
270 ! CHECK: %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.ptr<!fir.array<?xf32>>
271 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ptr<!fir.array<?xf32>>) -> i64
272 ! CHECK: %[[VAL_4:.*]] = arith.constant 0 : i64
273 ! CHECK: %[[VAL_5:.*]] = arith.cmpi ne, %[[VAL_3]], %[[VAL_4]] : i64
274 ! CHECK: %[[VAL_6:.*]] = fir.absent !fir.box<!fir.array<?xf32>>
275 ! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
276 ! CHECK: %[[VAL_8:.*]] = arith.constant 0 : index
277 ! CHECK: %[[VAL_9:.*]]:3 = fir.box_dims %[[VAL_7]], %[[VAL_8]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, index) -> (index, index, index)
278 ! CHECK: %[[VAL_10:.*]] = fir.box_addr %[[VAL_7]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.ptr<!fir.array<?xf32>>
279 ! CHECK: %[[VAL_11:.*]] = fir.shape_shift %[[VAL_9]]#0, %[[VAL_9]]#1 : (index, index) -> !fir.shapeshift<1>
280 ! CHECK: %[[VAL_12:.*]] = fir.embox %[[VAL_10]](%[[VAL_11]]) : (!fir.ptr<!fir.array<?xf32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<?xf32>>
281 ! CHECK: %[[VAL_13:.*]] = arith.select %[[VAL_5]], %[[VAL_12]], %[[VAL_6]] : !fir.box<!fir.array<?xf32>>
282 ! CHECK: fir.call @_QPtakes_contiguous_optional(%[[VAL_13]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
283 ! CHECK-NEXT: return
285 subroutine test_pointer_opt_to_contiguous_opt(x)
286 real, pointer, optional :: x(:)
287 call takes_contiguous_optional(x)
288 end subroutine
289 ! CHECK-LABEL: func.func @_QMtestsPtest_pointer_opt_to_contiguous_opt(
290 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "x", fir.optional}) {
291 ! CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
292 ! CHECK: %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.ptr<!fir.array<?xf32>>
293 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ptr<!fir.array<?xf32>>) -> i64
294 ! CHECK: %[[VAL_4:.*]] = arith.constant 0 : i64
295 ! CHECK: %[[VAL_5:.*]] = arith.cmpi ne, %[[VAL_3]], %[[VAL_4]] : i64
296 ! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
297 ! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index
298 ! CHECK: %[[VAL_8:.*]]:3 = fir.box_dims %[[VAL_6]], %[[VAL_7]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, index) -> (index, index, index)
299 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_6]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.box<none>
300 ! CHECK: %[[VAL_10:.*]] = fir.call @_FortranAIsContiguous(%[[VAL_9]]) {{.*}}: (!fir.box<none>) -> i1
301 ! CHECK: %[[VAL_11:.*]] = fir.if %[[VAL_5]] -> (!fir.heap<!fir.array<?xf32>>) {
302 ! CHECK: %[[VAL_12:.*]] = fir.if %[[VAL_10]] -> (!fir.heap<!fir.array<?xf32>>) {
303 ! CHECK: %[[VAL_13:.*]] = fir.box_addr %[[VAL_6]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
304 ! CHECK: fir.result %[[VAL_13]] : !fir.heap<!fir.array<?xf32>>
305 ! CHECK: } else {
306 ! CHECK: %[[VAL_16:.*]] = fir.allocmem !fir.array<?xf32>
307 ! CHECK: fir.call @_FortranAAssign
308 ! CHECK: fir.result %[[VAL_16]] : !fir.heap<!fir.array<?xf32>>
309 ! CHECK: }
310 ! CHECK: fir.result %[[VAL_12]] : !fir.heap<!fir.array<?xf32>>
311 ! CHECK: } else {
312 ! CHECK: %[[VAL_31:.*]] = fir.zero_bits !fir.heap<!fir.array<?xf32>>
313 ! CHECK: fir.result %[[VAL_31]] : !fir.heap<!fir.array<?xf32>>
314 ! CHECK: }
315 ! CHECK: %[[VAL_32:.*]] = arith.constant 0 : index
316 ! CHECK: %[[VAL_33:.*]]:3 = fir.box_dims %[[VAL_6]], %[[VAL_32]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, index) -> (index, index, index)
317 ! CHECK: %[[VAL_34:.*]] = arith.constant false
318 ! CHECK: %[[VAL_35:.*]] = arith.cmpi eq, %[[VAL_10]], %[[VAL_34]] : i1
319 ! CHECK: %[[VAL_36:.*]] = arith.andi %[[VAL_5]], %[[VAL_35]] : i1
320 ! CHECK: %[[VAL_37:.*]] = fir.shape_shift %[[VAL_8]]#0, %[[VAL_33]]#1 : (index, index) -> !fir.shapeshift<1>
321 ! CHECK: %[[VAL_38:.*]] = fir.embox %[[VAL_11]](%[[VAL_37]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<?xf32>>
322 ! CHECK: %[[VAL_40:.*]] = fir.absent !fir.box<!fir.array<?xf32>>
323 ! CHECK: %[[VAL_41:.*]] = arith.select %[[VAL_5]], %[[VAL_38]], %[[VAL_40]] : !fir.box<!fir.array<?xf32>>
324 ! CHECK: fir.call @_QPtakes_contiguous_optional(%[[VAL_41]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
325 ! CHECK: fir.if %[[VAL_36]] {
326 ! CHECK: fir.call @_FortranACopyOutAssign
327 ! CHECK: fir.freemem %[[VAL_11]] : !fir.heap<!fir.array<?xf32>>
328 ! CHECK: }
329 ! CHECK: return
330 ! CHECK:}
332 subroutine test_pointer_contiguous_opt_to_contiguous_opt(x)
333 real, pointer, contiguous, optional :: x(:)
334 call takes_contiguous_optional(x)
335 end subroutine
336 ! CHECK-LABEL: func.func @_QMtestsPtest_pointer_contiguous_opt_to_contiguous_opt(
337 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "x", fir.contiguous, fir.optional}) {
338 ! CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
339 ! CHECK: %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.ptr<!fir.array<?xf32>>
340 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ptr<!fir.array<?xf32>>) -> i64
341 ! CHECK: %[[VAL_4:.*]] = arith.constant 0 : i64
342 ! CHECK: %[[VAL_5:.*]] = arith.cmpi ne, %[[VAL_3]], %[[VAL_4]] : i64
343 ! CHECK: %[[VAL_6:.*]] = fir.absent !fir.box<!fir.array<?xf32>>
344 ! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
345 ! CHECK: %[[VAL_8:.*]] = arith.constant 0 : index
346 ! CHECK: %[[VAL_9:.*]]:3 = fir.box_dims %[[VAL_7]], %[[VAL_8]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, index) -> (index, index, index)
347 ! CHECK: %[[VAL_10:.*]] = fir.box_addr %[[VAL_7]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.ptr<!fir.array<?xf32>>
348 ! CHECK: %[[VAL_11:.*]] = fir.shape_shift %[[VAL_9]]#0, %[[VAL_9]]#1 : (index, index) -> !fir.shapeshift<1>
349 ! CHECK: %[[VAL_12:.*]] = fir.embox %[[VAL_10]](%[[VAL_11]]) : (!fir.ptr<!fir.array<?xf32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<?xf32>>
350 ! CHECK: %[[VAL_13:.*]] = arith.select %[[VAL_5]], %[[VAL_12]], %[[VAL_6]] : !fir.box<!fir.array<?xf32>>
351 ! CHECK-NEXT: fir.call @_QPtakes_contiguous_optional(%[[VAL_13]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()
352 ! CHECK: return
353 end module