1// FIR ops diagnotic tests
2
3// RUN: fir-opt -split-input-file -verify-diagnostics %s
4
5// expected-error@+1{{custom op 'fir.string_lit' must have character type}}
6%0 = fir.string_lit "Hello, World!"(13) : !fir.int<32>
7
8// -----
9
10// expected-error@+1{{custom op 'fir.string_lit' found an invalid constant}}
11%0 = fir.string_lit 20(13) : !fir.int<32>
12
13// -----
14
15// expected-error@+1{{'fir.string_lit' op values in list must be integers}}
16%2 = fir.string_lit [158, 2.0](2) : !fir.char<2>
17
18// -----
19
20func.func @bad_rebox_1(%arg0: !fir.ref<!fir.array<?x?xf32>>) {
21  %c10 = arith.constant 10 : index
22  %0 = fir.shape %c10 : (index) -> !fir.shape<1>
23  // expected-error@+1{{op operand #0 must be The type of a Fortran descriptor, but got '!fir.ref<!fir.array<?x?xf32>>'}}
24  %1 = fir.rebox %arg0(%0) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
25  return
26}
27
28// -----
29
30func.func @bad_rebox_2(%arg0: !fir.box<!fir.array<?x?xf32>>) {
31  %c10 = arith.constant 10 : index
32  %0 = fir.shape %c10 : (index) -> !fir.shape<1>
33  // expected-error@+1{{op result #0 must be The type of a Fortran descriptor, but got '!fir.ref<!fir.array<?xf32>>'}}
34  %1 = fir.rebox %arg0(%0) : (!fir.box<!fir.array<?x?xf32>>, !fir.shape<1>) -> !fir.ref<!fir.array<?xf32>>
35  return
36}
37
38// -----
39
40func.func @bad_rebox_3(%arg0: !fir.box<!fir.array<*:f32>>) {
41  %c10 = arith.constant 10 : index
42  %0 = fir.shape %c10 : (index) -> !fir.shape<1>
43  // expected-error@+1{{op box operand must not have unknown rank or type}}
44  %1 = fir.rebox %arg0(%0) : (!fir.box<!fir.array<*:f32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
45  return
46}
47
48// -----
49
50func.func @bad_rebox_4(%arg0: !fir.box<!fir.array<?xf32>>) {
51  // expected-error@+1{{op result type must not have unknown rank or type}}
52  %0 = fir.rebox %arg0 : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<*:f32>>
53  return
54}
55
56// -----
57
58func.func @bad_rebox_5(%arg0: !fir.box<!fir.array<?x?xf32>>) {
59  %c1 = arith.constant 1 : index
60  %c10 = arith.constant 10 : index
61  %0 = fir.slice %c1, %c10, %c1 : (index, index, index) -> !fir.slice<1>
62  // expected-error@+1{{op slice operand rank must match box operand rank}}
63  %1 = fir.rebox %arg0 [%0] : (!fir.box<!fir.array<?x?xf32>>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
64  return
65}
66
67// -----
68
69func.func @bad_rebox_6(%arg0: !fir.box<!fir.array<?xf32>>) {
70  %c1 = arith.constant 1 : index
71  %c10 = arith.constant 10 : index
72  %0 = fir.slice %c1, %c10, %c1 : (index, index, index) -> !fir.slice<1>
73  %1 = fir.shift %c1, %c1 : (index, index) -> !fir.shift<2>
74  // expected-error@+1{{shape operand and input box ranks must match when there is a slice}}
75  %2 = fir.rebox %arg0(%1) [%0] : (!fir.box<!fir.array<?xf32>>, !fir.shift<2>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
76  return
77}
78
79// -----
80
81func.func @bad_rebox_7(%arg0: !fir.box<!fir.array<?xf32>>) {
82  %c1 = arith.constant 1 : index
83  %c10 = arith.constant 10 : index
84  %0 = fir.slice %c1, %c10, %c1 : (index, index, index) -> !fir.slice<1>
85  %1 = fir.shape %c10 : (index) -> !fir.shape<1>
86  // expected-error@+1{{shape operand must absent or be a fir.shift when there is a slice}}
87  %2 = fir.rebox %arg0(%1) [%0] : (!fir.box<!fir.array<?xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
88  return
89}
90
91// -----
92
93func.func @bad_rebox_8(%arg0: !fir.box<!fir.array<?x?xf32>>) {
94  %c1 = arith.constant 1 : index
95  %c10 = arith.constant 10 : index
96  %undef = fir.undefined index
97  %0 = fir.slice %c1, %undef, %undef, %c1, %c10, %c1 : (index, index, index, index, index, index) -> !fir.slice<2>
98  // expected-error@+1{{result type rank and rank after applying slice operand must match}}
99  %1 = fir.rebox %arg0 [%0] : (!fir.box<!fir.array<?x?xf32>>, !fir.slice<2>) -> !fir.box<!fir.array<?x?xf32>>
100  return
101}
102
103// -----
104
105func.func @bad_rebox_9(%arg0: !fir.box<!fir.array<?xf32>>) {
106  %c10 = arith.constant 10 : index
107  %0 = fir.shift %c10, %c10 : (index, index) -> !fir.shift<2>
108  // expected-error@+1{{shape operand and input box ranks must match when the shape is a fir.shift}}
109  %1 = fir.rebox %arg0(%0) : (!fir.box<!fir.array<?xf32>>, !fir.shift<2>) -> !fir.box<!fir.array<?x?xf32>>
110  return
111}
112
113// -----
114
115func.func @bad_rebox_10(%arg0: !fir.box<!fir.array<?xf32>>) {
116  %c10 = arith.constant 10 : index
117  %0 = fir.shape %c10, %c10 : (index, index) -> !fir.shape<2>
118  // expected-error@+1{{result type and shape operand ranks must match}}
119  %1 = fir.rebox %arg0(%0) : (!fir.box<!fir.array<?xf32>>, !fir.shape<2>) -> !fir.box<!fir.array<?xf32>>
120  return
121}
122
123// -----
124
125func.func @bad_rebox_11(%arg0: !fir.box<!fir.array<?x?xf32>>) {
126  %c42 = arith.constant 42 : index
127  %0 = fir.shape %c42 : (index) -> !fir.shape<1>
128  // expected-error@+1{{op input and output element types must match for intrinsic types}}
129  %1 = fir.rebox %arg0(%0) : (!fir.box<!fir.array<?x?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf64>>
130  return
131}
132
133// -----
134
135func.func @test_rebox_char(%arg0: !fir.box<!fir.array<?x!fir.char<1,20>>>) {
136  %c10 = arith.constant 10 : index
137  %1 = fir.shape %c10, %c10 : (index, index) -> !fir.shape<2>
138  // expected-error@+1{{op input and output element types must match for intrinsic types}}
139  %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>>>
140  return
141}
142
143// -----
144
145func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
146  %c1 = arith.constant 1 : index
147  %c100 = arith.constant 100 : index
148  %c50 = arith.constant 50 : index
149  %shape = fir.shape %c100, %c50 : (index, index) -> !fir.shape<2>
150  // expected-error@+1 {{'fir.array_coor' op operand #0 must be any reference or box, but got 'index'}}
151  %p = fir.array_coor %c100(%shape) %c1, %c1 : (index, !fir.shape<2>, index, index) -> !fir.ref<f32>
152  return
153}
154
155// -----
156
157func.func @array_access(%arr : !fir.ref<f32>) {
158  %c1 = arith.constant 1 : index
159  %c100 = arith.constant 100 : index
160  %c50 = arith.constant 50 : index
161  %shape = fir.shape %c100, %c50 : (index, index) -> !fir.shape<2>
162  // expected-error@+1 {{'fir.array_coor' op must be a reference to an array}}
163  %p = fir.array_coor %arr(%shape) %c1, %c1 : (!fir.ref<f32>, !fir.shape<2>, index, index) -> !fir.ref<f32>
164  return
165}
166
167// -----
168
169func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
170  %c1 = arith.constant 1 : index
171  %c100 = arith.constant 100 : index
172  %c50 = arith.constant 50 : index
173  %shape = fir.shape %c100, %c50 : (index, index) -> !fir.shape<2>
174  %c47 = arith.constant 47 : index
175  %c78 = arith.constant 78 : index
176  %c3 = arith.constant 3 : index
177  %slice = fir.slice %c47, %c78, %c3 : (index,index,index) -> !fir.slice<1>
178  // expected-error@+1 {{'fir.array_coor' op rank of dimension in slice mismatched}}
179  %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>
180  return
181}
182
183// -----
184
185func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
186  %c1 = arith.constant 1 : index
187  %c100 = arith.constant 100 : index
188  %shape = fir.shape %c100 : (index) -> !fir.shape<1>
189  // expected-error@+1 {{'fir.array_coor' op rank of dimension mismatched}}
190  %p = fir.array_coor %arr(%shape) %c1, %c1 : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<1>, index, index) -> !fir.ref<f32>
191  return
192}
193
194// -----
195
196func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
197  %c1 = arith.constant 1 : index
198  %c100 = arith.constant 100 : index
199  %shift = fir.shift %c1 : (index) -> !fir.shift<1>
200  // expected-error@+1 {{'fir.array_coor' op shift can only be provided with fir.box memref}}
201  %p = fir.array_coor %arr(%shift) %c1, %c1 : (!fir.ref<!fir.array<?x?xf32>>, !fir.shift<1>, index, index) -> !fir.ref<f32>
202  return
203}
204
205// -----
206
207func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
208  %c1 = arith.constant 1 : index
209  %c100 = arith.constant 100 : index
210  %c50 = arith.constant 50 : index
211  %shape = fir.shape %c100, %c50 : (index, index) -> !fir.shape<2>
212  // expected-error@+1 {{'fir.array_coor' op number of indices do not match dim rank}}
213  %p = fir.array_coor %arr(%shape) %c1 : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>, index) -> !fir.ref<f32>
214  return
215}
216
217// -----
218
219func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
220  %c2 = arith.constant 2 : index
221  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
222  // expected-error@+1 {{'fir.array_load' op operand #0 must be any reference or box, but got 'index'}}
223  %av1 = fir.array_load %c2(%s) : (index, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
224  return
225}
226
227// -----
228
229func.func @test_misc_ops(%arr1 : !fir.ref<f32>, %m : index, %n : index, %o : index, %p : index) {
230  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
231  // expected-error@+1 {{'fir.array_load' op must be a reference to an array}}
232  %av1 = fir.array_load %arr1(%s) : (!fir.ref<f32>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
233  return
234}
235
236// -----
237
238func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
239  %s = fir.shape_shift %m, %n: (index, index) -> !fir.shapeshift<1>
240  // expected-error@+1 {{'fir.array_load' op rank of dimension mismatched}}
241  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<1>) -> !fir.array<?x?xf32>
242  return
243}
244
245// -----
246
247func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
248  %c2 = arith.constant 2 : index
249  %shift = fir.shift %c2 : (index) -> !fir.shift<1>
250  // expected-error@+1 {{'fir.array_load' op shift can only be provided with fir.box memref}}
251  %av1 = fir.array_load %arr1(%shift) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shift<1>) -> !fir.array<?x?xf32>
252  return
253}
254
255// -----
256
257func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
258  %c47 = arith.constant 47 : index
259  %c78 = arith.constant 78 : index
260  %c3 = arith.constant 3 : index
261  %slice = fir.slice %c47, %c78, %c3 : (index,index,index) -> !fir.slice<1>
262  %s = fir.shape_shift %m, %n, %o, %p: (index, index, index, index) -> !fir.shapeshift<2>
263  // expected-error@+1 {{'fir.array_load' op rank of dimension in slice mismatched}}
264  %av1 = fir.array_load %arr1(%s)[%slice] : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>, !fir.slice<1>) -> !fir.array<?x?xf32>
265  return
266}
267
268// -----
269
270func.func @test_coordinate_of(%arr : !fir.ref<!fir.array<?x?xf32>>) {
271  %1 = arith.constant 10 : i32
272  // expected-error@+1 {{'fir.coordinate_of' op cannot find coordinate with unknown extents}}
273  %2 = fir.coordinate_of %arr, %1 : (!fir.ref<!fir.array<?x?xf32>>, i32) -> !fir.ref<f32>
274  return
275}
276
277// -----
278
279func.func @test_coordinate_of(%arr : !fir.ref<!fir.array<*:f32>>) {
280  %1 = arith.constant 10 : i32
281  // expected-error@+1 {{'fir.coordinate_of' op cannot find coordinate in unknown shape}}
282  %2 = fir.coordinate_of %arr, %1 : (!fir.ref<!fir.array<*:f32>>, i32) -> !fir.ref<f32>
283  return
284}
285
286// -----
287
288func.func @test_coordinate_of(%arr : !fir.ref<!fir.char<10>>) {
289  %1 = arith.constant 10 : i32
290  // expected-error@+1 {{'fir.coordinate_of' op cannot apply coordinate_of to this type}}
291  %2 = fir.coordinate_of %arr, %1 : (!fir.ref<!fir.char<10>>, i32) -> !fir.ref<f32>
292  return
293}
294
295// -----
296
297func.func @test_coordinate_of(%arr : !fir.ref<!fir.char<10, 1>>) {
298  %1 = arith.constant 10 : i32
299  // expected-error@+1 {{'fir.coordinate_of' op cannot apply coordinate_of to this type}}
300  %2 = fir.coordinate_of %arr, %1 : (!fir.ref<!fir.char<10, 1>>, i32) -> !fir.ref<f32>
301  return
302}
303
304// -----
305
306%0 = arith.constant 22 : i32
307// expected-error@+1 {{'fir.embox' op operand #0 must be any reference, but got 'i32'}}
308%1 = fir.embox %0 : (i32) -> !fir.box<i32>
309
310// -----
311
312func.func @fun(%0 : !fir.ref<i32>) {
313  %c_100 = arith.constant 100 : index
314  %1 = fir.shape %c_100 : (index) -> !fir.shape<1>
315  // expected-error@+1 {{'fir.embox' op shape must not be provided for a scalar}}
316  %2 = fir.embox %0(%1) : (!fir.ref<i32>, !fir.shape<1>) -> !fir.box<i32>
317}
318
319// -----
320
321func.func @fun(%0 : !fir.ref<i32>) {
322  %c_100 = arith.constant 100 : index
323  %1 = fir.slice %c_100, %c_100, %c_100 : (index, index, index) -> !fir.slice<1>
324  // expected-error@+1 {{'fir.embox' op operand #1 must be any legal shape type, but got '!fir.slice<1>'}}
325  %2 = fir.embox %0(%1) : (!fir.ref<i32>, !fir.slice<1>) -> !fir.box<i32>
326}
327
328// -----
329
330func.func @fun(%0 : !fir.ref<i32>) {
331  %c_100 = arith.constant 100 : index
332  %1 = fir.shape %c_100 : (index) -> !fir.shape<1>
333  // expected-error@+1 {{'fir.embox' op operand #1 must be FIR slice, but got '!fir.shape<1>'}}
334  %2 = fir.embox %0[%1] : (!fir.ref<i32>, !fir.shape<1>) -> !fir.box<i32>
335}
336
337// -----
338
339func.func @fun(%0 : !fir.ref<i32>) {
340  %c_100 = arith.constant 100 : index
341  %1 = fir.slice %c_100, %c_100, %c_100 : (index, index, index) -> !fir.slice<1>
342  // expected-error@+1 {{'fir.embox' op slice must not be provided for a scalar}}
343  %2 = fir.embox %0[%1] : (!fir.ref<i32>, !fir.slice<1>) -> !fir.box<i32>
344}
345
346// -----
347
348%lo = arith.constant 1 : index
349%c1 = arith.constant 1 : index
350%up = arith.constant 10 : index
351%okIn = arith.constant 1 : i1
352%shIn = arith.constant 1 : i16
353// expected-error@+1 {{'fir.iterate_while' op expected body first argument to be an index argument for the induction variable}}
354%v:3 = fir.iterate_while (%i = %lo to %up step %c1) and (%ok = %okIn) iter_args(%sh = %shIn) -> (i16, i1, i16) {
355  %shNew = fir.call @bar(%sh) : (i16) -> i16
356  %okNew = fir.call @foo(%sh) : (i16) -> i1
357  fir.result %shNew, %okNew, %shNew : i16, i1, i16
358}
359
360// -----
361
362%lo = arith.constant 1 : index
363%c1 = arith.constant 1 : index
364%up = arith.constant 10 : index
365%okIn = arith.constant 1 : i1
366%shIn = arith.constant 1 : i16
367// expected-error@+1 {{'fir.iterate_while' op expected body second argument to be an index argument for the induction variable}}
368%v:3 = fir.iterate_while (%i = %lo to %up step %c1) and (%ok = %okIn) iter_args(%sh = %shIn) -> (index, f32, i16) {
369  %shNew = fir.call @bar(%sh) : (i16) -> i16
370  %dummy = fir.call @foo(%sh) : (i16) -> f32
371  fir.result %i, %dummy, %shNew : index, f32, i16
372}
373
374// -----
375
376%c1 = arith.constant 1 : index
377%c10 = arith.constant 10 : index
378// expected-error@+1 {{'fir.do_loop' op unordered loop has no final value}}
379fir.do_loop %i = %c1 to %c10 step %c1 unordered -> index {
380}
381
382// -----
383
384%c1 = arith.constant 1 : index
385%c10 = arith.constant 10 : index
386fir.do_loop %i = %c1 to %c10 step %c1 -> index {
387  %f1 = arith.constant 1.0 : f32
388  // expected-error@+1 {{'fir.result' op types mismatch between result op and its parent}}
389  fir.result %f1 : f32
390}
391
392// -----
393
394%c1 = arith.constant 1 : index
395%c10 = arith.constant 10 : index
396// expected-error@+1 {{'fir.result' op parent of result must have same arity}}
397fir.do_loop %i = %c1 to %c10 step %c1 -> index {
398}
399
400// -----
401
402func.func @ugly_char_convert() {
403  %1 = fir.undefined i32
404  %2 = fir.undefined !fir.ref<!fir.char<1>>
405  %3 = fir.undefined !fir.ref<!fir.array<?x!fir.char<1>>>
406  // expected-error@+1 {{'fir.char_convert' op buffers must have different KIND values}}
407  fir.char_convert %2 for %1 to %3 : !fir.ref<!fir.char<1>>, i32, !fir.ref<!fir.array<?x!fir.char<1>>>
408  return
409}
410
411// -----
412
413func.func @ugly_char_convert() {
414  %1 = fir.undefined i32
415  %2 = fir.undefined !fir.ref<!fir.char<1>>
416  %3 = fir.undefined !fir.ref<!fir.array<?xf32>>
417  // expected-error@+1 {{'fir.char_convert' op not a reference to a character}}
418  fir.char_convert %2 for %1 to %3 : !fir.ref<!fir.char<1>>, i32, !fir.ref<!fir.array<?xf32>>
419  return
420}
421
422// -----
423
424func.func @ugly_char_convert() {
425  %1 = fir.undefined i32
426  %2 = fir.undefined !fir.ref<!fir.char<1>>
427  %3 = fir.undefined !fir.ref<!fir.array<?x!fir.char<2,?>>>
428  // expected-error@+1 {{'fir.char_convert' op operand #0 must be any reference, but got 'i32'}}
429  fir.char_convert %1 for %1 to %3 : i32, i32, !fir.ref<!fir.array<?x!fir.char<2,?>>>
430  return
431}
432
433// -----
434
435func.func @ugly_char_convert() {
436  %1 = fir.undefined i32
437  %2 = fir.undefined !fir.ref<!fir.char<1>>
438  %3 = fir.undefined !fir.ref<!fir.array<?x!fir.char<2,?>>>
439  // expected-error@+1 {{'fir.char_convert' op operand #1 must be any integer, but got '!fir.ref<!fir.char<1>>'}}
440  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,?>>>
441  return
442}
443
444// -----
445
446fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
447  %c0_i32 = arith.constant 1 : i32
448  %0 = fir.undefined !fir.array<32x32xi32>
449  // expected-error@+1 {{'fir.insert_on_range' op has uneven number of values in ranges}}
450  %2 = "fir.insert_on_range"(%0, %c0_i32) { coor = dense<[0, 31, 0]> : tensor<3xindex> } : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
451  fir.has_value %2 : !fir.array<32x32xi32>
452}
453
454// -----
455
456fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
457  %c0_i32 = arith.constant 1 : i32
458  %0 = fir.undefined !fir.array<32x32xi32>
459  // expected-error@+1 {{'fir.insert_on_range' op has uneven number of values in ranges}}
460  %2 = "fir.insert_on_range"(%0, %c0_i32) { coor = dense<[0]> : tensor<1xindex> }  : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
461  fir.has_value %2 : !fir.array<32x32xi32>
462}
463
464// -----
465
466fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
467  %c0_i32 = arith.constant 1 : i32
468  %0 = fir.undefined !fir.array<32x32xi32>
469  // expected-error@+1 {{'fir.insert_on_range' op negative range bound}}
470  %2 = fir.insert_on_range %0, %c0_i32 from (-1) to (0) : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
471  fir.has_value %2 : !fir.array<32x32xi32>
472}
473
474// -----
475
476fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
477  %c0_i32 = arith.constant 1 : i32
478  %0 = fir.undefined !fir.array<32x32xi32>
479  // expected-error@+1 {{'fir.insert_on_range' op empty range}}
480  %2 = fir.insert_on_range %0, %c0_i32 from (10) to (9) : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
481  fir.has_value %2 : !fir.array<32x32xi32>
482}
483
484// -----
485
486fir.global internal @_QEmultiarray : !fir.array<?xi32> {
487  %c0_i32 = arith.constant 1 : i32
488  %0 = fir.undefined !fir.array<?xi32>
489  // expected-error@+1 {{'fir.insert_on_range' op must have constant shape and size}}
490  %2 = fir.insert_on_range %0, %c0_i32 from (0) to (10) : (!fir.array<?xi32>, i32) -> !fir.array<?xi32>
491  fir.has_value %2 : !fir.array<?xi32>
492}
493
494// -----
495
496fir.global internal @_QEmultiarray : !fir.array<*:i32> {
497  %c0_i32 = arith.constant 1 : i32
498  %0 = fir.undefined !fir.array<*:i32>
499  // expected-error@+1 {{'fir.insert_on_range' op must have constant shape and size}}
500  %2 = fir.insert_on_range %0, %c0_i32 from (0) to (10) : (!fir.array<*:i32>, i32) -> !fir.array<*:i32>
501  fir.has_value %2 : !fir.array<*:i32>
502}
503
504// -----
505
506func.func @bad_save_result(%buffer : !fir.ref<!fir.array<?xf64>>, %n :index) {
507  %res = fir.call @array_func() : () -> !fir.array<?xf32>
508  %shape = fir.shape %n : (index) -> !fir.shape<1>
509  // expected-error@+1 {{'fir.save_result' op value type must match memory reference type}}
510  fir.save_result %res to %buffer(%shape) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf64>>, !fir.shape<1>
511  return
512}
513
514// -----
515
516func.func @bad_save_result(%buffer : !fir.ref<!fir.box<!fir.array<*:f32>>>) {
517  %res = fir.call @array_func() : () -> !fir.box<!fir.array<*:f32>>
518  // expected-error@+1 {{'fir.save_result' op cannot save !fir.box of unknown rank or type}}
519  fir.save_result %res to %buffer : !fir.box<!fir.array<*:f32>>, !fir.ref<!fir.box<!fir.array<*:f32>>>
520  return
521}
522
523// -----
524
525func.func @bad_save_result(%buffer : !fir.ref<f64>) {
526  %res = fir.call @array_func() : () -> f64
527  // expected-error@+1 {{'fir.save_result' op operand #0 must be fir.box, fir.array or fir.type, but got 'f64'}}
528  fir.save_result %res to %buffer : f64, !fir.ref<f64>
529  return
530}
531
532// -----
533
534func.func @bad_save_result(%buffer : !fir.ref<!fir.box<!fir.array<?xf32>>>, %n : index) {
535  %res = fir.call @array_func() : () -> !fir.box<!fir.array<?xf32>>
536  %shape = fir.shape %n : (index) -> !fir.shape<1>
537  // expected-error@+1 {{'fir.save_result' op must not have shape or length operands if the value is a fir.box}}
538  fir.save_result %res to %buffer(%shape) : !fir.box<!fir.array<?xf32>>, !fir.ref<!fir.box<!fir.array<?xf32>>>, !fir.shape<1>
539  return
540}
541
542// -----
543
544func.func @bad_save_result(%buffer : !fir.ref<!fir.array<?xf32>>, %n :index) {
545  %res = fir.call @array_func() : () -> !fir.array<?xf32>
546  %shape = fir.shape %n, %n : (index, index) -> !fir.shape<2>
547  // expected-error@+1 {{'fir.save_result' op shape operand must be provided and have the value rank when the value is a fir.array}}
548  fir.save_result %res to %buffer(%shape) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<2>
549  return
550}
551
552// -----
553
554func.func @bad_save_result(%buffer : !fir.ref<!fir.type<t{x:f32}>>, %n :index) {
555  %res = fir.call @array_func() : () -> !fir.type<t{x:f32}>
556  %shape = fir.shape %n : (index) -> !fir.shape<1>
557  // expected-error@+1 {{'fir.save_result' op shape operand should only be provided if the value is a fir.array}}
558  fir.save_result %res to %buffer(%shape) : !fir.type<t{x:f32}>, !fir.ref<!fir.type<t{x:f32}>>, !fir.shape<1>
559  return
560}
561
562// -----
563
564func.func @bad_save_result(%buffer : !fir.ref<!fir.type<t{x:f32}>>, %n :index) {
565  %res = fir.call @array_func() : () -> !fir.type<t{x:f32}>
566  // expected-error@+1 {{'fir.save_result' op length parameters number must match with the value type length parameters}}
567  fir.save_result %res to %buffer typeparams %n : !fir.type<t{x:f32}>, !fir.ref<!fir.type<t{x:f32}>>, index
568  return
569}
570
571// -----
572
573func.func @bad_save_result(%buffer : !fir.ref<!fir.array<?xf32>>, %n :index) {
574  %res = fir.call @array_func() : () -> !fir.array<?xf32>
575  %shape = fir.shape %n : (index) -> !fir.shape<1>
576  // expected-error@+1 {{'fir.save_result' op length parameters must not be provided for this value type}}
577  fir.save_result %res to %buffer(%shape) typeparams %n : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>, index
578  return
579}
580
581// -----
582
583func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
584  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
585  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
586  // expected-error@+1 {{'fir.array_fetch' op number of indices != dimension of array}}
587  %f = fir.array_fetch %av1, %m : (!fir.array<?x?xf32>, index) -> f32
588  return
589}
590
591// -----
592
593func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
594  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
595  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
596  // expected-error@+1 {{'fir.array_fetch' op return type does not match array}}
597  %f = fir.array_fetch %av1, %m, %n : (!fir.array<?x?xf32>, index, index) -> i32
598  return
599}
600
601// -----
602
603func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
604  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
605  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
606  %f = fir.array_fetch %av1, %m, %n : (!fir.array<?x?xf32>, index, index) -> f32
607  // expected-error@+1 {{'fir.array_update' op number of indices != dimension of array}}
608  %av2 = fir.array_update %av1, %f, %m : (!fir.array<?x?xf32>, f32, index) -> !fir.array<?x?xf32>
609  return
610}
611
612// -----
613
614func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
615  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
616  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
617  %c0 = arith.constant 0 : i32
618  // expected-error@+1 {{'fir.array_update' op merged value does not have element type}}
619  %av2 = fir.array_update %av1, %c0, %m, %n : (!fir.array<?x?xf32>, i32, index, index) -> !fir.array<?x?xf32>
620  return
621}
622
623// -----
624
625func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index, %f: !fir.ref<i32>) {
626  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
627  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
628  // expected-error@+1 {{'fir.array_update' op does not support reference type for merge}}
629  %av2 = fir.array_update %av1, %f, %m, %n : (!fir.array<?x?xf32>, !fir.ref<i32>, index, index) -> !fir.array<?x?xf32>
630  return
631}
632
633// -----
634
635func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
636  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
637  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
638  %f = fir.array_fetch %av1, %m, %n : (!fir.array<?x?xf32>, index, index) -> f32
639  %av2 = fir.array_update %av1, %f, %m, %n : (!fir.array<?x?xf32>, f32, index, index) -> !fir.array<?x?xf32>
640  // expected-error@+1 {{'fir.array_merge_store' op operand #0 must be result of a fir.array_load op}}
641  fir.array_merge_store %av2, %av2 to %arr1 : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
642  return
643}
644
645// -----
646
647func.func @bad_array_modify(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index, %f : f32) {
648  %i10 = arith.constant 10 : index
649  %j20 = arith.constant 20 : index
650  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
651  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
652  // expected-error@+1 {{'fir.array_modify' op number of indices must match array dimension}}
653  %addr, %av2 = fir.array_modify %av1, %i10 : (!fir.array<?x?xf32>, index) -> (!fir.ref<f32>, !fir.array<?x?xf32>)
654  fir.store %f to %addr : !fir.ref<f32>
655  fir.array_merge_store %av1, %av2 to %arr1 : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
656  return
657}
658
659// -----
660
661func.func @slice_must_be_integral() {
662  %0 = arith.constant 42 : i32
663  %1 = fir.field_index field, !fir.type<t(param:i32){field:i32}> (%0 : i32)
664  // expected-error@+1 {{'fir.slice' op operand #0 must be any integer, but got '!fir.field'}}
665  %2 = fir.slice %1, %1, %1 : (!fir.field, !fir.field, !fir.field) -> !fir.slice<1>
666  return
667}
668
669// -----
670
671func.func @array_coor_no_slice_substr(%a : !fir.ref<!fir.array<?x?xf32>>) {
672  %c1 = arith.constant 1 : index
673  %c10 = arith.constant 10 : index
674  %slice = fir.slice %c1, %c10, %c1 substr %c1, %c10 : (index, index, index, index, index) -> !fir.slice<1>
675  // expected-error@+1 {{'fir.array_coor' op array_coor cannot take a slice with substring}}
676  %p = fir.array_coor %a[%slice] %c1, %c1 : (!fir.ref<!fir.array<?x?xf32>>, !fir.slice<1>, index, index) -> !fir.ref<f32>
677  return
678}
679
680// -----
681
682func.func @array_coor_no_slice_substr(%a : !fir.ref<!fir.array<?x?xf32>>) {
683  %c1 = arith.constant 1 : index
684  %c10 = arith.constant 10 : index
685  %slice = fir.slice %c1, %c10, %c1 substr %c1, %c10 : (index, index, index, index, index) -> !fir.slice<1>
686  // expected-error@+1 {{'fir.array_load' op array_load cannot take a slice with substring}}
687  %v = fir.array_load %a[%slice] : (!fir.ref<!fir.array<?x?xf32>>, !fir.slice<1>) -> !fir.array<?x?xf32>
688  return
689}
690
691// -----
692
693func.func @array_merge_store_no_slice_substr(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index, %f : f32) {
694  %i10 = arith.constant 10 : index
695  %j20 = arith.constant 20 : index
696  %c1 = arith.constant 1 : index
697  %c10 = arith.constant 10 : index
698  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
699  %slice = fir.slice %c1, %c10, %c1 substr %c1, %c10 : (index, index, index, index, index) -> !fir.slice<1>
700  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
701  %addr, %av2 = fir.array_modify %av1, %i10, %i10 : (!fir.array<?x?xf32>, index, index) -> (!fir.ref<f32>, !fir.array<?x?xf32>)
702  fir.store %f to %addr : !fir.ref<f32>
703  // expected-error@+1 {{'fir.array_merge_store' op array_merge_store cannot take a slice with substring}}
704  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>
705  return
706}
707
708// -----
709
710func.func @array_access(%a : !fir.ref<!fir.array<?x?xf32>>) {
711  %c1 = arith.constant 1 : index
712  %n = arith.constant 0 : index
713  %m = arith.constant 50 : index
714  %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
715  %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
716  // expected-error@+1 {{'fir.array_access' op number of indices != dimension of array}}
717  %p = fir.array_access %v, %c1 : (!fir.array<?x?xf32>, index) -> !fir.ref<f32>
718  return
719}
720
721// -----
722
723func.func @array_access(%a : !fir.ref<!fir.array<?x?xf32>>) {
724  %c1 = arith.constant 1 : index
725  %n = arith.constant 0 : index
726  %m = arith.constant 50 : index
727  %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
728  %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
729  // expected-error@+1 {{'fir.array_access' op return type does not match array}}
730  %p = fir.array_access %v, %c1, %c1 : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f64>
731  return
732}
733
734// -----
735
736func.func @foo(%arg0: !fir.ref<!fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>>) {
737  %c1 = arith.constant 1 : index
738  %c0 = arith.constant 0 : index
739  %c9 = arith.constant 9 : index
740  %c19 = arith.constant 19 : index
741  %c30 = arith.constant 30 : index
742  %0 = fir.shape %c30 : (index) -> !fir.shape<1>
743  %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>}>>
744  %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>}>>) {
745    %3 = fir.field_index c, !fir.type<t{c:!fir.array<20xi32>}>
746    %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>}>>) {
747      // expected-error@+1 {{'fir.array_access' op return type and/or indices do not type check}}
748      %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>
749      %6 = fir.call @ifoo(%5) : (!fir.ref<f32>) -> i32
750      %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>}>>
751      fir.result %7 : !fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>
752    }
753    fir.result %4 : !fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>
754  }
755  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>}>>>
756  return
757}
758func.func private @ifoo(!fir.ref<f32>) -> i32
759