Debian Codegraph @

flang/test/Fir/invalid.fir

raw
1 // RUN: fir-opt -split-input-file -verify-diagnostics --strict-fir-volatile-verifier %s
2
3 // expected-error@+1{{custom op 'fir.string_lit' must have character type}}
4 %0 = fir.string_lit "Hello, World!"(13) : !fir.int<32>
5
6 // -----
7
8 // expected-error@+1{{custom op 'fir.string_lit' found an invalid constant}}
9 %0 = fir.string_lit 20(13) : !fir.int<32>
10
11 // -----
12
13 // expected-error@+1{{'fir.string_lit' op values in initializer must be integers}}
14 %2 = fir.string_lit [158, 2.0](2) : !fir.char<2>
15
16 // -----
17
18 func.func @bad_rebox_1(%arg0: !fir.ref<!fir.array<?x?xf32>>) {
19 %c10 = arith.constant 10 : index
20 %0 = fir.shape %c10 : (index) -> !fir.shape<1>
21 // expected-error@+1{{op operand #0 must be box or class, but got '!fir.ref<!fir.array<?x?xf32>>'}}
22 %1 = fir.rebox %arg0(%0) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
23 return
24 }
25
26 // -----
27
28 func.func @bad_rebox_2(%arg0: !fir.box<!fir.array<?x?xf32>>) {
29 %c10 = arith.constant 10 : index
30 %0 = fir.shape %c10 : (index) -> !fir.shape<1>
31 // expected-error@+1{{op result #0 must be box or class, but got '!fir.ref<!fir.array<?xf32>>'}}
32 %1 = fir.rebox %arg0(%0) : (!fir.box<!fir.array<?x?xf32>>, !fir.shape<1>) -> !fir.ref<!fir.array<?xf32>>
33 return
34 }
35
36 // -----
37
38 func.func @bad_rebox_3(%arg0: !fir.box<!fir.array<*:f32>>) {
39 %c10 = arith.constant 10 : index
40 %0 = fir.shape %c10 : (index) -> !fir.shape<1>
41 // expected-error@+1{{op box operand must not have unknown rank or type}}
42 %1 = fir.rebox %arg0(%0) : (!fir.box<!fir.array<*:f32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
43 return
44 }
45
46 // -----
47
48 func.func @bad_rebox_4(%arg0: !fir.box<!fir.array<?xf32>>) {
49 // expected-error@+1{{op result type must not have unknown rank or type}}
50 %0 = fir.rebox %arg0 : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<*:f32>>
51 return
52 }
53
54 // -----
55
56 func.func @bad_rebox_5(%arg0: !fir.box<!fir.array<?x?xf32>>) {
57 %c1 = arith.constant 1 : index
58 %c10 = arith.constant 10 : index
59 %0 = fir.slice %c1, %c10, %c1 : (index, index, index) -> !fir.slice<1>
60 // expected-error@+1{{op slice operand rank must match box operand rank}}
61 %1 = fir.rebox %arg0 [%0] : (!fir.box<!fir.array<?x?xf32>>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
62 return
63 }
64
65 // -----
66
67 func.func @bad_rebox_6(%arg0: !fir.box<!fir.array<?xf32>>) {
68 %c1 = arith.constant 1 : index
69 %c10 = arith.constant 10 : index
70 %0 = fir.slice %c1, %c10, %c1 : (index, index, index) -> !fir.slice<1>
71 %1 = fir.shift %c1, %c1 : (index, index) -> !fir.shift<2>
72 // expected-error@+1{{shape operand and input box ranks must match when there is a slice}}
73 %2 = fir.rebox %arg0(%1) [%0] : (!fir.box<!fir.array<?xf32>>, !fir.shift<2>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
74 return
75 }
76
77 // -----
78
79 func.func @bad_rebox_7(%arg0: !fir.box<!fir.array<?xf32>>) {
80 %c1 = arith.constant 1 : index
81 %c10 = arith.constant 10 : index
82 %0 = fir.slice %c1, %c10, %c1 : (index, index, index) -> !fir.slice<1>
83 %1 = fir.shape %c10 : (index) -> !fir.shape<1>
84 // expected-error@+1{{shape operand must absent or be a fir.shift when there is a slice}}
85 %2 = fir.rebox %arg0(%1) [%0] : (!fir.box<!fir.array<?xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
86 return
87 }
88
89 // -----
90
91 func.func @bad_rebox_8(%arg0: !fir.box<!fir.array<?x?xf32>>) {
92 %c1 = arith.constant 1 : index
93 %c10 = arith.constant 10 : index
94 %undef = fir.undefined index
95 %0 = fir.slice %c1, %undef, %undef, %c1, %c10, %c1 : (index, index, index, index, index, index) -> !fir.slice<2>
96 // expected-error@+1{{result type rank and rank after applying slice operand must match}}
97 %1 = fir.rebox %arg0 [%0] : (!fir.box<!fir.array<?x?xf32>>, !fir.slice<2>) -> !fir.box<!fir.array<?x?xf32>>
98 return
99 }
100
101 // -----
102
103 func.func @bad_rebox_9(%arg0: !fir.box<!fir.array<?xf32>>) {
104 %c10 = arith.constant 10 : index
105 %0 = fir.shift %c10, %c10 : (index, index) -> !fir.shift<2>
106 // expected-error@+1{{shape operand and input box ranks must match when the shape is a fir.shift}}
107 %1 = fir.rebox %arg0(%0) : (!fir.box<!fir.array<?xf32>>, !fir.shift<2>) -> !fir.box<!fir.array<?x?xf32>>
108 return
109 }
110
111 // -----
112
113 func.func @bad_rebox_10(%arg0: !fir.box<!fir.array<?xf32>>) {
114 %c10 = arith.constant 10 : index
115 %0 = fir.shape %c10, %c10 : (index, index) -> !fir.shape<2>
116 // expected-error@+1{{result type and shape operand ranks must match}}
117 %1 = fir.rebox %arg0(%0) : (!fir.box<!fir.array<?xf32>>, !fir.shape<2>) -> !fir.box<!fir.array<?xf32>>
118 return
119 }
120
121 // -----
122
123 func.func @bad_rebox_11(%arg0: !fir.box<!fir.array<?x?xf32>>) {
124 %c42 = arith.constant 42 : index
125 %0 = fir.shape %c42 : (index) -> !fir.shape<1>
126 // expected-error@+1{{op input and output element types must match for intrinsic types}}
127 %1 = fir.rebox %arg0(%0) : (!fir.box<!fir.array<?x?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf64>>
128 return
129 }
130
131 // -----
132
133 func.func @test_rebox_char(%arg0: !fir.box<!fir.array<?x!fir.char<1,20>>>) {
134 %c10 = arith.constant 10 : index
135 %1 = fir.shape %c10, %c10 : (index, index) -> !fir.shape<2>
136 // expected-error@+1{{op input and output element types must match for intrinsic types}}
137 %2 = fir.rebox %arg0(%1) : (!fir.box<!fir.array<?x!fir.char<1,20>>>, !fir.shape<2>) -> !fir.box<!fir.array<10x10x!fir.char<1,10>>>
138 return
139 }
140
141 // -----
142
143 func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
144 %c1 = arith.constant 1 : index
145 %c100 = arith.constant 100 : index
146 %c50 = arith.constant 50 : index
147 %shape = fir.shape %c100, %c50 : (index, index) -> !fir.shape<2>
148 // expected-error@+1 {{'fir.array_coor' op operand #0 must be any reference or box, but got 'index'}}
149 %p = fir.array_coor %c100(%shape) %c1, %c1 : (index, !fir.shape<2>, index, index) -> !fir.ref<f32>
150 return
151 }
152
153 // -----
154
155 func.func @array_access(%arr : !fir.ref<f32>) {
156 %c1 = arith.constant 1 : index
157 %c100 = arith.constant 100 : index
158 %c50 = arith.constant 50 : index
159 %shape = fir.shape %c100, %c50 : (index, index) -> !fir.shape<2>
160 // expected-error@+1 {{'fir.array_coor' op must be a reference to an array}}
161 %p = fir.array_coor %arr(%shape) %c1, %c1 : (!fir.ref<f32>, !fir.shape<2>, index, index) -> !fir.ref<f32>
162 return
163 }
164
165 // -----
166
167 func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
168 %c1 = arith.constant 1 : index
169 %c100 = arith.constant 100 : index
170 %c50 = arith.constant 50 : index
171 %shape = fir.shape %c100, %c50 : (index, index) -> !fir.shape<2>
172 %c47 = arith.constant 47 : index
173 %c78 = arith.constant 78 : index
174 %c3 = arith.constant 3 : index
175 %slice = fir.slice %c47, %c78, %c3 : (index,index,index) -> !fir.slice<1>
176 // expected-error@+1 {{'fir.array_coor' op rank of dimension in slice mismatched}}
177 %p = fir.array_coor %arr(%shape)[%slice] %c1, %c1 : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>, !fir.slice<1>, index, index) -> !fir.ref<f32>
178 return
179 }
180
181 // -----
182
183 func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
184 %c1 = arith.constant 1 : index
185 %c100 = arith.constant 100 : index
186 %shape = fir.shape %c100 : (index) -> !fir.shape<1>
187 // expected-error@+1 {{'fir.array_coor' op rank of dimension mismatched}}
188 %p = fir.array_coor %arr(%shape) %c1, %c1 : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<1>, index, index) -> !fir.ref<f32>
189 return
190 }
191
192 // -----
193
194 func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
195 %c1 = arith.constant 1 : index
196 %c100 = arith.constant 100 : index
197 %shift = fir.shift %c1 : (index) -> !fir.shift<1>
198 // expected-error@+1 {{'fir.array_coor' op shift can only be provided with fir.box memref}}
199 %p = fir.array_coor %arr(%shift) %c1, %c1 : (!fir.ref<!fir.array<?x?xf32>>, !fir.shift<1>, index, index) -> !fir.ref<f32>
200 return
201 }
202
203 // -----
204
205 func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
206 %c1 = arith.constant 1 : index
207 %c100 = arith.constant 100 : index
208 %c50 = arith.constant 50 : index
209 %shape = fir.shape %c100, %c50 : (index, index) -> !fir.shape<2>
210 // expected-error@+1 {{'fir.array_coor' op number of indices do not match dim rank}}
211 %p = fir.array_coor %arr(%shape) %c1 : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>, index) -> !fir.ref<f32>
212 return
213 }
214
215 // -----
216
217 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
218 %c2 = arith.constant 2 : index
219 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
220 // expected-error@+1 {{'fir.array_load' op operand #0 must be any reference or box, but got 'index'}}
221 %av1 = fir.array_load %c2(%s) : (index, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
222 return
223 }
224
225 // -----
226
227 func.func @test_misc_ops(%arr1 : !fir.ref<f32>, %m : index, %n : index, %o : index, %p : index) {
228 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
229 // expected-error@+1 {{'fir.array_load' op must be a reference to an array}}
230 %av1 = fir.array_load %arr1(%s) : (!fir.ref<f32>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
231 return
232 }
233
234 // -----
235
236 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
237 %s = fir.shape_shift %m, %n: (index, index) -> !fir.shapeshift<1>
238 // expected-error@+1 {{'fir.array_load' op rank of dimension mismatched}}
239 %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<1>) -> !fir.array<?x?xf32>
240 return
241 }
242
243 // -----
244
245 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
246 %c2 = arith.constant 2 : index
247 %shift = fir.shift %c2 : (index) -> !fir.shift<1>
248 // expected-error@+1 {{'fir.array_load' op shift can only be provided with fir.box memref}}
249 %av1 = fir.array_load %arr1(%shift) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shift<1>) -> !fir.array<?x?xf32>
250 return
251 }
252
253 // -----
254
255 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
256 %c47 = arith.constant 47 : index
257 %c78 = arith.constant 78 : index
258 %c3 = arith.constant 3 : index
259 %slice = fir.slice %c47, %c78, %c3 : (index,index,index) -> !fir.slice<1>
260 %s = fir.shape_shift %m, %n, %o, %p: (index, index, index, index) -> !fir.shapeshift<2>
261 // expected-error@+1 {{'fir.array_load' op rank of dimension in slice mismatched}}
262 %av1 = fir.array_load %arr1(%s)[%slice] : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>, !fir.slice<1>) -> !fir.array<?x?xf32>
263 return
264 }
265
266 // -----
267
268 func.func @test_coordinate_of(%arr : !fir.ref<!fir.array<?x?xf32>>) {
269 %1 = arith.constant 10 : i32
270 // expected-error@+1 {{'fir.coordinate_of' op cannot find coordinate with unknown extents}}
271 %2 = fir.coordinate_of %arr, %1 : (!fir.ref<!fir.array<?x?xf32>>, i32) -> !fir.ref<f32>
272 return
273 }
274
275 // -----
276
277 func.func @test_coordinate_of(%arr : !fir.ref<!fir.array<*:f32>>) {
278 %1 = arith.constant 10 : i32
279 // expected-error@+1 {{'fir.coordinate_of' op cannot find coordinate in unknown shape}}
280 %2 = fir.coordinate_of %arr, %1 : (!fir.ref<!fir.array<*:f32>>, i32) -> !fir.ref<f32>
281 return
282 }
283
284 // -----
285
286 func.func @test_coordinate_of(%arr : !fir.ref<!fir.char<10>>) {
287 %1 = arith.constant 10 : i32
288 // expected-error@+1 {{'fir.coordinate_of' op cannot apply to this element type}}
289 %2 = fir.coordinate_of %arr, %1 : (!fir.ref<!fir.char<10>>, i32) -> !fir.ref<!fir.char<10>>
290 return
291 }
292
293 // -----
294
295 func.func @test_coordinate_of(%arr : !fir.ref<!fir.char<10, 2>>) {
296 %1 = arith.constant 10 : i32
297 // expected-error@+1 {{'fir.coordinate_of' op cannot apply to character singleton}}
298 %2 = fir.coordinate_of %arr, %1, %1 : (!fir.ref<!fir.char<10, 2>>, i32, i32) -> !fir.ref<!fir.char<10>>
299 return
300 }
301
302 // -----
303
304 %0 = arith.constant 22 : i32
305 // expected-error@+1 {{'fir.embox' op operand #0 must be any reference, but got 'i32'}}
306 %1 = fir.embox %0 : (i32) -> !fir.box<i32>
307
308 // -----
309
310 func.func @fun(%0 : !fir.ref<i32>) {
311 %c_100 = arith.constant 100 : index
312 %1 = fir.shape %c_100 : (index) -> !fir.shape<1>
313 // expected-error@+1 {{'fir.embox' op shape must not be provided for a scalar}}
314 %2 = fir.embox %0(%1) : (!fir.ref<i32>, !fir.shape<1>) -> !fir.box<i32>
315 }
316
317 // -----
318
319 func.func @fun(%0 : !fir.ref<i32>) {
320 %c_100 = arith.constant 100 : index
321 %1 = fir.slice %c_100, %c_100, %c_100 : (index, index, index) -> !fir.slice<1>
322 // expected-error@+1 {{'fir.embox' op operand #1 must be any legal shape type, but got '!fir.slice<1>'}}
323 %2 = fir.embox %0(%1) : (!fir.ref<i32>, !fir.slice<1>) -> !fir.box<i32>
324 }
325
326 // -----
327
328 func.func @fun(%0 : !fir.ref<i32>) {
329 %c_100 = arith.constant 100 : index
330 %1 = fir.shape %c_100 : (index) -> !fir.shape<1>
331 // expected-error@+1 {{'fir.embox' op operand #1 must be FIR slice, but got '!fir.shape<1>'}}
332 %2 = fir.embox %0[%1] : (!fir.ref<i32>, !fir.shape<1>) -> !fir.box<i32>
333 }
334
335 // -----
336
337 func.func @fun(%0 : !fir.ref<i32>) {
338 %c_100 = arith.constant 100 : index
339 %1 = fir.slice %c_100, %c_100, %c_100 : (index, index, index) -> !fir.slice<1>
340 // expected-error@+1 {{'fir.embox' op slice must not be provided for a scalar}}
341 %2 = fir.embox %0[%1] : (!fir.ref<i32>, !fir.slice<1>) -> !fir.box<i32>
342 }
343
344 // -----
345
346 func.func @embox_tdesc(%arg0: !fir.class<!fir.array<10x!fir.type<derived{a:i32,b:i32}>>>) {
347 %0 = fir.alloca i32
348 %c1_i32 = arith.constant 1 : i32
349 %1 = fir.convert %c1_i32 : (i32) -> index
350 %c10_i32 = arith.constant 10 : i32
351 %2 = fir.convert %c10_i32 : (i32) -> index
352 %c1 = arith.constant 1 : index
353 %3 = fir.convert %1 : (index) -> i32
354 %4:2 = fir.do_loop %arg2 = %1 to %2 step %c1 iter_args(%arg3 = %3) -> (index, i32) {
355 fir.store %arg3 to %0 : !fir.ref<i32>
356 %9 = fir.load %0 : !fir.ref<i32>
357 %10 = fir.convert %9 : (i32) -> i64
358 %c1_i64 = arith.constant 1 : i64
359 %11 = arith.subi %10, %c1_i64 : i64
360 %12 = fir.coordinate_of %arg0, %11 : (!fir.class<!fir.array<10x!fir.type<derived{a:i32,b:i32}>>>, i64) -> !fir.ref<!fir.type<derived{a:i32,b:i32}>>
361 // expected-error@+1 {{'fir.embox' op source_box must be used with fir.class result type}}
362 %13 = fir.embox %12 source_box %arg0 : (!fir.ref<!fir.type<derived{a:i32,b:i32}>>, !fir.class<!fir.array<10x!fir.type<derived{a:i32,b:i32}>>>) -> !fir.box<!fir.type<derived{a:i32,b:i32}>>
363 %14 = arith.addi %arg2, %c1 : index
364 %15 = fir.convert %c1 : (index) -> i32
365 %16 = fir.load %0 : !fir.ref<i32>
366 %17 = arith.addi %16, %15 : i32
367 fir.result %14, %17 : index, i32
368 }
369 fir.store %4#1 to %0 : !fir.ref<i32>
370 return
371 }
372
373 // -----
374
375 %lo = arith.constant 1 : index
376 %c1 = arith.constant 1 : index
377 %up = arith.constant 10 : index
378 %okIn = arith.constant 1 : i1
379 %shIn = arith.constant 1 : i16
380 // expected-error@+1 {{'fir.iterate_while' op expected body first argument to be an index argument for the induction variable}}
381 %v:3 = fir.iterate_while (%i = %lo to %up step %c1) and (%ok = %okIn) iter_args(%sh = %shIn) -> (i16, i1, i16) {
382 %shNew = fir.call @bar(%sh) : (i16) -> i16
383 %okNew = fir.call @foo(%sh) : (i16) -> i1
384 fir.result %shNew, %okNew, %shNew : i16, i1, i16
385 }
386
387 // -----
388
389 %lo = arith.constant 1 : index
390 %c1 = arith.constant 1 : index
391 %up = arith.constant 10 : index
392 %okIn = arith.constant 1 : i1
393 %shIn = arith.constant 1 : i16
394 // expected-error@+1 {{'fir.iterate_while' op expected body second argument to be an index argument for the induction variable}}
395 %v:3 = fir.iterate_while (%i = %lo to %up step %c1) and (%ok = %okIn) iter_args(%sh = %shIn) -> (index, f32, i16) {
396 %shNew = fir.call @bar(%sh) : (i16) -> i16
397 %dummy = fir.call @foo(%sh) : (i16) -> f32
398 fir.result %i, %dummy, %shNew : index, f32, i16
399 }
400
401 // -----
402
403 %c1 = arith.constant 1 : index
404 %c10 = arith.constant 10 : index
405 // expected-error@+1 {{'fir.do_loop' op unordered loop has no final value}}
406 fir.do_loop %i = %c1 to %c10 step %c1 unordered -> index {
407 }
408
409 // -----
410
411 %c1 = arith.constant 1 : index
412 %c10 = arith.constant 10 : index
413 fir.do_loop %i = %c1 to %c10 step %c1 -> index {
414 %f1 = arith.constant 1.0 : f32
415 // expected-error@+1 {{'fir.result' op types mismatch between result op and its parent}}
416 fir.result %f1 : f32
417 }
418
419 // -----
420
421 %c1 = arith.constant 1 : index
422 %c10 = arith.constant 10 : index
423 // expected-error@+1 {{'fir.result' op parent of result must have same arity}}
424 fir.do_loop %i = %c1 to %c10 step %c1 -> index {
425 }
426
427 // -----
428
429 func.func @ugly_char_convert() {
430 %1 = fir.undefined i32
431 %2 = fir.undefined !fir.ref<!fir.char<1>>
432 %3 = fir.undefined !fir.ref<!fir.array<?x!fir.char<1>>>
433 // expected-error@+1 {{'fir.char_convert' op buffers must have different KIND values}}
434 fir.char_convert %2 for %1 to %3 : !fir.ref<!fir.char<1>>, i32, !fir.ref<!fir.array<?x!fir.char<1>>>
435 return
436 }
437
438 // -----
439
440 func.func @ugly_char_convert() {
441 %1 = fir.undefined i32
442 %2 = fir.undefined !fir.ref<!fir.char<1>>
443 %3 = fir.undefined !fir.ref<!fir.array<?xf32>>
444 // expected-error@+1 {{'fir.char_convert' op not a reference to a character}}
445 fir.char_convert %2 for %1 to %3 : !fir.ref<!fir.char<1>>, i32, !fir.ref<!fir.array<?xf32>>
446 return
447 }
448
449 // -----
450
451 func.func @ugly_char_convert() {
452 %1 = fir.undefined i32
453 %2 = fir.undefined !fir.ref<!fir.char<1>>
454 %3 = fir.undefined !fir.ref<!fir.array<?x!fir.char<2,?>>>
455 // expected-error@+1 {{'fir.char_convert' op operand #0 must be any reference, but got 'i32'}}
456 fir.char_convert %1 for %1 to %3 : i32, i32, !fir.ref<!fir.array<?x!fir.char<2,?>>>
457 return
458 }
459
460 // -----
461
462 func.func @ugly_char_convert() {
463 %1 = fir.undefined i32
464 %2 = fir.undefined !fir.ref<!fir.char<1>>
465 %3 = fir.undefined !fir.ref<!fir.array<?x!fir.char<2,?>>>
466 // expected-error@+1 {{'fir.char_convert' op operand #1 must be any integer, but got '!fir.ref<!fir.char<1>>'}}
467 fir.char_convert %2 for %2 to %3 : !fir.ref<!fir.char<1>>, !fir.ref<!fir.char<1>>, !fir.ref<!fir.array<?x!fir.char<2,?>>>
468 return
469 }
470
471 // -----
472
473 fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
474 %c0_i32 = arith.constant 1 : i32
475 %0 = fir.undefined !fir.array<32x32xi32>
476 // expected-error@+1 {{'fir.insert_on_range' op has uneven number of values in ranges}}
477 %2 = "fir.insert_on_range"(%0, %c0_i32) { coor = dense<[0, 31, 0]> : tensor<3xindex> } : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
478 fir.has_value %2 : !fir.array<32x32xi32>
479 }
480
481 // -----
482
483 fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
484 %c0_i32 = arith.constant 1 : i32
485 %0 = fir.undefined !fir.array<32x32xi32>
486 // expected-error@+1 {{'fir.insert_on_range' op has uneven number of values in ranges}}
487 %2 = "fir.insert_on_range"(%0, %c0_i32) { coor = dense<[0]> : tensor<1xindex> } : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
488 fir.has_value %2 : !fir.array<32x32xi32>
489 }
490
491 // -----
492
493 fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
494 %c0_i32 = arith.constant 1 : i32
495 %0 = fir.undefined !fir.array<32x32xi32>
496 // expected-error@+1 {{'fir.insert_on_range' op negative range bound}}
497 %2 = fir.insert_on_range %0, %c0_i32 from (-1) to (0) : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
498 fir.has_value %2 : !fir.array<32x32xi32>
499 }
500
501 // -----
502
503 fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
504 %c0_i32 = arith.constant 1 : i32
505 %0 = fir.undefined !fir.array<32x32xi32>
506 // expected-error@+1 {{'fir.insert_on_range' op empty range}}
507 %2 = fir.insert_on_range %0, %c0_i32 from (10) to (9) : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
508 fir.has_value %2 : !fir.array<32x32xi32>
509 }
510
511 // -----
512
513 fir.global internal @_QEmultiarray : !fir.array<?xi32> {
514 %c0_i32 = arith.constant 1 : i32
515 %0 = fir.undefined !fir.array<?xi32>
516 // expected-error@+1 {{'fir.insert_on_range' op must have constant shape and size}}
517 %2 = fir.insert_on_range %0, %c0_i32 from (0) to (10) : (!fir.array<?xi32>, i32) -> !fir.array<?xi32>
518 fir.has_value %2 : !fir.array<?xi32>
519 }
520
521 // -----
522
523 fir.global internal @_QEmultiarray : !fir.array<*:i32> {
524 %c0_i32 = arith.constant 1 : i32
525 %0 = fir.undefined !fir.array<*:i32>
526 // expected-error@+1 {{'fir.insert_on_range' op must have constant shape and size}}
527 %2 = fir.insert_on_range %0, %c0_i32 from (0) to (10) : (!fir.array<*:i32>, i32) -> !fir.array<*:i32>
528 fir.has_value %2 : !fir.array<*:i32>
529 }
530
531 // -----
532
533 func.func @bad_save_result(%buffer : !fir.ref<!fir.array<?xf64>>, %n :index) {
534 %res = fir.call @array_func() : () -> !fir.array<?xf32>
535 %shape = fir.shape %n : (index) -> !fir.shape<1>
536 // expected-error@+1 {{'fir.save_result' op value type must match memory reference type}}
537 fir.save_result %res to %buffer(%shape) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf64>>, !fir.shape<1>
538 return
539 }
540
541 // -----
542
543 func.func @bad_save_result(%buffer : !fir.ref<!fir.box<!fir.array<*:f32>>>) {
544 %res = fir.call @array_func() : () -> !fir.box<!fir.array<*:f32>>
545 // expected-error@+1 {{'fir.save_result' op cannot save !fir.box of unknown rank or type}}
546 fir.save_result %res to %buffer : !fir.box<!fir.array<*:f32>>, !fir.ref<!fir.box<!fir.array<*:f32>>>
547 return
548 }
549
550 // -----
551
552 func.func @bad_save_result(%buffer : !fir.ref<f64>) {
553 %res = fir.call @array_func() : () -> f64
554 // expected-error@+1 {{'fir.save_result' op operand #0 must be fir.box, fir.array or fir.type, but got 'f64'}}
555 fir.save_result %res to %buffer : f64, !fir.ref<f64>
556 return
557 }
558
559 // -----
560
561 func.func @bad_save_result(%buffer : !fir.ref<!fir.box<!fir.array<?xf32>>>, %n : index) {
562 %res = fir.call @array_func() : () -> !fir.box<!fir.array<?xf32>>
563 %shape = fir.shape %n : (index) -> !fir.shape<1>
564 // expected-error@+1 {{'fir.save_result' op must not have shape or length operands if the value is a fir.box}}
565 fir.save_result %res to %buffer(%shape) : !fir.box<!fir.array<?xf32>>, !fir.ref<!fir.box<!fir.array<?xf32>>>, !fir.shape<1>
566 return
567 }
568
569 // -----
570
571 func.func @bad_save_result(%buffer : !fir.ref<!fir.array<?xf32>>, %n :index) {
572 %res = fir.call @array_func() : () -> !fir.array<?xf32>
573 %shape = fir.shape %n, %n : (index, index) -> !fir.shape<2>
574 // expected-error@+1 {{'fir.save_result' op shape operand must be provided and have the value rank when the value is a fir.array}}
575 fir.save_result %res to %buffer(%shape) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<2>
576 return
577 }
578
579 // -----
580
581 func.func @bad_save_result(%buffer : !fir.ref<!fir.type<t{x:f32}>>, %n :index) {
582 %res = fir.call @array_func() : () -> !fir.type<t{x:f32}>
583 %shape = fir.shape %n : (index) -> !fir.shape<1>
584 // expected-error@+1 {{'fir.save_result' op shape operand should only be provided if the value is a fir.array}}
585 fir.save_result %res to %buffer(%shape) : !fir.type<t{x:f32}>, !fir.ref<!fir.type<t{x:f32}>>, !fir.shape<1>
586 return
587 }
588
589 // -----
590
591 func.func @bad_save_result(%buffer : !fir.ref<!fir.type<t{x:f32}>>, %n :index) {
592 %res = fir.call @array_func() : () -> !fir.type<t{x:f32}>
593 // expected-error@+1 {{'fir.save_result' op length parameters number must match with the value type length parameters}}
594 fir.save_result %res to %buffer typeparams %n : !fir.type<t{x:f32}>, !fir.ref<!fir.type<t{x:f32}>>, index
595 return
596 }
597
598 // -----
599
600 func.func @bad_save_result(%buffer : !fir.ref<!fir.array<?xf32>>, %n :index) {
601 %res = fir.call @array_func() : () -> !fir.array<?xf32>
602 %shape = fir.shape %n : (index) -> !fir.shape<1>
603 // expected-error@+1 {{'fir.save_result' op length parameters must not be provided for this value type}}
604 fir.save_result %res to %buffer(%shape) typeparams %n : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>, index
605 return
606 }
607
608 // -----
609
610 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
611 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
612 %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
613 // expected-error@+1 {{'fir.array_fetch' op number of indices != dimension of array}}
614 %f = fir.array_fetch %av1, %m : (!fir.array<?x?xf32>, index) -> f32
615 return
616 }
617
618 // -----
619
620 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
621 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
622 %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
623 // expected-error@+1 {{'fir.array_fetch' op return type does not match array}}
624 %f = fir.array_fetch %av1, %m, %n : (!fir.array<?x?xf32>, index, index) -> i32
625 return
626 }
627
628 // -----
629
630 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
631 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
632 %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
633 %f = fir.array_fetch %av1, %m, %n : (!fir.array<?x?xf32>, index, index) -> f32
634 // expected-error@+1 {{'fir.array_update' op number of indices != dimension of array}}
635 %av2 = fir.array_update %av1, %f, %m : (!fir.array<?x?xf32>, f32, index) -> !fir.array<?x?xf32>
636 return
637 }
638
639 // -----
640
641 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
642 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
643 %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
644 %c0 = arith.constant 0 : i32
645 // expected-error@+1 {{'fir.array_update' op merged value does not have element type}}
646 %av2 = fir.array_update %av1, %c0, %m, %n : (!fir.array<?x?xf32>, i32, index, index) -> !fir.array<?x?xf32>
647 return
648 }
649
650 // -----
651
652 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index, %f: !fir.ref<i32>) {
653 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
654 %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
655 // expected-error@+1 {{'fir.array_update' op does not support reference type for merge}}
656 %av2 = fir.array_update %av1, %f, %m, %n : (!fir.array<?x?xf32>, !fir.ref<i32>, index, index) -> !fir.array<?x?xf32>
657 return
658 }
659
660 // -----
661
662 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
663 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
664 %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
665 %f = fir.array_fetch %av1, %m, %n : (!fir.array<?x?xf32>, index, index) -> f32
666 %av2 = fir.array_update %av1, %f, %m, %n : (!fir.array<?x?xf32>, f32, index, index) -> !fir.array<?x?xf32>
667 // expected-error@+1 {{'fir.array_merge_store' op operand #0 must be result of a fir.array_load op}}
668 fir.array_merge_store %av2, %av2 to %arr1 : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
669 return
670 }
671
672 // -----
673
674 func.func @bad_array_modify(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index, %f : f32) {
675 %i10 = arith.constant 10 : index
676 %j20 = arith.constant 20 : index
677 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
678 %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
679 // expected-error@+1 {{'fir.array_modify' op number of indices must match array dimension}}
680 %addr, %av2 = fir.array_modify %av1, %i10 : (!fir.array<?x?xf32>, index) -> (!fir.ref<f32>, !fir.array<?x?xf32>)
681 fir.store %f to %addr : !fir.ref<f32>
682 fir.array_merge_store %av1, %av2 to %arr1 : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
683 return
684 }
685
686 // -----
687
688 func.func @slice_must_be_integral() {
689 %0 = arith.constant 42 : i32
690 %1 = fir.field_index field, !fir.type<t(param:i32){field:i32}> (%0 : i32)
691 // expected-error@+1 {{'fir.slice' op operand #0 must be variadic of any integer, but got '!fir.field'}}
692 %2 = fir.slice %1, %1, %1 : (!fir.field, !fir.field, !fir.field) -> !fir.slice<1>
693 return
694 }
695
696 // -----
697
698 func.func @array_coor_no_slice_substr(%a : !fir.ref<!fir.array<?x?xf32>>) {
699 %c1 = arith.constant 1 : index
700 %c10 = arith.constant 10 : index
701 %slice = fir.slice %c1, %c10, %c1 substr %c1, %c10 : (index, index, index, index, index) -> !fir.slice<1>
702 // expected-error@+1 {{'fir.array_coor' op array_coor cannot take a slice with substring}}
703 %p = fir.array_coor %a[%slice] %c1, %c1 : (!fir.ref<!fir.array<?x?xf32>>, !fir.slice<1>, index, index) -> !fir.ref<f32>
704 return
705 }
706
707 // -----
708
709 func.func @array_coor_no_slice_substr(%a : !fir.ref<!fir.array<?x?xf32>>) {
710 %c1 = arith.constant 1 : index
711 %c10 = arith.constant 10 : index
712 %slice = fir.slice %c1, %c10, %c1 substr %c1, %c10 : (index, index, index, index, index) -> !fir.slice<1>
713 // expected-error@+1 {{'fir.array_load' op array_load cannot take a slice with substring}}
714 %v = fir.array_load %a[%slice] : (!fir.ref<!fir.array<?x?xf32>>, !fir.slice<1>) -> !fir.array<?x?xf32>
715 return
716 }
717
718 // -----
719
720 func.func @array_merge_store_no_slice_substr(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index, %f : f32) {
721 %i10 = arith.constant 10 : index
722 %j20 = arith.constant 20 : index
723 %c1 = arith.constant 1 : index
724 %c10 = arith.constant 10 : index
725 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
726 %slice = fir.slice %c1, %c10, %c1 substr %c1, %c10 : (index, index, index, index, index) -> !fir.slice<1>
727 %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
728 %addr, %av2 = fir.array_modify %av1, %i10, %i10 : (!fir.array<?x?xf32>, index, index) -> (!fir.ref<f32>, !fir.array<?x?xf32>)
729 fir.store %f to %addr : !fir.ref<f32>
730 // expected-error@+1 {{'fir.array_merge_store' op array_merge_store cannot take a slice with substring}}
731 fir.array_merge_store %av1, %av2 to %arr1[%slice] : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>, !fir.slice<1>
732 return
733 }
734
735 // -----
736
737 func.func @array_access(%a : !fir.ref<!fir.array<?x?xf32>>) {
738 %c1 = arith.constant 1 : index
739 %n = arith.constant 0 : index
740 %m = arith.constant 50 : index
741 %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
742 %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
743 // expected-error@+1 {{'fir.array_access' op number of indices != dimension of array}}
744 %p = fir.array_access %v, %c1 : (!fir.array<?x?xf32>, index) -> !fir.ref<f32>
745 return
746 }
747
748 // -----
749
750 func.func @array_access(%a : !fir.ref<!fir.array<?x?xf32>>) {
751 %c1 = arith.constant 1 : index
752 %n = arith.constant 0 : index
753 %m = arith.constant 50 : index
754 %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
755 %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
756 // expected-error@+1 {{'fir.array_access' op return type does not match array}}
757 %p = fir.array_access %v, %c1, %c1 : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f64>
758 return
759 }
760
761 // -----
762
763 func.func @foo(%arg0: !fir.ref<!fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>>) {
764 %c1 = arith.constant 1 : index
765 %c0 = arith.constant 0 : index
766 %c9 = arith.constant 9 : index
767 %c19 = arith.constant 19 : index
768 %c30 = arith.constant 30 : index
769 %0 = fir.shape %c30 : (index) -> !fir.shape<1>
770 %1 = fir.array_load %arg0(%0) : (!fir.ref<!fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>>, !fir.shape<1>) -> !fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>
771 %2 = fir.do_loop %arg1 = %c1 to %c9 step %c1 unordered iter_args(%arg2 = %1) -> (!fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>) {
772 %3 = fir.field_index c, !fir.type<t{c:!fir.array<20xi32>}>
773 %4 = fir.do_loop %arg3 = %c0 to %c19 step %c1 unordered iter_args(%arg4 = %arg2) -> (!fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>) {
774 // expected-error@+1 {{'fir.array_access' op return type and/or indices do not type check}}
775 %5 = fir.array_access %1, %arg1, %3, %arg3 : (!fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>, index, !fir.field, index) -> !fir.ref<f32>
776 %6 = fir.call @ifoo(%5) : (!fir.ref<f32>) -> i32
777 %7 = fir.array_update %arg4, %6, %arg1, %3, %arg3 : (!fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>, i32, index, !fir.field, index) -> !fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>
778 fir.result %7 : !fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>
779 }
780 fir.result %4 : !fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>
781 }
782 fir.array_merge_store %1, %2 to %arg0 : !fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>, !fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>, !fir.ref<!fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>>
783 return
784 }
785 func.func private @ifoo(!fir.ref<f32>) -> i32
786
787 // -----
788
789 func.func private @dispatch(%arg0: !fir.class<!fir.type<derived{a:i32,b:i32}>>) -> () {
790 // expected-error@+1 {{'fir.dispatch' op pass_arg_pos must be smaller than the number of operands}}
791 fir.dispatch "proc1"(%arg0 : !fir.class<!fir.type<derived{a:i32,b:i32}>>) (%arg0 : !fir.class<!fir.type<derived{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32}
792 return
793 }
794
795 // -----
796
797 func.func private @dispatch(%arg0: !fir.class<!fir.type<derived{a:i32,b:i32}>>, %arg1: i32) -> () {
798 // expected-error@+1 {{'fir.dispatch' op pass_arg_pos must be a polymorphic operand}}
799 fir.dispatch "proc1"(%arg0 : !fir.class<!fir.type<derived{a:i32,b:i32}>>) (%arg0, %arg1 : !fir.class<!fir.type<derived{a:i32,b:i32}>>, i32) {pass_arg_pos = 1 : i32}
800 return
801 }
802
803 // -----
804 func.func @test_fortran_var_attrs() {
805 // expected-error@+1 {{Unknown fortran variable attribute: volatypo}}
806 %0 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<volatypo>}
807 }
808
809 // -----
810 func.func @bad_numeric_declare(%arg0: !fir.ref<f32>) {
811 %c1 = arith.constant 1 : index
812 // expected-error@+1 {{'fir.declare' op requires attribute 'uniq_name'}}
813 %0 = fir.declare %arg0 typeparams %c1 {uniq_typo = "x"} : (!fir.ref<f32>, index) -> !fir.ref<f32>
814 return
815 }
816
817 // -----
818 func.func @bad_numeric_declare(%arg0: !fir.ref<f32>) {
819 %c1 = arith.constant 1 : index
820 // expected-error@+1 {{'fir.declare' op of numeric, logical, or assumed type entity must not have length parameters}}
821 %0 = fir.declare %arg0 typeparams %c1 {uniq_name = "x"} : (!fir.ref<f32>, index) -> !fir.ref<f32>
822 return
823 }
824
825 // -----
826 func.func @bad_char_declare(%arg0: !fir.boxchar<1> ) {
827 %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
828 // expected-error@+1 {{'fir.declare' op must be provided exactly one type parameter when its base is a character that is not a box}}
829 %1 = fir.declare %0#0 {uniq_name = "c"} : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.char<1,?>>
830 return
831 }
832
833 // -----
834 func.func @bad_char_declare(%arg0: !fir.boxchar<1> ) {
835 %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
836 // expected-error@+1 {{'fir.declare' op of character entity must have at most one length parameter}}
837 %1 = fir.declare %0#0 typeparams %0#1, %0#1 {uniq_name = "c"} : (!fir.ref<!fir.char<1,?>>, index, index) -> !fir.ref<!fir.char<1,?>>
838 return
839 }
840
841 // -----
842 func.func @bad_derived_declare(%arg0: !fir.ref<!fir.type<t{field:i32}>>) {
843 %c1 = arith.constant 1 : index
844 // expected-error@+1 {{'fir.declare' op has too many length parameters}}
845 %0 = fir.declare %arg0 typeparams %c1 {uniq_name = "x"} : (!fir.ref<!fir.type<t{field:i32}>>, index) -> !fir.ref<!fir.type<t{field:i32}>>
846 return
847 }
848
849 // -----
850 func.func @bad_pdt_declare(%arg0: !fir.ref<!fir.type<pdt(param:i32){field:i32}>>) {
851 // expected-error@+1 {{'fir.declare' op must be provided all the derived type length parameters when the base is not a box}}
852 %0 = fir.declare %arg0 {uniq_name = "x"} : (!fir.ref<!fir.type<pdt(param:i32){field:i32}>>) -> !fir.ref<!fir.type<pdt(param:i32){field:i32}>>
853 return
854 }
855
856 // -----
857 func.func @bad_pdt_declare_2(%arg0: !fir.ref<!fir.type<pdt(param:i32){field:i32}>>) {
858 %c1 = arith.constant 1 : index
859 // expected-error@+1 {{'fir.declare' op has too many length parameters}}
860 %0 = fir.declare %arg0 typeparams %c1, %c1 {uniq_name = "x"} : (!fir.ref<!fir.type<pdt(param:i32){field:i32}>>, index, index) -> !fir.ref<!fir.type<pdt(param:i32){field:i32}>>
861 return
862 }
863
864
865 // -----
866 func.func @bad_array_declare(%arg0: !fir.ref<!fir.array<?x?xf32>>) {
867 // expected-error@+1 {{'fir.declare' op of array entity with a raw address base must have a shape operand that is a shape or shapeshift}}
868 %0 = fir.declare %arg0 {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>) -> !fir.ref<!fir.array<?x?xf32>>
869 return
870 }
871
872 // -----
873 func.func @bad_array_declare_2(%arg0: !fir.ref<!fir.array<?x?xf32>>) {
874 %c1 = arith.constant 1 : index
875 %c2 = arith.constant 2 : index
876 %shift = fir.shift %c1, %c2 : (index, index) -> !fir.shift<2>
877 // expected-error@+1 {{'fir.declare' op of array entity with a raw address base must have a shape operand that is a shape or shapeshift}}
878 %0 = fir.declare %arg0(%shift) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shift<2>) -> !fir.ref<!fir.array<?x?xf32>>
879 return
880 }
881
882 // -----
883 func.func @bad_array_declare_3(%arg0: !fir.ref<!fir.array<?x?xf32>>) {
884 %c1 = arith.constant 1 : index
885 %shape = fir.shape %c1 : (index) -> !fir.shape<1>
886 // expected-error@+1 {{'fir.declare' op has conflicting shape and base operand ranks}}
887 %0 = fir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<1>) -> !fir.ref<!fir.array<?x?xf32>>
888 return
889 }
890
891 // -----
892 func.func @bad_array_declare_4(%arg0: !fir.ref<!fir.array<?x?xf32>>) {
893 %c1 = arith.constant 1 : index
894 %shape = fir.shape_shift %c1, %c1 : (index, index) -> !fir.shapeshift<1>
895 // expected-error@+1 {{'fir.declare' op has conflicting shape and base operand ranks}}
896 %0 = fir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<1>) -> !fir.ref<!fir.array<?x?xf32>>
897 return
898 }
899
900 // -----
901 func.func @bad_array_declare_box(%arg0: !fir.box<!fir.array<?x?xf32>>) {
902 %c1 = arith.constant 1 : index
903 %shape = fir.shift %c1 : (index) -> !fir.shift<1>
904 // expected-error@+1 {{'fir.declare' op has conflicting shape and base operand ranks}}
905 %0 = fir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.box<!fir.array<?x?xf32>>, !fir.shift<1>) -> !fir.box<!fir.array<?x?xf32>>
906 return
907 }
908
909 // -----
910 func.func @bad_array_declare_char_boxaddr(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) {
911 %c1 = arith.constant 1 : index
912 %c2 = arith.constant 2 : index
913 %shape = fir.shift %c1, %c2 : (index, index) -> !fir.shift<2>
914 // expected-error@+1 {{'fir.declare' op for box address must not have a shape operand}}
915 %0 = fir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>, !fir.shift<2>) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>
916 return
917 }
918
919 // -----
920 func.func @bad_array_declare_unlimited_polymorphic_boxaddr(%arg0: !fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>) {
921 %c1 = arith.constant 1 : index
922 %c2 = arith.constant 2 : index
923 %shape = fir.shift %c1, %c2 : (index, index) -> !fir.shift<2>
924 // expected-error@+1 {{'fir.declare' op for box address must not have a shape operand}}
925 %0 = fir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>, !fir.shift<2>) -> !fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>
926 return
927 }
928
929 // -----
930
931 func.func @invalid_selector(%arg : !fir.box<!fir.ref<i32>>) -> i32 {
932 %0 = arith.constant 1 : i32
933 %2 = arith.constant 3 : i32
934 // expected-error@+1{{'fir.select_type' op selector must be polymorphic}}
935 fir.select_type %arg : !fir.box<!fir.ref<i32>> [
936 #fir.type_is<!fir.int<4>>,^bb1(%0:i32),
937 #fir.type_is<!fir.int<8>>,^bb2(%2:i32),
938 unit,^bb5 ]
939 ^bb1(%a : i32) :
940 return %a : i32
941 ^bb2(%b : i32) :
942 return %b : i32
943 ^bb5 :
944 %zero = arith.constant 0 : i32
945 return %zero : i32
946 }
947
948 // -----
949
950 func.func @logical_to_fp(%arg0: !fir.logical<4>) -> f32 {
951 // expected-error@+1{{'fir.convert' op invalid type conversion}}
952 %0 = fir.convert %arg0 : (!fir.logical<4>) -> f32
953 return %0 : f32
954 }
955
956 // -----
957
958 func.func @fp_to_logical(%arg0: f32) -> !fir.logical<4> {
959 // expected-error@+1{{'fir.convert' op invalid type conversion}}
960 %0 = fir.convert %arg0 : (f32) -> !fir.logical<4>
961 return %0 : !fir.logical<4>
962 }
963
964 // -----
965
966 func.func @rec_to_rec(%arg0: !fir.type<t1{i:i32, f:f32}>) -> !fir.type<t2{f:f32, i:i32}> {
967 // expected-error@+1{{'fir.convert' op invalid type conversion}}
968 %0 = fir.convert %arg0 : (!fir.type<t1{i:i32, f:f32}>) -> !fir.type<t2{f:f32, i:i32}>
969 return %0 : !fir.type<t2{f:f32, i:i32}>
970 }
971
972 // -----
973
974 func.func @bad_box_offset(%not_a_box : !fir.ref<i32>) {
975 // expected-error@+1{{'fir.box_offset' op box_ref operand must have !fir.ref<!fir.box<T>> or !fir.ref<!fir.boxchar<k>> type}}
976 %addr1 = fir.box_offset %not_a_box base_addr : (!fir.ref<i32>) -> !fir.llvm_ptr<!fir.ref<i32>>
977 return
978 }
979
980 // -----
981
982 func.func @bad_box_offset(%boxchar : !fir.ref<!fir.boxchar<1>>) {
983 // expected-error@+1{{'fir.box_offset' op cannot address derived_type field of a fir.boxchar}}
984 %addr1 = fir.box_offset %boxchar derived_type : (!fir.ref<!fir.boxchar<1>>) -> !fir.llvm_ptr<!fir.ref<!fir.char<1,?>>>
985 return
986 }
987
988 // -----
989
990 func.func @bad_box_offset(%no_addendum : !fir.ref<!fir.box<i32>>) {
991 // expected-error@+1{{'fir.box_offset' op can only address derived_type field of derived type or unlimited polymorphic fir.box}}
992 %addr1 = fir.box_offset %no_addendum derived_type : (!fir.ref<!fir.box<i32>>) -> !fir.llvm_ptr<!fir.tdesc<!fir.type<none>>>
993 return
994 }
995
996 // -----
997
998 func.func @bad_rebox_assumed_rank_1(%arg0: !fir.ref<!fir.array<*:f32>> ) {
999 // expected-error@+1{{'fir.rebox_assumed_rank' op input must be a box or box address}}
1000 %1 = fir.rebox_assumed_rank %arg0 lbs ones : (!fir.ref<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>>
1001 return
1002 }
1003
1004 // -----
1005
1006 func.func @bad_rebox_assumed_rank_2(%arg0: !fir.box<!fir.array<*:f32>> ) {
1007 // expected-error@+1{{'fir.rebox_assumed_rank' op result #0 must be box or class, but got '!fir.ref<!fir.box<!fir.array<*:f32>>>'}}
1008 %1 = fir.rebox_assumed_rank %arg0 lbs ones : (!fir.box<!fir.array<*:f32>>) -> !fir.ref<!fir.box<!fir.array<*:f32>>>
1009 return
1010 }
1011
1012 // -----
1013
1014 func.func @bad_rebox_assumed_rank_3(%arg0: !fir.box<!fir.array<*:f32>> ) {
1015 // expected-error@+1{{'fir.rebox_assumed_rank' op input and output element types are incompatible}}
1016 %1 = fir.rebox_assumed_rank %arg0 lbs ones : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:i32>>
1017 return
1018 }
1019
1020 // -----
1021
1022 func.func @bad_is_assumed_size(%arg0: !fir.ref<!fir.array<*:none>>) {
1023 // expected-error@+1{{op operand #0 must be box or class, but got '!fir.ref<!fir.array<*:none>>'}}
1024 %1 = fir.is_assumed_size %arg0 : (!fir.ref<!fir.array<*:none>>) -> i1
1025 return
1026 }
1027
1028 // -----
1029
1030 !t=!fir.type<sometype{i:i32}>
1031 !t2=!fir.type<sometype2{j:i32}>
1032 func.func @bad_copy_1(%arg0: !fir.ref<!t>, %arg1: !fir.ref<!t2>) {
1033 // expected-error@+1{{'fir.copy' op source and destination must have the same value type}}
1034 fir.copy %arg0 to %arg1 no_overlap : !fir.ref<!t>, !fir.ref<!t2>
1035 return
1036 }
1037
1038 // -----
1039
1040 !t=!fir.type<sometype{i:i32}>
1041 func.func @bad_copy_2(%arg0: !fir.ref<!t>, %arg1: !t) {
1042 // expected-error@+1{{'fir.copy' op operand #0 must be a reference type to a constant size fir.array, fir.char, or fir.type, but got '!fir.type<sometype{i:i32}>'}}
1043 fir.copy %arg1 to %arg0 no_overlap : !t, !fir.ref<!t>
1044 return
1045 }
1046
1047 // -----
1048
1049 !t=!fir.array<?xi32>
1050 func.func @bad_copy_3(%arg0: !fir.ref<!t>, %arg1: !fir.ref<!t>) {
1051 // expected-error@+1{{'fir.copy' op operand #0 must be a reference type to a constant size fir.array, fir.char, or fir.type, but got '!fir.ref<!fir.array<?xi32>>'}}
1052 fir.copy %arg0 to %arg1 no_overlap : !fir.ref<!t>, !fir.ref<!t>
1053 return
1054 }
1055
1056 // -----
1057
1058 !t=f32
1059 func.func @bad_copy_4(%arg0: !fir.ref<!t>, %arg1: !fir.ref<!t>) {
1060 // expected-error@+1{{'fir.copy' op operand #0 must be a reference type to a constant size fir.array, fir.char, or fir.type, but got '!fir.ref<f32>'}}
1061 fir.copy %arg0 to %arg1 no_overlap : !fir.ref<!t>, !fir.ref<!t>
1062 return
1063 }
1064
1065 // -----
1066
1067 func.func @bad_pack_array1(%arg0: !fir.ref<!fir.box<!fir.array<?xi32>>>) {
1068 // expected-error@+1{{op operand #0 must be any boxed array, but got '!fir.ref<!fir.box<!fir.array<?xi32>>>'}}
1069 %0 = fir.pack_array %arg0 stack whole : (!fir.ref<!fir.box<!fir.array<?xi32>>>) -> !fir.ref<!fir.box<!fir.array<?xi32>>>
1070 return
1071 }
1072
1073 // -----
1074
1075 func.func @bad_pack_array2(%arg0: !fir.box<!fir.array<?xi32>>) {
1076 // expected-error@+1{{op failed to verify that all of {array, result} have same type}}
1077 %0 = fir.pack_array %arg0 stack whole : (!fir.box<!fir.array<?xi32>>) -> !fir.box<!fir.array<?xi64>>
1078 return
1079 }
1080
1081 // -----
1082
1083 func.func @bad_pack_array3(%arg0: !fir.box<!fir.array<?x!fir.char<1,?>>>, %arg1: i32) {
1084 // expected-error@+1{{op invalid type parameters}}
1085 %0 = fir.pack_array %arg0 stack whole typeparams %arg1, %arg1 : (!fir.box<!fir.array<?x!fir.char<1,?>>>, i32, i32) -> !fir.box<!fir.array<?x!fir.char<1,?>>>
1086 return
1087 }
1088
1089 // -----
1090
1091 func.func @bad_pack_array4(%arg0: !fir.box<!fir.array<?xf32>>) {
1092 // expected-error@+1{{op attribute 'max_size' failed to satisfy constraint: 64-bit unsigned integer attribute}}
1093 %0 = fir.pack_array %arg0 stack whole constraints {max_size = -1 : i64} : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
1094 return
1095 }
1096
1097 // -----
1098
1099 func.func @bad_pack_array5(%arg0: !fir.box<!fir.array<?xf32>>) {
1100 // expected-error@+1{{op attribute 'max_element_size' failed to satisfy constraint: 64-bit unsigned integer attribute}}
1101 %0 = fir.pack_array %arg0 stack whole constraints {max_element_size = -1 : i64} : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
1102 return
1103 }
1104
1105 // -----
1106
1107 func.func @bad_pack_array6(%arg0: !fir.box<!fir.array<?xf32>>) {
1108 // expected-error@+1{{op attribute 'min_stride' failed to satisfy constraint: 64-bit unsigned integer attribute}}
1109 %0 = fir.pack_array %arg0 stack whole constraints {min_stride = -1 : i64} : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
1110 return
1111 }
1112
1113 // -----
1114
1115 func.func @bad_pack_array7(%arg0: !fir.box<!fir.array<?xf32>>) {
1116 // expected-error@+1{{op 'innermost' is invalid for 1D arrays, use 'whole' instead}}
1117 %0 = fir.pack_array %arg0 stack innermost : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
1118 return
1119 }
1120
1121 // -----
1122
1123 func.func @bad_unpack_array1(%arg0: !fir.ref<!fir.box<!fir.array<?xi32>>>, %arg1: !fir.ref<!fir.box<!fir.array<?xi32>>>) {
1124 // expected-error@+1{{op operand #0 must be any boxed array, but got '!fir.ref<!fir.box<!fir.array<?xi32>>>'}}
1125 fir.unpack_array %arg0 to %arg1 stack : !fir.ref<!fir.box<!fir.array<?xi32>>>
1126 return
1127 }
1128
1129 // -----
1130
1131 func.func @bad_unpack_array2(%arg0: !fir.box<!fir.array<?xf32>>) {
1132 %0 = fir.pack_array %arg0 stack whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
1133 // expected-error@+1{{op the pack operation uses different memory for the temporary (stack vs heap)}}
1134 fir.unpack_array %0 to %arg0 heap no_copy : !fir.box<!fir.array<?xf32>>
1135 return
1136 }
1137
1138 // -----
1139
1140 func.func @bad_unpack_array3(%arg0: !fir.box<!fir.array<?xf32>>) {
1141 %0 = fir.pack_array %arg0 heap whole no_copy: (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
1142 // expected-error@+1{{op the pack operation uses different memory for the temporary (stack vs heap)}}
1143 fir.unpack_array %0 to %arg0 stack : !fir.box<!fir.array<?xf32>>
1144 return
1145 }
1146
1147 // -----
1148
1149 func.func @bad_unpack_array4(%arg0: !fir.box<!fir.array<?xf32>>, %arg1: !fir.box<!fir.array<?xi32>>) {
1150 // expected-note@-1 {{prior use here}}
1151 // expected-error@+1{{use of value '%arg0' expects different type than prior uses: '!fir.box<!fir.array<?xi32>>' vs '!fir.box<!fir.array<?xf32>>'}}
1152 fir.unpack_array %arg0 to %arg1 stack : !fir.box<!fir.array<?xi32>>
1153 return
1154 }
1155
1156 // -----
1157
1158 func.func @bad_is_contiguous_box(%arg0: !fir.ref<!fir.box<!fir.array<?xi32>>>) -> i1 {
1159 // expected-error@+1{{op operand #0 must be any box, but got '!fir.ref<!fir.box<!fir.array<?xi32>>>'}}
1160 %0 = fir.is_contiguous_box %arg0 whole : (!fir.ref<!fir.box<!fir.array<?xi32>>>) -> i1
1161 return %0 : i1
1162 }
1163
1164 // -----
1165
1166 func.func @bad_box_total_elements(%arg0: !fir.ref<!fir.box<!fir.array<?xi32>>>) -> i32 {
1167 // expected-error@+1{{op operand #0 must be any box, but got '!fir.ref<!fir.box<!fir.array<?xi32>>>'}}
1168 %0 = fir.box_total_elements %arg0 : (!fir.ref<!fir.box<!fir.array<?xi32>>>) -> i32
1169 return %0 : i32
1170 }
1171
1172 // -----
1173
1174 func.func @empty_dc_wrapper_body() {
1175 // expected-error@+1 {{'fir.do_concurrent' op expects a non-empty block}}
1176 fir.do_concurrent {
1177 }
1178 return
1179 }
1180
1181 // -----
1182
1183 func.func @dc_wrong_terminator() {
1184 // expected-error@+1 {{'fir.do_concurrent' op must be terminated by 'fir.do_concurrent.loop'}}
1185 fir.do_concurrent {
1186 llvm.return
1187 }
1188 return
1189 }
1190
1191 // -----
1192
1193 func.func @dc_0d() {
1194 // expected-error@+2 {{'fir.do_concurrent.loop' op needs at least one tuple element for lowerBound, upperBound and step}}
1195 fir.do_concurrent {
1196 fir.do_concurrent.loop () = () to () step () {
1197 %tmp = fir.alloca i32
1198 }
1199 }
1200 return
1201 }
1202
1203 // -----
1204
1205 func.func @dc_invalid_parent(%arg0: index, %arg1: index) {
1206 // expected-error@+1 {{'fir.do_concurrent.loop' op expects parent op 'fir.do_concurrent'}}
1207 "fir.do_concurrent.loop"(%arg0, %arg1) <{operandSegmentSizes = array<i32: 1, 1, 0, 0, 0>}> ({
1208 ^bb0(%arg2: index):
1209 %tmp = "fir.alloca"() <{in_type = i32, operandSegmentSizes = array<i32: 0, 0>}> : () -> !fir.ref<i32>
1210 }) : (index, index) -> ()
1211 return
1212 }
1213
1214 // -----
1215
1216 func.func @dc_invalid_control(%arg0: index, %arg1: index) {
1217 // expected-error@+2 {{'fir.do_concurrent.loop' op different number of tuple elements for lowerBound, upperBound or step}}
1218 fir.do_concurrent {
1219 "fir.do_concurrent.loop"(%arg0, %arg1) <{operandSegmentSizes = array<i32: 1, 1, 0, 0, 0>}> ({
1220 ^bb0(%arg2: index):
1221 %tmp = "fir.alloca"() <{in_type = i32, operandSegmentSizes = array<i32: 0, 0>}> : () -> !fir.ref<i32>
1222 }) : (index, index) -> ()
1223 }
1224 return
1225 }
1226
1227 // -----
1228
1229 func.func @dc_invalid_ind_var(%arg0: index, %arg1: index) {
1230 // expected-error@+2 {{'fir.do_concurrent.loop' op expects the same number of induction variables: 2 as bound and step values: 1}}
1231 fir.do_concurrent {
1232 "fir.do_concurrent.loop"(%arg0, %arg1, %arg0) <{operandSegmentSizes = array<i32: 1, 1, 1, 0, 0>}> ({
1233 ^bb0(%arg3: index, %arg4: index):
1234 %tmp = "fir.alloca"() <{in_type = i32, operandSegmentSizes = array<i32: 0, 0>}> : () -> !fir.ref<i32>
1235 }) : (index, index, index) -> ()
1236 }
1237 return
1238 }
1239
1240 // -----
1241
1242 func.func @dc_invalid_ind_var_type(%arg0: index, %arg1: index) {
1243 // expected-error@+2 {{'fir.do_concurrent.loop' op expects arguments for the induction variable to be of index type}}
1244 fir.do_concurrent {
1245 "fir.do_concurrent.loop"(%arg0, %arg1, %arg0) <{operandSegmentSizes = array<i32: 1, 1, 1, 0, 0>}> ({
1246 ^bb0(%arg3: i32):
1247 %tmp = "fir.alloca"() <{in_type = i32, operandSegmentSizes = array<i32: 0, 0>}> : () -> !fir.ref<i32>
1248 }) : (index, index, index) -> ()
1249 }
1250 return
1251 }
1252
1253 // -----
1254
1255 func.func @dc_invalid_reduction(%arg0: index, %arg1: index) {
1256 %sum = fir.alloca i32
1257 // expected-error@+2 {{'fir.do_concurrent.loop' op mismatch in number of reduction variables and reduction attributes}}
1258 fir.do_concurrent {
1259 "fir.do_concurrent.loop"(%arg0, %arg1, %arg0, %sum) <{operandSegmentSizes = array<i32: 1, 1, 1, 0, 1>}> ({
1260 ^bb0(%arg3: index, %sum_arg: i32):
1261 %tmp = "fir.alloca"() <{in_type = i32, operandSegmentSizes = array<i32: 0, 0>}> : () -> !fir.ref<i32>
1262 }) : (index, index, index, !fir.ref<i32>) -> ()
1263 }
1264 return
1265 }
1266
1267 // -----
1268
1269 func.func @dc_reduce_no_attr() {
1270 %3 = fir.alloca i32 {bindc_name = "s", uniq_name = "dc_reduce"}
1271 %4:2 = hlfir.declare %3 {uniq_name = "dc_reduce"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
1272 %c1 = arith.constant 1 : index
1273 // expected-error@+2 {{expected attribute value}}
1274 fir.do_concurrent {
1275 fir.do_concurrent.loop (%arg0) = (%c1) to (%c1) step (%c1) reduce(@add_reduction_i32 %4#0 -> %arg1 : !fir.ref<i32>) {
1276 }
1277 }
1278 return
1279 }
1280
1281 // -----
1282
1283 // Should fail when volatility changes from a fir.convert
1284 func.func @bad_convert_volatile(%arg0: !fir.ref<i32>) -> !fir.ref<i32, volatile> {
1285 // expected-error@+1 {{op this conversion does not preserve volatility}}
1286 %0 = fir.convert %arg0 : (!fir.ref<i32>) -> !fir.ref<i32, volatile>
1287 return %0 : !fir.ref<i32, volatile>
1288 }
1289
1290 // -----
1291
1292 // Should fail when volatility changes from a fir.convert
1293 func.func @bad_convert_volatile2(%arg0: !fir.ref<i32, volatile>) -> !fir.ref<i32> {
1294 // expected-error@+1 {{op this conversion does not preserve volatility}}
1295 %0 = fir.convert %arg0 : (!fir.ref<i32, volatile>) -> !fir.ref<i32>
1296 return %0 : !fir.ref<i32>
1297 }
1298
1299 // -----
1300
1301 // Should fail when the element type and the containing type change
1302 func.func @bad_convert_volatile3(%arg0: !fir.ref<i32>) -> !fir.box<i64> {
1303 // expected-error@+1 {{'fir.volatile_cast' op types must be identical except for volatility}}
1304 %0 = fir.volatile_cast %arg0 : (!fir.ref<i32>) -> !fir.box<i64>
1305 return %0 : !fir.box<i64>
1306 }
1307
1308 // -----
1309
1310 // Should fail when the containing type changes
1311 func.func @bad_convert_volatile4(%arg0: !fir.ref<i32>) -> !fir.box<i32> {
1312 // expected-error@+1 {{'fir.volatile_cast' op types must be identical except for volatility}}
1313 %0 = fir.volatile_cast %arg0 : (!fir.ref<i32>) -> !fir.box<i32>
1314 return %0 : !fir.box<i32>
1315 }
1316
1317 // -----
1318
1319 // Should fail when the containing type changes
1320 func.func @bad_convert_volatile5(%arg0: !fir.ref<i32>) -> !fir.box<i32, volatile> {
1321 // expected-error@+1 {{'fir.volatile_cast' op types must be identical except for volatility}}
1322 %0 = fir.volatile_cast %arg0 : (!fir.ref<i32>) -> !fir.box<i32, volatile>
1323 return %0 : !fir.box<i32, volatile>
1324 }
1325
1326 // -----
1327
1328 // Should fail when the element type changes
1329 func.func @bad_convert_volatile6(%arg0: !fir.ref<i32>) -> !fir.ref<i64> {
1330 // expected-error@+1 {{'fir.volatile_cast' op types must be identical except for volatility}}
1331 %0 = fir.volatile_cast %arg0 : (!fir.ref<i32>) -> !fir.ref<i64>
1332 return %0 : !fir.ref<i64>
1333 }
1334
1335 // -----
1336
1337 fir.local {type = local} @x.localizer : i32 init {
1338 ^bb0(%arg0: i32, %arg1: i32):
1339 %0 = arith.constant 0.0 : f32
1340 // expected-error @below {{Invalid yielded value. Expected type: 'i32', got: 'f32'}}
1341 fir.yield(%0 : f32)
1342 }
1343
1344 // -----
1345
1346 // expected-error @below {{Region argument type mismatch: got 'f32' expected 'i32'.}}
1347 fir.local {type = local} @x.localizer : i32 init {
1348 ^bb0(%arg0: i32, %arg1: f32):
1349 fir.yield
1350 }
1351
1352 // -----
1353
1354 fir.local {type = local} @x.localizer : f32 init {
1355 ^bb0(%arg0: f32, %arg1: f32):
1356 fir.yield(%arg0: f32)
1357 } dealloc {
1358 ^bb0(%arg0: f32):
1359 // expected-error @below {{Did not expect any values to be yielded.}}
1360 fir.yield(%arg0 : f32)
1361 }
1362
1363 // -----
1364
1365 fir.local {type = local} @x.localizer : i32 init {
1366 ^bb0(%arg0: i32, %arg1: i32):
1367 // expected-error @below {{expected exit block terminator to be an `fir.yield` op.}}
1368 fir.unreachable
1369 }
1370
1371 // -----
1372
1373 // expected-error @below {{`init`: expected 2 region arguments, got: 1}}
1374 fir.local {type = local} @x.localizer : f32 init {
1375 ^bb0(%arg0: f32):
1376 fir.yield(%arg0 : f32)
1377 }
1378
1379 // -----
1380
1381 // expected-error @below {{`copy`: expected 2 region arguments, got: 1}}
1382 fir.local {type = local_init} @x.privatizer : f32 copy {
1383 ^bb0(%arg0: f32):
1384 fir.yield(%arg0 : f32)
1385 }
1386
1387 // -----
1388
1389 // expected-error @below {{`dealloc`: expected 1 region arguments, got: 2}}
1390 fir.local {type = local} @x.localizer : f32 dealloc {
1391 ^bb0(%arg0: f32, %arg1: f32):
1392 fir.yield
1393 }
1394
1395 // -----
1396
1397 // expected-error @below {{`local` specifiers do not require a `copy` region.}}
1398 fir.local {type = local} @x.localizer : f32 copy {
1399 ^bb0(%arg0: f32, %arg1 : f32):
1400 fir.yield(%arg0 : f32)
1401 }
1402
1403 // -----
1404
1405 // expected-error @below {{`local_init` specifiers require at least a `copy` region.}}
1406 fir.local {type = local_init} @x.localizer : f32 init {
1407 ^bb0(%arg0: f32, %arg1: f32):
1408 fir.yield(%arg0 : f32)
1409 }
1410
1411 // -----
1412
1413 func.func @wrong_weights_number_in_if_then(%cond: i1) {
1414 // expected-error @below {{expects number of region weights to match number of regions: 1 vs 2}}
1415 fir.if %cond weights([50]) {
1416 }
1417 return
1418 }
1419
1420 // -----
1421
1422 func.func @wrong_weights_number_in_if_then_else(%cond: i1) {
1423 // expected-error @below {{expects number of region weights to match number of regions: 3 vs 2}}
1424 fir.if %cond weights([50, 40, 10]) {
1425 } else {
1426 }
1427 return
1428 }