1// RUN: mlir-opt %s -split-input-file -allow-unregistered-dialect -verify-diagnostics | FileCheck %s
2
3//===----------------------------------------------------------------------===//
4// Test AnyAttrOf attributes
5//===----------------------------------------------------------------------===//
6
7func.func @any_attr_of_pass() {
8  "test.any_attr_of_i32_str"() {
9    // CHECK: attr = 3 : i32
10    attr = 3 : i32
11  } : () -> ()
12
13  "test.any_attr_of_i32_str"() {
14    // CHECK: attr = "string_data"
15    attr = "string_data"
16  } : () -> ()
17
18  return
19}
20
21// -----
22
23func.func @any_attr_of_fail() {
24  // expected-error @+1 {{'test.any_attr_of_i32_str' op attribute 'attr' failed to satisfy constraint: 32-bit signless integer attribute or string attribute}}
25  "test.any_attr_of_i32_str"() {
26    attr = 3 : i64
27  } : () -> ()
28
29  return
30}
31
32// -----
33
34//===----------------------------------------------------------------------===//
35// Test integer attributes
36//===----------------------------------------------------------------------===//
37
38func.func @int_attrs_pass() {
39  "test.int_attrs"() {
40    // CHECK: any_i32_attr = 5 : ui32
41    any_i32_attr = 5 : ui32,
42    // CHECK-SAME: index_attr = 8 : index
43    index_attr = 8 : index,
44    // CHECK-SAME: si32_attr = 7 : si32
45    si32_attr = 7 : si32,
46    // CHECK-SAME: ui32_attr = 6 : ui32
47    ui32_attr = 6 : ui32
48  } : () -> ()
49
50  "test.int_attrs"() {
51    // CHECK: any_i32_attr = 5 : si32
52    any_i32_attr = 5 : si32,
53    index_attr = 8 : index,
54    si32_attr = 7 : si32,
55    ui32_attr = 6 : ui32
56  } : () -> ()
57
58  "test.int_attrs"() {
59    // CHECK: any_i32_attr = 5 : i32
60    any_i32_attr = 5 : i32,
61    index_attr = 8 : index,
62    si32_attr = 7 : si32,
63    ui32_attr = 6 : ui32
64  } : () -> ()
65
66  return
67}
68
69// -----
70
71//===----------------------------------------------------------------------===//
72// Check that the maximum and minimum integer attribute values are
73// representable and preserved during a round-trip.
74//===----------------------------------------------------------------------===//
75
76func.func @int_attrs_pass() {
77  "test.in_range_attrs"() {
78    // CHECK: attr_00 = -128 : i8
79    attr_00 = -128 : i8,
80    // CHECK-SAME: attr_01 = 127 : i8
81    attr_01 = 127 : i8,
82    // CHECK-SAME: attr_02 = -128 : si8
83    attr_02 = -128 : si8,
84    // CHECK-SAME: attr_03 = 127 : si8
85    attr_03 = 127 : si8,
86    // CHECK-SAME: attr_04 = 255 : ui8
87    attr_04 = 255 : ui8,
88    // CHECK-SAME: attr_05 = -32768 : i16
89    attr_05 = -32768 : i16,
90    // CHECK-SAME: attr_06 = 32767 : i16
91    attr_06 = 32767 : i16,
92    // CHECK-SAME: attr_07 = -32768 : si16
93    attr_07 = -32768 : si16,
94    // CHECK-SAME: attr_08 = 32767 : si16
95    attr_08 = 32767 : si16,
96    // CHECK-SAME: attr_09 = 65535 : ui16
97    attr_09 = 65535 : ui16,
98    // CHECK-SAME: attr_10 = -2147483647 : i32
99    attr_10 = -2147483647 : i32,
100    // CHECK-SAME: attr_11 = 2147483646 : i32
101    attr_11 = 2147483646 : i32,
102    // CHECK-SAME: attr_12 = -2147483647 : si32
103    attr_12 = -2147483647 : si32,
104    // CHECK-SAME: attr_13 = 2147483646 : si32
105    attr_13 = 2147483646 : si32,
106    // CHECK-SAME: attr_14 = 4294967295 : ui32
107    attr_14 = 4294967295 : ui32,
108    // CHECK-SAME: attr_15 = -9223372036854775808 : i64
109    attr_15 = -9223372036854775808 : i64,
110    // CHECK-SAME: attr_16 = 9223372036854775807 : i64
111    attr_16 = 9223372036854775807 : i64,
112    // CHECK-SAME: attr_17 = -9223372036854775808 : si64
113    attr_17 = -9223372036854775808 : si64,
114    // CHECK-SAME: attr_18 = 9223372036854775807 : si64
115    attr_18 = 9223372036854775807 : si64,
116    // CHECK-SAME: attr_19 = 18446744073709551615 : ui64
117    attr_19 = 18446744073709551615 : ui64,
118    // CHECK-SAME: attr_20 = 1 : ui1
119    attr_20 = 1 : ui1,
120    // CHECK-SAME: attr_21 = -1 : si1
121    attr_21 = -1 : si1,
122    // CHECK-SAME: attr_22 = 79228162514264337593543950335 : ui96
123    attr_22 = 79228162514264337593543950335 : ui96,
124    // CHECK-SAME: attr_23 = -39614081257132168796771975168 : si96
125    attr_23 = -39614081257132168796771975168 : si96
126  } : () -> ()
127
128  return
129}
130
131// -----
132
133//===----------------------------------------------------------------------===//
134// Check that positive values larger than 2^n-1 for signless integers
135// are mapped to their negative signed counterpart. This behaviour is
136// undocumented in the language specification, but it is what the
137// parser currently does.
138//===----------------------------------------------------------------------===//
139
140func.func @int_attrs_pass() {
141  "test.i8_attr"() {
142    // CHECK: attr_00 = -1 : i8
143    attr_00 = 255 : i8,
144    // CHECK-SAME: attr_01 = -1 : i16
145    attr_01 = 65535 : i16,
146    // CHECK-SAME: attr_02 = -1 : i32
147    attr_02 = 4294967295 : i32,
148    // CHECK-SAME: attr_03 = -1 : i64
149    attr_03 = 18446744073709551615 : i64
150  } : () -> ()
151  return
152}
153
154// -----
155
156//===----------------------------------------------------------------------===//
157// Check that i0 is parsed and verified correctly. It can only have value 0.
158// We check it explicitly because there are various special cases for it that
159// are good to verify.
160//===----------------------------------------------------------------------===//
161
162func.func @int0_attrs_pass() {
163  "test.i0_attr"() {
164    // CHECK: attr_00 = 0 : i0
165    attr_00 = 0 : i0,
166    // CHECK: attr_01 = 0 : si0
167    attr_01 = 0 : si0,
168    // CHECK: attr_02 = 0 : ui0
169    attr_02 = 0 : ui0,
170    // CHECK: attr_03 = 0 : i0
171    attr_03 = 0x0000 : i0,
172    // CHECK: attr_04 = 0 : si0
173    attr_04 = 0x0000 : si0,
174    // CHECK: attr_05 = 0 : ui0
175    attr_05 = 0x0000 : ui0
176  } : () -> ()
177  return
178}
179
180// -----
181
182func.func @int0_attrs_negative_fail() {
183  "test.i0_attr"() {
184    // expected-error @+1 {{integer constant out of range for attribute}}
185    attr_00 = -1 : i0
186  } : () -> ()
187  return
188}
189
190// -----
191
192func.func @int0_attrs_positive_fail() {
193  "test.i0_attr"() {
194    // expected-error @+1 {{integer constant out of range for attribute}}
195    attr_00 = 1 : i0
196  } : () -> ()
197  return
198}
199
200// -----
201
202func.func @wrong_int_attrs_signedness_fail() {
203  // expected-error @+1 {{'si32_attr' failed to satisfy constraint: 32-bit signed integer attribute}}
204  "test.int_attrs"() {
205    any_i32_attr = 5 : i32,
206    index_attr = 8 : index,
207    si32_attr = 7 : ui32,
208    ui32_attr = 6 : ui32
209  } : () -> ()
210  return
211}
212
213// -----
214
215func.func @wrong_int_attrs_signedness_fail() {
216  // expected-error @+1 {{'ui32_attr' failed to satisfy constraint: 32-bit unsigned integer attribute}}
217  "test.int_attrs"() {
218    any_i32_attr = 5 : i32,
219    index_attr = 8 : index,
220    si32_attr = 7 : si32,
221    ui32_attr = 6 : si32
222  } : () -> ()
223  return
224}
225
226// -----
227
228func.func @wrong_int_attrs_type_fail() {
229  // expected-error @+1 {{'any_i32_attr' failed to satisfy constraint: 32-bit integer attribute}}
230  "test.int_attrs"() {
231    any_i32_attr = 5.0 : f32,
232    si32_attr = 7 : si32,
233    ui32_attr = 6 : ui32,
234    index_attr = 1 : index
235  } : () -> ()
236  return
237}
238
239// -----
240
241//===----------------------------------------------------------------------===//
242// Test Non-negative Int Attr
243//===----------------------------------------------------------------------===//
244
245func.func @non_negative_int_attr_pass() {
246  // CHECK: test.non_negative_int_attr
247  "test.non_negative_int_attr"() {i32attr = 5 : i32, i64attr = 10 : i64} : () -> ()
248  // CHECK: test.non_negative_int_attr
249  "test.non_negative_int_attr"() {i32attr = 0 : i32, i64attr = 0 : i64} : () -> ()
250  return
251}
252
253// -----
254
255func.func @negative_int_attr_fail() {
256  // expected-error @+1 {{'i32attr' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative}}
257  "test.non_negative_int_attr"() {i32attr = -5 : i32, i64attr = 10 : i64} : () -> ()
258  return
259}
260
261// -----
262
263func.func @negative_int_attr_fail() {
264  // expected-error @+1 {{'i64attr' failed to satisfy constraint: 64-bit signless integer attribute whose value is non-negative}}
265  "test.non_negative_int_attr"() {i32attr = 5 : i32, i64attr = -10 : i64} : () -> ()
266  return
267}
268
269// -----
270
271//===----------------------------------------------------------------------===//
272// Test Positive Int Attr
273//===----------------------------------------------------------------------===//
274
275func.func @positive_int_attr_pass() {
276  // CHECK: test.positive_int_attr
277  "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = 10 : i64} : () -> ()
278  return
279}
280
281// -----
282
283func.func @positive_int_attr_fail() {
284  // expected-error @+1 {{'i32attr' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive}}
285  "test.positive_int_attr"() {i32attr = 0 : i32, i64attr = 5: i64} : () -> ()
286  return
287}
288
289// -----
290
291func.func @positive_int_attr_fail() {
292  // expected-error @+1 {{'i64attr' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive}}
293  "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = 0: i64} : () -> ()
294  return
295}
296
297// -----
298
299func.func @positive_int_attr_fail() {
300  // expected-error @+1 {{'i32attr' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive}}
301  "test.positive_int_attr"() {i32attr = -10 : i32, i64attr = 5 : i64} : () -> ()
302  return
303}
304
305// -----
306
307func.func @positive_int_attr_fail() {
308  // expected-error @+1 {{'i64attr' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive}}
309  "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = -10 : i64} : () -> ()
310  return
311}
312
313// -----
314
315//===----------------------------------------------------------------------===//
316// Test TypeArrayAttr
317//===----------------------------------------------------------------------===//
318
319func.func @correct_type_array_attr_pass() {
320  // CHECK: test.type_array_attr
321  "test.type_array_attr"() {attr = [i32, f32]} : () -> ()
322  return
323}
324
325// -----
326
327func.func @non_type_in_type_array_attr_fail() {
328  // expected-error @+1 {{'attr' failed to satisfy constraint: type array attribute}}
329  "test.type_array_attr"() {attr = [i32, 5 : i64]} : () -> ()
330  return
331}
332
333// -----
334
335//===----------------------------------------------------------------------===//
336// Test StringAttr with custom type
337//===----------------------------------------------------------------------===//
338
339// CHECK-LABEL: func @string_attr_custom_type
340func.func @string_attr_custom_type() {
341  // CHECK: "string_data" : !foo.string
342  test.string_attr_with_type "string_data" : !foo.string
343  return
344}
345
346// -----
347
348//===----------------------------------------------------------------------===//
349// Test I32EnumAttr
350//===----------------------------------------------------------------------===//
351
352// CHECK-LABEL: func @allowed_cases_pass
353func.func @allowed_cases_pass() {
354  // CHECK: test.i32_enum_attr
355  %0 = "test.i32_enum_attr"() {attr = 5: i32} : () -> i32
356  // CHECK: test.i32_enum_attr
357  %1 = "test.i32_enum_attr"() {attr = 10: i32} : () -> i32
358  return
359}
360
361// -----
362
363func.func @disallowed_case7_fail() {
364  // expected-error @+1 {{allowed 32-bit signless integer cases: 5, 10}}
365  %0 = "test.i32_enum_attr"() {attr = 7: i32} : () -> i32
366  return
367}
368
369// -----
370
371func.func @disallowed_case7_fail() {
372  // expected-error @+1 {{allowed 32-bit signless integer cases: 5, 10}}
373  %0 = "test.i32_enum_attr"() {attr = 5: i64} : () -> i32
374  return
375}
376
377// -----
378
379//===----------------------------------------------------------------------===//
380// Test I64EnumAttr
381//===----------------------------------------------------------------------===//
382
383// CHECK-LABEL: func @allowed_cases_pass
384func.func @allowed_cases_pass() {
385  // CHECK: test.i64_enum_attr
386  %0 = "test.i64_enum_attr"() {attr = 5: i64} : () -> i32
387  // CHECK: test.i64_enum_attr
388  %1 = "test.i64_enum_attr"() {attr = 10: i64} : () -> i32
389  return
390}
391
392// -----
393
394func.func @disallowed_case7_fail() {
395  // expected-error @+1 {{allowed 64-bit signless integer cases: 5, 10}}
396  %0 = "test.i64_enum_attr"() {attr = 7: i64} : () -> i32
397  return
398}
399
400// -----
401
402func.func @disallowed_case7_fail() {
403  // expected-error @+1 {{allowed 64-bit signless integer cases: 5, 10}}
404  %0 = "test.i64_enum_attr"() {attr = 5: i32} : () -> i32
405  return
406}
407
408// -----
409
410//===----------------------------------------------------------------------===//
411// Test BitEnumAttr
412//===----------------------------------------------------------------------===//
413
414// CHECK-LABEL: func @allowed_cases_pass
415func.func @allowed_cases_pass() {
416  // CHECK: test.op_with_bit_enum <read,write>
417  "test.op_with_bit_enum"() {value = #test.bit_enum<read, write>} : () -> ()
418  // CHECK: test.op_with_bit_enum <read,execute>
419  test.op_with_bit_enum <read,execute>
420  return
421}
422
423// -----
424
425// CHECK-LABEL: func @allowed_cases_pass
426func.func @allowed_cases_pass() {
427  // CHECK: test.op_with_bit_enum_vbar <user|group>
428  "test.op_with_bit_enum_vbar"() {
429    value = #test.bit_enum_vbar<user|group>
430  } : () -> ()
431  // CHECK: test.op_with_bit_enum_vbar <user|group|other>
432  test.op_with_bit_enum_vbar <user | group | other>
433  return
434}
435
436// -----
437
438func.func @disallowed_case_sticky_fail() {
439  // expected-error@+2 {{expected test::TestBitEnum to be one of: read, write, execute}}
440  // expected-error@+1 {{failed to parse TestBitEnumAttr}}
441  "test.op_with_bit_enum"() {value = #test.bit_enum<sticky>} : () -> ()
442}
443
444// -----
445
446//===----------------------------------------------------------------------===//
447// Test FloatElementsAttr
448//===----------------------------------------------------------------------===//
449
450func.func @correct_type_pass() {
451  "test.float_elements_attr"() {
452    // CHECK: scalar_f32_attr = dense<5.000000e+00> : tensor<2xf32>
453    // CHECK: tensor_f64_attr = dense<6.000000e+00> : tensor<4x8xf64>
454    scalar_f32_attr = dense<5.0> : tensor<2xf32>,
455    tensor_f64_attr = dense<6.0> : tensor<4x8xf64>
456  } : () -> ()
457  return
458}
459
460// -----
461
462func.func @wrong_element_type_pass() {
463  // expected-error @+1 {{failed to satisfy constraint: 32-bit float elements attribute of shape [2]}}
464  "test.float_elements_attr"() {
465    scalar_f32_attr = dense<5.0> : tensor<2xf64>,
466    tensor_f64_attr = dense<6.0> : tensor<4x8xf64>
467  } : () -> ()
468  return
469}
470
471// -----
472
473func.func @correct_type_pass() {
474  // expected-error @+1 {{failed to satisfy constraint: 64-bit float elements attribute of shape [4, 8]}}
475  "test.float_elements_attr"() {
476    scalar_f32_attr = dense<5.0> : tensor<2xf32>,
477    tensor_f64_attr = dense<6.0> : tensor<4xf64>
478  } : () -> ()
479  return
480}
481
482// -----
483
484//===----------------------------------------------------------------------===//
485// Test StringElementsAttr
486//===----------------------------------------------------------------------===//
487
488func.func @simple_scalar_example() {
489  "test.string_elements_attr"() {
490    // CHECK: dense<"example">
491    scalar_string_attr = dense<"example"> : tensor<2x!unknown<"">>
492  } : () -> ()
493  return
494}
495
496// -----
497
498func.func @escape_string_example() {
499  "test.string_elements_attr"() {
500    // CHECK: dense<"new\0Aline">
501    scalar_string_attr = dense<"new\nline"> : tensor<2x!unknown<"">>
502  } : () -> ()
503  return
504}
505
506// -----
507
508func.func @simple_scalar_example() {
509  "test.string_elements_attr"() {
510    // CHECK: dense<["example1", "example2"]>
511    scalar_string_attr = dense<["example1", "example2"]> : tensor<2x!unknown<"">>
512  } : () -> ()
513  return
514}
515
516// -----
517
518//===----------------------------------------------------------------------===//
519// Test SymbolRefAttr
520//===----------------------------------------------------------------------===//
521
522func.func @fn() { return }
523
524// CHECK: test.symbol_ref_attr
525"test.symbol_ref_attr"() {symbol = @fn} : () -> ()
526
527// -----
528
529// expected-error @+1 {{referencing to a 'func::FuncOp' symbol}}
530"test.symbol_ref_attr"() {symbol = @foo} : () -> ()
531
532// -----
533
534//===----------------------------------------------------------------------===//
535// Test IntElementsAttr
536//===----------------------------------------------------------------------===//
537
538func.func @correct_int_elements_attr_pass() {
539  "test.int_elements_attr"() {
540    // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xui32>,
541    any_i32_attr = dense<5> : tensor<1x2x3x4xui32>,
542    i32_attr = dense<5> : tensor<6xi32>
543  } : () -> ()
544
545  "test.int_elements_attr"() {
546    // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xsi32>,
547    any_i32_attr = dense<5> : tensor<1x2x3x4xsi32>,
548    i32_attr = dense<5> : tensor<6xi32>
549  } : () -> ()
550
551  "test.int_elements_attr"() {
552    // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xi32>,
553    any_i32_attr = dense<5> : tensor<1x2x3x4xi32>,
554    i32_attr = dense<5> : tensor<6xi32>
555  } : () -> ()
556
557  "test.index_elements_attr"() {
558    // CHECK: any_index_attr = dense<5> : tensor<1x2x3x4xindex>,
559    any_index_attr = dense<5> : tensor<1x2x3x4xindex>,
560    index_attr = dense<5> : tensor<6xindex>
561  } : () -> ()
562
563  "test.hex_index_elements_attr"() {
564    // CHECK: hex_index_attr = dense<"0x00000C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000080C0000000000001A150000000000005078000000000000B659010000000000ECBC010000000000FEC5010000000000342902000000000046320200000000007C950200000000008E9E020000000000C401030000000000D60A0300000000000C6E0300000000001E7703000000000054DA03000000000066E30300000000009C46040000000000AE4F040000000000E4B2040000000000F6BB0400000000002C1F050000000000628100000000000098E40000000000000E0C00000000000020150000000000005678000000000000BC59010000000000F2BC01000000000004C60100000000003A290200000000004C320200000000008295020000000000949E020000000000CA01030000000000DC0A030000000000126E03000000000024770300000000005ADA0300000000006CE3030000000000A246040000000000B44F040000000000EAB2040000000000FCBB040000000000321F05000000000068810000000000009EE40000000000"> : tensor<23x5xindex>
565    hex_index_attr = dense<"0x00000C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000080C0000000000001A150000000000005078000000000000B659010000000000ECBC010000000000FEC5010000000000342902000000000046320200000000007C950200000000008E9E020000000000C401030000000000D60A0300000000000C6E0300000000001E7703000000000054DA03000000000066E30300000000009C46040000000000AE4F040000000000E4B2040000000000F6BB0400000000002C1F050000000000628100000000000098E40000000000000E0C00000000000020150000000000005678000000000000BC59010000000000F2BC01000000000004C60100000000003A290200000000004C320200000000008295020000000000949E020000000000CA01030000000000DC0A030000000000126E03000000000024770300000000005ADA0300000000006CE3030000000000A246040000000000B44F040000000000EAB2040000000000FCBB040000000000321F05000000000068810000000000009EE40000000000"> : tensor<23x5xindex>
566  } : () -> ()
567
568  return
569}
570
571// -----
572
573func.func @wrong_int_elements_attr_type_fail() {
574  // expected-error @+1 {{'any_i32_attr' failed to satisfy constraint: 32-bit integer elements attribute}}
575  "test.int_elements_attr"() {
576    any_i32_attr = dense<5.0> : tensor<1x2x3x4xf32>,
577    i32_attr = dense<5> : tensor<6xi32>
578  } : () -> ()
579  return
580}
581
582// -----
583
584func.func @wrong_int_elements_attr_signedness_fail() {
585  // expected-error @+1 {{'i32_attr' failed to satisfy constraint: 32-bit signless integer elements attribute}}
586  "test.int_elements_attr"() {
587    any_i32_attr = dense<5> : tensor<1x2x3x4xi32>,
588    i32_attr = dense<5> : tensor<6xsi32>
589  } : () -> ()
590  return
591}
592
593// -----
594
595//===----------------------------------------------------------------------===//
596// Test Ranked IntElementsAttr
597//===----------------------------------------------------------------------===//
598
599func.func @correct_type_pass() {
600  "test.ranked_int_elements_attr"() {
601    // CHECK: matrix_i64_attr = dense<6> : tensor<4x8xi64>
602    // CHECK: vector_i32_attr = dense<5> : tensor<2xi32>
603    matrix_i64_attr = dense<6> : tensor<4x8xi64>,
604    vector_i32_attr = dense<5> : tensor<2xi32>
605  } : () -> ()
606  return
607}
608
609// -----
610
611func.func @wrong_element_type_fail() {
612  // expected-error @+1 {{failed to satisfy constraint: 32-bit signless int elements attribute of shape [2]}}
613  "test.ranked_int_elements_attr"() {
614    matrix_i64_attr = dense<6> : tensor<4x8xi64>,
615    vector_i32_attr = dense<5> : tensor<2xi64>
616  } : () -> ()
617  return
618}
619
620// -----
621
622func.func @wrong_shape_fail() {
623  // expected-error @+1 {{failed to satisfy constraint: 64-bit signless int elements attribute of shape [4, 8]}}
624  "test.ranked_int_elements_attr"() {
625    matrix_i64_attr = dense<6> : tensor<4xi64>,
626    vector_i32_attr = dense<5> : tensor<2xi32>
627  } : () -> ()
628  return
629}
630
631// -----
632
633func.func @wrong_shape_fail() {
634  // expected-error @+1 {{failed to satisfy constraint: 32-bit signless int elements attribute of shape [2]}}
635  "test.ranked_int_elements_attr"() {
636    matrix_i64_attr = dense<6> : tensor<4x8xi64>,
637    vector_i32_attr = dense<5> : tensor<i32>
638  } : () -> ()
639  return
640}
641
642//===----------------------------------------------------------------------===//
643// Test StructAttr
644//===----------------------------------------------------------------------===//
645
646// -----
647
648func.func @missing_fields() {
649  // expected-error @+1 {{failed to satisfy constraint: DictionaryAttr with field(s): 'some_field', 'some_other_field' (each field having its own constraints)}}
650  "test.struct_attr"() {the_struct_attr = {}} : () -> ()
651  return
652}
653
654// -----
655
656func.func @erroneous_fields() {
657  // expected-error @+1 {{failed to satisfy constraint: DictionaryAttr with field(s): 'some_field', 'some_other_field' (each field having its own constraints)}}
658  "test.struct_attr"() {the_struct_attr = {some_field = 1 : i8, some_other_field = 1}} : () -> ()
659  return
660}
661
662// -----
663
664// expected-error @+1 {{invalid dialect namespace '"string with space"'}}
665#invalid_dialect = opaque<"string with space", "0xDEADBEEF"> : tensor<100xi32>
666