xref: /llvm-project/flang/test/Fir/invalid.fir (revision 390943f25b18a352bb3a72fe1b0908df355f77d9)
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 initializer 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 box or class, 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 box or class, 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 to this element type}}
291  %2 = fir.coordinate_of %arr, %1 : (!fir.ref<!fir.char<10>>, i32) -> !fir.ref<!fir.char<10>>
292  return
293}
294
295// -----
296
297func.func @test_coordinate_of(%arr : !fir.ref<!fir.char<10, 2>>) {
298  %1 = arith.constant 10 : i32
299  // expected-error@+1 {{'fir.coordinate_of' op cannot apply to character singleton}}
300  %2 = fir.coordinate_of %arr, %1, %1 : (!fir.ref<!fir.char<10, 2>>, i32, i32) -> !fir.ref<!fir.char<10>>
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
348func.func @embox_tdesc(%arg0: !fir.class<!fir.array<10x!fir.type<derived{a:i32,b:i32}>>>) {
349  %0 = fir.alloca i32
350  %c1_i32 = arith.constant 1 : i32
351  %1 = fir.convert %c1_i32 : (i32) -> index
352  %c10_i32 = arith.constant 10 : i32
353  %2 = fir.convert %c10_i32 : (i32) -> index
354  %c1 = arith.constant 1 : index
355  %3 = fir.convert %1 : (index) -> i32
356  %4:2 = fir.do_loop %arg2 = %1 to %2 step %c1 iter_args(%arg3 = %3) -> (index, i32) {
357    fir.store %arg3 to %0 : !fir.ref<i32>
358    %9 = fir.load %0 : !fir.ref<i32>
359    %10 = fir.convert %9 : (i32) -> i64
360    %c1_i64 = arith.constant 1 : i64
361    %11 = arith.subi %10, %c1_i64 : i64
362    %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}>>
363    // expected-error@+1 {{'fir.embox' op source_box must be used with fir.class result type}}
364    %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}>>
365    %14 = arith.addi %arg2, %c1 : index
366    %15 = fir.convert %c1 : (index) -> i32
367    %16 = fir.load %0 : !fir.ref<i32>
368    %17 = arith.addi %16, %15 : i32
369    fir.result %14, %17 : index, i32
370  }
371  fir.store %4#1 to %0 : !fir.ref<i32>
372  return
373}
374
375// -----
376
377%lo = arith.constant 1 : index
378%c1 = arith.constant 1 : index
379%up = arith.constant 10 : index
380%okIn = arith.constant 1 : i1
381%shIn = arith.constant 1 : i16
382// expected-error@+1 {{'fir.iterate_while' op expected body first argument to be an index argument for the induction variable}}
383%v:3 = fir.iterate_while (%i = %lo to %up step %c1) and (%ok = %okIn) iter_args(%sh = %shIn) -> (i16, i1, i16) {
384  %shNew = fir.call @bar(%sh) : (i16) -> i16
385  %okNew = fir.call @foo(%sh) : (i16) -> i1
386  fir.result %shNew, %okNew, %shNew : i16, i1, i16
387}
388
389// -----
390
391%lo = arith.constant 1 : index
392%c1 = arith.constant 1 : index
393%up = arith.constant 10 : index
394%okIn = arith.constant 1 : i1
395%shIn = arith.constant 1 : i16
396// expected-error@+1 {{'fir.iterate_while' op expected body second argument to be an index argument for the induction variable}}
397%v:3 = fir.iterate_while (%i = %lo to %up step %c1) and (%ok = %okIn) iter_args(%sh = %shIn) -> (index, f32, i16) {
398  %shNew = fir.call @bar(%sh) : (i16) -> i16
399  %dummy = fir.call @foo(%sh) : (i16) -> f32
400  fir.result %i, %dummy, %shNew : index, f32, i16
401}
402
403// -----
404
405%c1 = arith.constant 1 : index
406%c10 = arith.constant 10 : index
407// expected-error@+1 {{'fir.do_loop' op unordered loop has no final value}}
408fir.do_loop %i = %c1 to %c10 step %c1 unordered -> index {
409}
410
411// -----
412
413%c1 = arith.constant 1 : index
414%c10 = arith.constant 10 : index
415fir.do_loop %i = %c1 to %c10 step %c1 -> index {
416  %f1 = arith.constant 1.0 : f32
417  // expected-error@+1 {{'fir.result' op types mismatch between result op and its parent}}
418  fir.result %f1 : f32
419}
420
421// -----
422
423%c1 = arith.constant 1 : index
424%c10 = arith.constant 10 : index
425// expected-error@+1 {{'fir.result' op parent of result must have same arity}}
426fir.do_loop %i = %c1 to %c10 step %c1 -> index {
427}
428
429// -----
430
431func.func @ugly_char_convert() {
432  %1 = fir.undefined i32
433  %2 = fir.undefined !fir.ref<!fir.char<1>>
434  %3 = fir.undefined !fir.ref<!fir.array<?x!fir.char<1>>>
435  // expected-error@+1 {{'fir.char_convert' op buffers must have different KIND values}}
436  fir.char_convert %2 for %1 to %3 : !fir.ref<!fir.char<1>>, i32, !fir.ref<!fir.array<?x!fir.char<1>>>
437  return
438}
439
440// -----
441
442func.func @ugly_char_convert() {
443  %1 = fir.undefined i32
444  %2 = fir.undefined !fir.ref<!fir.char<1>>
445  %3 = fir.undefined !fir.ref<!fir.array<?xf32>>
446  // expected-error@+1 {{'fir.char_convert' op not a reference to a character}}
447  fir.char_convert %2 for %1 to %3 : !fir.ref<!fir.char<1>>, i32, !fir.ref<!fir.array<?xf32>>
448  return
449}
450
451// -----
452
453func.func @ugly_char_convert() {
454  %1 = fir.undefined i32
455  %2 = fir.undefined !fir.ref<!fir.char<1>>
456  %3 = fir.undefined !fir.ref<!fir.array<?x!fir.char<2,?>>>
457  // expected-error@+1 {{'fir.char_convert' op operand #0 must be any reference, but got 'i32'}}
458  fir.char_convert %1 for %1 to %3 : i32, i32, !fir.ref<!fir.array<?x!fir.char<2,?>>>
459  return
460}
461
462// -----
463
464func.func @ugly_char_convert() {
465  %1 = fir.undefined i32
466  %2 = fir.undefined !fir.ref<!fir.char<1>>
467  %3 = fir.undefined !fir.ref<!fir.array<?x!fir.char<2,?>>>
468  // expected-error@+1 {{'fir.char_convert' op operand #1 must be any integer, but got '!fir.ref<!fir.char<1>>'}}
469  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,?>>>
470  return
471}
472
473// -----
474
475fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
476  %c0_i32 = arith.constant 1 : i32
477  %0 = fir.undefined !fir.array<32x32xi32>
478  // expected-error@+1 {{'fir.insert_on_range' op has uneven number of values in ranges}}
479  %2 = "fir.insert_on_range"(%0, %c0_i32) { coor = dense<[0, 31, 0]> : tensor<3xindex> } : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
480  fir.has_value %2 : !fir.array<32x32xi32>
481}
482
483// -----
484
485fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
486  %c0_i32 = arith.constant 1 : i32
487  %0 = fir.undefined !fir.array<32x32xi32>
488  // expected-error@+1 {{'fir.insert_on_range' op has uneven number of values in ranges}}
489  %2 = "fir.insert_on_range"(%0, %c0_i32) { coor = dense<[0]> : tensor<1xindex> }  : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
490  fir.has_value %2 : !fir.array<32x32xi32>
491}
492
493// -----
494
495fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
496  %c0_i32 = arith.constant 1 : i32
497  %0 = fir.undefined !fir.array<32x32xi32>
498  // expected-error@+1 {{'fir.insert_on_range' op negative range bound}}
499  %2 = fir.insert_on_range %0, %c0_i32 from (-1) to (0) : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
500  fir.has_value %2 : !fir.array<32x32xi32>
501}
502
503// -----
504
505fir.global internal @_QEmultiarray : !fir.array<32x32xi32> {
506  %c0_i32 = arith.constant 1 : i32
507  %0 = fir.undefined !fir.array<32x32xi32>
508  // expected-error@+1 {{'fir.insert_on_range' op empty range}}
509  %2 = fir.insert_on_range %0, %c0_i32 from (10) to (9) : (!fir.array<32x32xi32>, i32) -> !fir.array<32x32xi32>
510  fir.has_value %2 : !fir.array<32x32xi32>
511}
512
513// -----
514
515fir.global internal @_QEmultiarray : !fir.array<?xi32> {
516  %c0_i32 = arith.constant 1 : i32
517  %0 = fir.undefined !fir.array<?xi32>
518  // expected-error@+1 {{'fir.insert_on_range' op must have constant shape and size}}
519  %2 = fir.insert_on_range %0, %c0_i32 from (0) to (10) : (!fir.array<?xi32>, i32) -> !fir.array<?xi32>
520  fir.has_value %2 : !fir.array<?xi32>
521}
522
523// -----
524
525fir.global internal @_QEmultiarray : !fir.array<*:i32> {
526  %c0_i32 = arith.constant 1 : i32
527  %0 = fir.undefined !fir.array<*:i32>
528  // expected-error@+1 {{'fir.insert_on_range' op must have constant shape and size}}
529  %2 = fir.insert_on_range %0, %c0_i32 from (0) to (10) : (!fir.array<*:i32>, i32) -> !fir.array<*:i32>
530  fir.has_value %2 : !fir.array<*:i32>
531}
532
533// -----
534
535func.func @bad_save_result(%buffer : !fir.ref<!fir.array<?xf64>>, %n :index) {
536  %res = fir.call @array_func() : () -> !fir.array<?xf32>
537  %shape = fir.shape %n : (index) -> !fir.shape<1>
538  // expected-error@+1 {{'fir.save_result' op value type must match memory reference type}}
539  fir.save_result %res to %buffer(%shape) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf64>>, !fir.shape<1>
540  return
541}
542
543// -----
544
545func.func @bad_save_result(%buffer : !fir.ref<!fir.box<!fir.array<*:f32>>>) {
546  %res = fir.call @array_func() : () -> !fir.box<!fir.array<*:f32>>
547  // expected-error@+1 {{'fir.save_result' op cannot save !fir.box of unknown rank or type}}
548  fir.save_result %res to %buffer : !fir.box<!fir.array<*:f32>>, !fir.ref<!fir.box<!fir.array<*:f32>>>
549  return
550}
551
552// -----
553
554func.func @bad_save_result(%buffer : !fir.ref<f64>) {
555  %res = fir.call @array_func() : () -> f64
556  // expected-error@+1 {{'fir.save_result' op operand #0 must be fir.box, fir.array or fir.type, but got 'f64'}}
557  fir.save_result %res to %buffer : f64, !fir.ref<f64>
558  return
559}
560
561// -----
562
563func.func @bad_save_result(%buffer : !fir.ref<!fir.box<!fir.array<?xf32>>>, %n : index) {
564  %res = fir.call @array_func() : () -> !fir.box<!fir.array<?xf32>>
565  %shape = fir.shape %n : (index) -> !fir.shape<1>
566  // expected-error@+1 {{'fir.save_result' op must not have shape or length operands if the value is a fir.box}}
567  fir.save_result %res to %buffer(%shape) : !fir.box<!fir.array<?xf32>>, !fir.ref<!fir.box<!fir.array<?xf32>>>, !fir.shape<1>
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, %n : (index, index) -> !fir.shape<2>
576  // expected-error@+1 {{'fir.save_result' op shape operand must be provided and have the value rank when the value is a fir.array}}
577  fir.save_result %res to %buffer(%shape) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<2>
578  return
579}
580
581// -----
582
583func.func @bad_save_result(%buffer : !fir.ref<!fir.type<t{x:f32}>>, %n :index) {
584  %res = fir.call @array_func() : () -> !fir.type<t{x:f32}>
585  %shape = fir.shape %n : (index) -> !fir.shape<1>
586  // expected-error@+1 {{'fir.save_result' op shape operand should only be provided if the value is a fir.array}}
587  fir.save_result %res to %buffer(%shape) : !fir.type<t{x:f32}>, !fir.ref<!fir.type<t{x:f32}>>, !fir.shape<1>
588  return
589}
590
591// -----
592
593func.func @bad_save_result(%buffer : !fir.ref<!fir.type<t{x:f32}>>, %n :index) {
594  %res = fir.call @array_func() : () -> !fir.type<t{x:f32}>
595  // expected-error@+1 {{'fir.save_result' op length parameters number must match with the value type length parameters}}
596  fir.save_result %res to %buffer typeparams %n : !fir.type<t{x:f32}>, !fir.ref<!fir.type<t{x:f32}>>, index
597  return
598}
599
600// -----
601
602func.func @bad_save_result(%buffer : !fir.ref<!fir.array<?xf32>>, %n :index) {
603  %res = fir.call @array_func() : () -> !fir.array<?xf32>
604  %shape = fir.shape %n : (index) -> !fir.shape<1>
605  // expected-error@+1 {{'fir.save_result' op length parameters must not be provided for this value type}}
606  fir.save_result %res to %buffer(%shape) typeparams %n : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>, index
607  return
608}
609
610// -----
611
612func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
613  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
614  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
615  // expected-error@+1 {{'fir.array_fetch' op number of indices != dimension of array}}
616  %f = fir.array_fetch %av1, %m : (!fir.array<?x?xf32>, index) -> f32
617  return
618}
619
620// -----
621
622func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
623  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
624  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
625  // expected-error@+1 {{'fir.array_fetch' op return type does not match array}}
626  %f = fir.array_fetch %av1, %m, %n : (!fir.array<?x?xf32>, index, index) -> i32
627  return
628}
629
630// -----
631
632func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
633  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
634  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
635  %f = fir.array_fetch %av1, %m, %n : (!fir.array<?x?xf32>, index, index) -> f32
636  // expected-error@+1 {{'fir.array_update' op number of indices != dimension of array}}
637  %av2 = fir.array_update %av1, %f, %m : (!fir.array<?x?xf32>, f32, index) -> !fir.array<?x?xf32>
638  return
639}
640
641// -----
642
643func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
644  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
645  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
646  %c0 = arith.constant 0 : i32
647  // expected-error@+1 {{'fir.array_update' op merged value does not have element type}}
648  %av2 = fir.array_update %av1, %c0, %m, %n : (!fir.array<?x?xf32>, i32, index, index) -> !fir.array<?x?xf32>
649  return
650}
651
652// -----
653
654func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index, %f: !fir.ref<i32>) {
655  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
656  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
657  // expected-error@+1 {{'fir.array_update' op does not support reference type for merge}}
658  %av2 = fir.array_update %av1, %f, %m, %n : (!fir.array<?x?xf32>, !fir.ref<i32>, index, index) -> !fir.array<?x?xf32>
659  return
660}
661
662// -----
663
664func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
665  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
666  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
667  %f = fir.array_fetch %av1, %m, %n : (!fir.array<?x?xf32>, index, index) -> f32
668  %av2 = fir.array_update %av1, %f, %m, %n : (!fir.array<?x?xf32>, f32, index, index) -> !fir.array<?x?xf32>
669  // expected-error@+1 {{'fir.array_merge_store' op operand #0 must be result of a fir.array_load op}}
670  fir.array_merge_store %av2, %av2 to %arr1 : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
671  return
672}
673
674// -----
675
676func.func @bad_array_modify(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index, %f : f32) {
677  %i10 = arith.constant 10 : index
678  %j20 = arith.constant 20 : index
679  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
680  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
681  // expected-error@+1 {{'fir.array_modify' op number of indices must match array dimension}}
682  %addr, %av2 = fir.array_modify %av1, %i10 : (!fir.array<?x?xf32>, index) -> (!fir.ref<f32>, !fir.array<?x?xf32>)
683  fir.store %f to %addr : !fir.ref<f32>
684  fir.array_merge_store %av1, %av2 to %arr1 : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
685  return
686}
687
688// -----
689
690func.func @slice_must_be_integral() {
691  %0 = arith.constant 42 : i32
692  %1 = fir.field_index field, !fir.type<t(param:i32){field:i32}> (%0 : i32)
693  // expected-error@+1 {{'fir.slice' op operand #0 must be variadic of any integer, but got '!fir.field'}}
694  %2 = fir.slice %1, %1, %1 : (!fir.field, !fir.field, !fir.field) -> !fir.slice<1>
695  return
696}
697
698// -----
699
700func.func @array_coor_no_slice_substr(%a : !fir.ref<!fir.array<?x?xf32>>) {
701  %c1 = arith.constant 1 : index
702  %c10 = arith.constant 10 : index
703  %slice = fir.slice %c1, %c10, %c1 substr %c1, %c10 : (index, index, index, index, index) -> !fir.slice<1>
704  // expected-error@+1 {{'fir.array_coor' op array_coor cannot take a slice with substring}}
705  %p = fir.array_coor %a[%slice] %c1, %c1 : (!fir.ref<!fir.array<?x?xf32>>, !fir.slice<1>, index, index) -> !fir.ref<f32>
706  return
707}
708
709// -----
710
711func.func @array_coor_no_slice_substr(%a : !fir.ref<!fir.array<?x?xf32>>) {
712  %c1 = arith.constant 1 : index
713  %c10 = arith.constant 10 : index
714  %slice = fir.slice %c1, %c10, %c1 substr %c1, %c10 : (index, index, index, index, index) -> !fir.slice<1>
715  // expected-error@+1 {{'fir.array_load' op array_load cannot take a slice with substring}}
716  %v = fir.array_load %a[%slice] : (!fir.ref<!fir.array<?x?xf32>>, !fir.slice<1>) -> !fir.array<?x?xf32>
717  return
718}
719
720// -----
721
722func.func @array_merge_store_no_slice_substr(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index, %f : f32) {
723  %i10 = arith.constant 10 : index
724  %j20 = arith.constant 20 : index
725  %c1 = arith.constant 1 : index
726  %c10 = arith.constant 10 : index
727  %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
728  %slice = fir.slice %c1, %c10, %c1 substr %c1, %c10 : (index, index, index, index, index) -> !fir.slice<1>
729  %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
730  %addr, %av2 = fir.array_modify %av1, %i10, %i10 : (!fir.array<?x?xf32>, index, index) -> (!fir.ref<f32>, !fir.array<?x?xf32>)
731  fir.store %f to %addr : !fir.ref<f32>
732  // expected-error@+1 {{'fir.array_merge_store' op array_merge_store cannot take a slice with substring}}
733  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>
734  return
735}
736
737// -----
738
739func.func @array_access(%a : !fir.ref<!fir.array<?x?xf32>>) {
740  %c1 = arith.constant 1 : index
741  %n = arith.constant 0 : index
742  %m = arith.constant 50 : index
743  %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
744  %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
745  // expected-error@+1 {{'fir.array_access' op number of indices != dimension of array}}
746  %p = fir.array_access %v, %c1 : (!fir.array<?x?xf32>, index) -> !fir.ref<f32>
747  return
748}
749
750// -----
751
752func.func @array_access(%a : !fir.ref<!fir.array<?x?xf32>>) {
753  %c1 = arith.constant 1 : index
754  %n = arith.constant 0 : index
755  %m = arith.constant 50 : index
756  %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
757  %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
758  // expected-error@+1 {{'fir.array_access' op return type does not match array}}
759  %p = fir.array_access %v, %c1, %c1 : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f64>
760  return
761}
762
763// -----
764
765func.func @foo(%arg0: !fir.ref<!fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>>) {
766  %c1 = arith.constant 1 : index
767  %c0 = arith.constant 0 : index
768  %c9 = arith.constant 9 : index
769  %c19 = arith.constant 19 : index
770  %c30 = arith.constant 30 : index
771  %0 = fir.shape %c30 : (index) -> !fir.shape<1>
772  %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>}>>
773  %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>}>>) {
774    %3 = fir.field_index c, !fir.type<t{c:!fir.array<20xi32>}>
775    %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>}>>) {
776      // expected-error@+1 {{'fir.array_access' op return type and/or indices do not type check}}
777      %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>
778      %6 = fir.call @ifoo(%5) : (!fir.ref<f32>) -> i32
779      %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>}>>
780      fir.result %7 : !fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>
781    }
782    fir.result %4 : !fir.array<30x!fir.type<t{c:!fir.array<20xi32>}>>
783  }
784  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>}>>>
785  return
786}
787func.func private @ifoo(!fir.ref<f32>) -> i32
788
789// -----
790
791func.func private @dispatch(%arg0: !fir.class<!fir.type<derived{a:i32,b:i32}>>) -> () {
792  // expected-error@+1 {{'fir.dispatch' op pass_arg_pos must be smaller than the number of operands}}
793  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}
794  return
795}
796
797// -----
798
799func.func private @dispatch(%arg0: !fir.class<!fir.type<derived{a:i32,b:i32}>>, %arg1: i32) -> () {
800  // expected-error@+1 {{'fir.dispatch' op pass_arg_pos must be a polymorphic operand}}
801  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}
802  return
803}
804
805// -----
806func.func @test_fortran_var_attrs() {
807  // expected-error@+1 {{Unknown fortran variable attribute: volatypo}}
808  %0 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<volatypo>}
809}
810
811// -----
812func.func @bad_numeric_declare(%arg0: !fir.ref<f32>) {
813  %c1 = arith.constant 1 : index
814  // expected-error@+1 {{'fir.declare' op requires attribute 'uniq_name'}}
815  %0 = fir.declare %arg0 typeparams %c1 {uniq_typo = "x"} : (!fir.ref<f32>, index) -> !fir.ref<f32>
816  return
817}
818
819// -----
820func.func @bad_numeric_declare(%arg0: !fir.ref<f32>) {
821  %c1 = arith.constant 1 : index
822  // expected-error@+1 {{'fir.declare' op of numeric, logical, or assumed type entity must not have length parameters}}
823  %0 = fir.declare %arg0 typeparams %c1 {uniq_name = "x"} : (!fir.ref<f32>, index) -> !fir.ref<f32>
824  return
825}
826
827// -----
828func.func @bad_char_declare(%arg0: !fir.boxchar<1> ) {
829  %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
830  // expected-error@+1 {{'fir.declare' op must be provided exactly one type parameter when its base is a character that is not a box}}
831  %1 = fir.declare %0#0 {uniq_name = "c"} : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.char<1,?>>
832  return
833}
834
835// -----
836func.func @bad_char_declare(%arg0: !fir.boxchar<1> ) {
837  %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
838  // expected-error@+1 {{'fir.declare' op of character entity must have at most one length parameter}}
839  %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,?>>
840  return
841}
842
843// -----
844func.func @bad_derived_declare(%arg0: !fir.ref<!fir.type<t{field:i32}>>) {
845  %c1 = arith.constant 1 : index
846  // expected-error@+1 {{'fir.declare' op has too many length parameters}}
847  %0 = fir.declare %arg0 typeparams %c1 {uniq_name = "x"} : (!fir.ref<!fir.type<t{field:i32}>>, index) -> !fir.ref<!fir.type<t{field:i32}>>
848  return
849}
850
851// -----
852func.func @bad_pdt_declare(%arg0: !fir.ref<!fir.type<pdt(param:i32){field:i32}>>) {
853  // expected-error@+1 {{'fir.declare' op must be provided all the derived type length parameters when the base is not a box}}
854  %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}>>
855  return
856}
857
858// -----
859func.func @bad_pdt_declare_2(%arg0: !fir.ref<!fir.type<pdt(param:i32){field:i32}>>) {
860  %c1 = arith.constant 1 : index
861  // expected-error@+1 {{'fir.declare' op has too many length parameters}}
862  %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}>>
863  return
864}
865
866
867// -----
868func.func @bad_array_declare(%arg0: !fir.ref<!fir.array<?x?xf32>>) {
869  // 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}}
870  %0 = fir.declare %arg0 {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>) -> !fir.ref<!fir.array<?x?xf32>>
871  return
872}
873
874// -----
875func.func @bad_array_declare_2(%arg0: !fir.ref<!fir.array<?x?xf32>>) {
876  %c1 = arith.constant 1 : index
877  %c2 = arith.constant 2 : index
878  %shift = fir.shift %c1, %c2 : (index, index) -> !fir.shift<2>
879  // 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}}
880  %0 = fir.declare %arg0(%shift) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shift<2>) -> !fir.ref<!fir.array<?x?xf32>>
881  return
882}
883
884// -----
885func.func @bad_array_declare_3(%arg0: !fir.ref<!fir.array<?x?xf32>>) {
886  %c1 = arith.constant 1 : index
887  %shape = fir.shape %c1 : (index) -> !fir.shape<1>
888  // expected-error@+1 {{'fir.declare' op has conflicting shape and base operand ranks}}
889  %0 = fir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<1>) -> !fir.ref<!fir.array<?x?xf32>>
890  return
891}
892
893// -----
894func.func @bad_array_declare_4(%arg0: !fir.ref<!fir.array<?x?xf32>>) {
895  %c1 = arith.constant 1 : index
896  %shape = fir.shape_shift %c1, %c1 : (index, index) -> !fir.shapeshift<1>
897  // expected-error@+1 {{'fir.declare' op has conflicting shape and base operand ranks}}
898  %0 = fir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<1>) -> !fir.ref<!fir.array<?x?xf32>>
899  return
900}
901
902// -----
903func.func @bad_array_declare_box(%arg0: !fir.box<!fir.array<?x?xf32>>) {
904  %c1 = arith.constant 1 : index
905  %shape = fir.shift %c1 : (index) -> !fir.shift<1>
906  // expected-error@+1 {{'fir.declare' op has conflicting shape and base operand ranks}}
907  %0 = fir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.box<!fir.array<?x?xf32>>, !fir.shift<1>) -> !fir.box<!fir.array<?x?xf32>>
908  return
909}
910
911// -----
912func.func @bad_array_declare_char_boxaddr(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) {
913  %c1 = arith.constant 1 : index
914  %c2 = arith.constant 2 : index
915  %shape = fir.shift %c1, %c2 : (index, index) -> !fir.shift<2>
916  // expected-error@+1 {{'fir.declare' op for box address must not have a shape operand}}
917  %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,?>>>>>
918  return
919}
920
921// -----
922func.func @bad_array_declare_unlimited_polymorphic_boxaddr(%arg0: !fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>) {
923  %c1 = arith.constant 1 : index
924  %c2 = arith.constant 2 : index
925  %shape = fir.shift %c1, %c2 : (index, index) -> !fir.shift<2>
926  // expected-error@+1 {{'fir.declare' op for box address must not have a shape operand}}
927  %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>>>>
928  return
929}
930
931// -----
932
933func.func @invalid_selector(%arg : !fir.box<!fir.ref<i32>>) -> i32 {
934  %0 = arith.constant 1 : i32
935  %2 = arith.constant 3 : i32
936  // expected-error@+1{{'fir.select_type' op selector must be polymorphic}}
937  fir.select_type %arg : !fir.box<!fir.ref<i32>> [
938    #fir.type_is<!fir.int<4>>,^bb1(%0:i32),
939    #fir.type_is<!fir.int<8>>,^bb2(%2:i32),
940    unit,^bb5 ]
941^bb1(%a : i32) :
942  return %a : i32
943^bb2(%b : i32) :
944  return %b : i32
945^bb5 :
946  %zero = arith.constant 0 : i32
947  return %zero : i32
948}
949
950// -----
951
952func.func @logical_to_fp(%arg0: !fir.logical<4>) -> f32 {
953  // expected-error@+1{{'fir.convert' op invalid type conversion}}
954  %0 = fir.convert %arg0 : (!fir.logical<4>) -> f32
955  return %0 : f32
956}
957
958// -----
959
960func.func @fp_to_logical(%arg0: f32) -> !fir.logical<4> {
961  // expected-error@+1{{'fir.convert' op invalid type conversion}}
962  %0 = fir.convert %arg0 : (f32) -> !fir.logical<4>
963  return %0 : !fir.logical<4>
964}
965
966// -----
967
968func.func @rec_to_rec(%arg0: !fir.type<t1{i:i32, f:f32}>) -> !fir.type<t2{f:f32, i:i32}> {
969  // expected-error@+1{{'fir.convert' op invalid type conversion}}
970  %0 = fir.convert %arg0 : (!fir.type<t1{i:i32, f:f32}>) -> !fir.type<t2{f:f32, i:i32}>
971  return %0 : !fir.type<t2{f:f32, i:i32}>
972}
973
974// -----
975
976func.func @bad_box_offset(%not_a_box : !fir.ref<i32>) {
977  // expected-error@+1{{'fir.box_offset' op box_ref operand must have !fir.ref<!fir.box<T>> type}}
978  %addr1 = fir.box_offset %not_a_box base_addr : (!fir.ref<i32>) -> !fir.llvm_ptr<!fir.ref<i32>>
979  return
980}
981
982// -----
983
984func.func @bad_box_offset(%no_addendum : !fir.ref<!fir.box<i32>>) {
985  // expected-error@+1{{'fir.box_offset' op can only address derived_type field of derived type or unlimited polymorphic fir.box}}
986  %addr1 = fir.box_offset %no_addendum derived_type : (!fir.ref<!fir.box<i32>>) -> !fir.llvm_ptr<!fir.tdesc<!fir.type<none>>>
987  return
988}
989
990// -----
991
992func.func @bad_rebox_assumed_rank_1(%arg0: !fir.ref<!fir.array<*:f32>> ) {
993  // expected-error@+1{{'fir.rebox_assumed_rank' op input must be a box or box address}}
994  %1 = fir.rebox_assumed_rank %arg0 lbs ones : (!fir.ref<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>>
995  return
996}
997
998// -----
999
1000func.func @bad_rebox_assumed_rank_2(%arg0: !fir.box<!fir.array<*:f32>> ) {
1001  // expected-error@+1{{'fir.rebox_assumed_rank' op result #0 must be box or class, but got '!fir.ref<!fir.box<!fir.array<*:f32>>>'}}
1002  %1 = fir.rebox_assumed_rank %arg0 lbs ones : (!fir.box<!fir.array<*:f32>>) -> !fir.ref<!fir.box<!fir.array<*:f32>>>
1003  return
1004}
1005
1006// -----
1007
1008func.func @bad_rebox_assumed_rank_3(%arg0: !fir.box<!fir.array<*:f32>> ) {
1009  // expected-error@+1{{'fir.rebox_assumed_rank' op input and output element types are incompatible}}
1010  %1 = fir.rebox_assumed_rank %arg0 lbs ones : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:i32>>
1011  return
1012}
1013
1014// -----
1015
1016func.func @bad_is_assumed_size(%arg0: !fir.ref<!fir.array<*:none>>) {
1017  // expected-error@+1{{op operand #0 must be box or class, but got '!fir.ref<!fir.array<*:none>>'}}
1018  %1 = fir.is_assumed_size %arg0 : (!fir.ref<!fir.array<*:none>>) -> i1
1019  return
1020}
1021