1 // RUN: mlir-opt %s -split-input-file -allow-unregistered-dialect -verify-diagnostics | FileCheck %s
3 //===----------------------------------------------------------------------===//
4 // Test AnyAttrOf attributes
5 //===----------------------------------------------------------------------===//
7 func.func @any_attr_of_pass() {
8 "test.any_attr_of_i32_str"() {
9 // CHECK: attr = 3 : i32
13 "test.any_attr_of_i32_str"() {
14 // CHECK: attr = "string_data"
23 func.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"() {
34 //===----------------------------------------------------------------------===//
35 // Test float attributes
36 //===----------------------------------------------------------------------===//
38 func.func @float_attrs_pass() {
39 "test.float_attrs"() {
40 // CHECK: float_attr = 2.000000e+00 : f4E2M1FN
41 float_attr = 2. : f4E2M1FN
43 "test.float_attrs"() {
44 // CHECK: float_attr = 2.000000e+00 : f6E2M3FN
45 float_attr = 2. : f6E2M3FN
47 "test.float_attrs"() {
48 // CHECK: float_attr = 2.000000e+00 : f6E3M2FN
49 float_attr = 2. : f6E3M2FN
51 "test.float_attrs"() {
52 // CHECK: float_attr = 2.000000e+00 : f8E5M2
53 float_attr = 2. : f8E5M2
55 "test.float_attrs"() {
56 // CHECK: float_attr = 2.000000e+00 : f8E4M3
57 float_attr = 2. : f8E4M3
59 "test.float_attrs"() {
60 // CHECK: float_attr = 2.000000e+00 : f8E4M3FN
61 float_attr = 2. : f8E4M3FN
63 "test.float_attrs"() {
64 // CHECK: float_attr = 2.000000e+00 : f8E5M2FNUZ
65 float_attr = 2. : f8E5M2FNUZ
67 "test.float_attrs"() {
68 // CHECK: float_attr = 2.000000e+00 : f8E4M3FNUZ
69 float_attr = 2. : f8E4M3FNUZ
71 "test.float_attrs"() {
72 // CHECK: float_attr = 2.000000e+00 : f8E4M3B11FNUZ
73 float_attr = 2. : f8E4M3B11FNUZ
75 "test.float_attrs"() {
76 // CHECK: float_attr = 2.000000e+00 : f8E3M4
77 float_attr = 2. : f8E3M4
79 "test.float_attrs"() {
80 // CHECK: float_attr = 2.000000e+00 : f8E8M0FNU
81 float_attr = 2. : f8E8M0FNU
83 "test.float_attrs"() {
84 // CHECK: float_attr = 2.000000e+00 : f16
87 "test.float_attrs"() {
88 // CHECK: float_attr = 2.000000e+00 : bf16
89 float_attr = 2. : bf16
91 "test.float_attrs"() {
92 // CHECK: float_attr = 2.000000e+00 : tf32
93 float_attr = 2. : tf32
95 "test.float_attrs"() {
96 // CHECK: float_attr = 2.000000e+00 : f32
99 "test.float_attrs"() {
100 // CHECK: float_attr = 2.000000e+00 : f64
101 float_attr = 2. : f64
103 "test.float_attrs"() {
104 // CHECK: float_attr = 2.000000e+00 : f80
105 float_attr = 2. : f80
107 "test.float_attrs"() {
108 // CHECK: float_attr = 2.000000e+00 : f128
109 float_attr = 2. : f128
114 //===----------------------------------------------------------------------===//
115 // Test integer attributes
116 //===----------------------------------------------------------------------===//
118 func.func @int_attrs_pass() {
120 // CHECK: any_i32_attr = 5 : ui32
121 any_i32_attr = 5 : ui32,
122 // CHECK-SAME: index_attr = 8 : index
123 index_attr = 8 : index,
124 // CHECK-SAME: si32_attr = 7 : si32
125 si32_attr = 7 : si32,
126 // CHECK-SAME: ui32_attr = 6 : ui32
131 // CHECK: any_i32_attr = 5 : si32
132 any_i32_attr = 5 : si32,
133 index_attr = 8 : index,
134 si32_attr = 7 : si32,
139 // CHECK: any_i32_attr = 5 : i32
140 any_i32_attr = 5 : i32,
141 index_attr = 8 : index,
142 si32_attr = 7 : si32,
151 //===----------------------------------------------------------------------===//
152 // Check that the maximum and minimum integer attribute values are
153 // representable and preserved during a round-trip.
154 //===----------------------------------------------------------------------===//
156 func.func @int_attrs_pass() {
157 "test.in_range_attrs"() {
158 // CHECK: attr_00 = -128 : i8
160 // CHECK-SAME: attr_01 = 127 : i8
162 // CHECK-SAME: attr_02 = -128 : si8
163 attr_02 = -128 : si8,
164 // CHECK-SAME: attr_03 = 127 : si8
166 // CHECK-SAME: attr_04 = 255 : ui8
168 // CHECK-SAME: attr_05 = -32768 : i16
169 attr_05 = -32768 : i16,
170 // CHECK-SAME: attr_06 = 32767 : i16
171 attr_06 = 32767 : i16,
172 // CHECK-SAME: attr_07 = -32768 : si16
173 attr_07 = -32768 : si16,
174 // CHECK-SAME: attr_08 = 32767 : si16
175 attr_08 = 32767 : si16,
176 // CHECK-SAME: attr_09 = 65535 : ui16
177 attr_09 = 65535 : ui16,
178 // CHECK-SAME: attr_10 = -2147483647 : i32
179 attr_10 = -2147483647 : i32,
180 // CHECK-SAME: attr_11 = 2147483646 : i32
181 attr_11 = 2147483646 : i32,
182 // CHECK-SAME: attr_12 = -2147483647 : si32
183 attr_12 = -2147483647 : si32,
184 // CHECK-SAME: attr_13 = 2147483646 : si32
185 attr_13 = 2147483646 : si32,
186 // CHECK-SAME: attr_14 = 4294967295 : ui32
187 attr_14 = 4294967295 : ui32,
188 // CHECK-SAME: attr_15 = -9223372036854775808 : i64
189 attr_15 = -9223372036854775808 : i64,
190 // CHECK-SAME: attr_16 = 9223372036854775807 : i64
191 attr_16 = 9223372036854775807 : i64,
192 // CHECK-SAME: attr_17 = -9223372036854775808 : si64
193 attr_17 = -9223372036854775808 : si64,
194 // CHECK-SAME: attr_18 = 9223372036854775807 : si64
195 attr_18 = 9223372036854775807 : si64,
196 // CHECK-SAME: attr_19 = 18446744073709551615 : ui64
197 attr_19 = 18446744073709551615 : ui64,
198 // CHECK-SAME: attr_20 = 1 : ui1
200 // CHECK-SAME: attr_21 = -1 : si1
202 // CHECK-SAME: attr_22 = 79228162514264337593543950335 : ui96
203 attr_22 = 79228162514264337593543950335 : ui96,
204 // CHECK-SAME: attr_23 = -39614081257132168796771975168 : si96
205 attr_23 = -39614081257132168796771975168 : si96
213 //===----------------------------------------------------------------------===//
214 // Check that positive values larger than 2^n-1 for signless integers
215 // are mapped to their negative signed counterpart. This behaviour is
216 // undocumented in the language specification, but it is what the
217 // parser currently does.
218 //===----------------------------------------------------------------------===//
220 func.func @int_attrs_pass() {
222 // CHECK: attr_00 = -1 : i8
224 // CHECK-SAME: attr_01 = -1 : i16
225 attr_01 = 65535 : i16,
226 // CHECK-SAME: attr_02 = -1 : i32
227 attr_02 = 4294967295 : i32,
228 // CHECK-SAME: attr_03 = -1 : i64
229 attr_03 = 18446744073709551615 : i64
236 //===----------------------------------------------------------------------===//
237 // Check that i0 is parsed and verified correctly. It can only have value 0.
238 // We check it explicitly because there are various special cases for it that
239 // are good to verify.
240 //===----------------------------------------------------------------------===//
242 func.func @int0_attrs_pass() {
244 // CHECK: attr_00 = 0 : i0
246 // CHECK: attr_01 = 0 : si0
248 // CHECK: attr_02 = 0 : ui0
250 // CHECK: attr_03 = 0 : i0
251 attr_03 = 0x0000 : i0,
252 // CHECK: attr_04 = 0 : si0
253 attr_04 = 0x0000 : si0,
254 // CHECK: attr_05 = 0 : ui0
255 attr_05 = 0x0000 : ui0
262 func.func @int0_attrs_negative_fail() {
264 // expected-error @+1 {{integer constant out of range for attribute}}
272 func.func @int0_attrs_positive_fail() {
274 // expected-error @+1 {{integer constant out of range for attribute}}
282 func.func @wrong_int_attrs_signedness_fail() {
283 // expected-error @+1 {{'si32_attr' failed to satisfy constraint: 32-bit signed integer attribute}}
285 any_i32_attr = 5 : i32,
286 index_attr = 8 : index,
287 si32_attr = 7 : ui32,
295 func.func @wrong_int_attrs_signedness_fail() {
296 // expected-error @+1 {{'ui32_attr' failed to satisfy constraint: 32-bit unsigned integer attribute}}
298 any_i32_attr = 5 : i32,
299 index_attr = 8 : index,
300 si32_attr = 7 : si32,
308 func.func @wrong_int_attrs_type_fail() {
309 // expected-error @+1 {{'any_i32_attr' failed to satisfy constraint: 32-bit integer attribute}}
311 any_i32_attr = 5.0 : f32,
312 si32_attr = 7 : si32,
313 ui32_attr = 6 : ui32,
314 index_attr = 1 : index
321 //===----------------------------------------------------------------------===//
322 // Test Non-negative Int Attr
323 //===----------------------------------------------------------------------===//
325 func.func @non_negative_int_attr_pass() {
326 // CHECK: test.non_negative_int_attr
327 "test.non_negative_int_attr"() {i32attr = 5 : i32, i64attr = 10 : i64} : () -> ()
328 // CHECK: test.non_negative_int_attr
329 "test.non_negative_int_attr"() {i32attr = 0 : i32, i64attr = 0 : i64} : () -> ()
335 func.func @negative_int_attr_fail() {
336 // expected-error @+1 {{'i32attr' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative}}
337 "test.non_negative_int_attr"() {i32attr = -5 : i32, i64attr = 10 : i64} : () -> ()
343 func.func @negative_int_attr_fail() {
344 // expected-error @+1 {{'i64attr' failed to satisfy constraint: 64-bit signless integer attribute whose value is non-negative}}
345 "test.non_negative_int_attr"() {i32attr = 5 : i32, i64attr = -10 : i64} : () -> ()
351 //===----------------------------------------------------------------------===//
352 // Test Positive Int Attr
353 //===----------------------------------------------------------------------===//
355 func.func @positive_int_attr_pass() {
356 // CHECK: test.positive_int_attr
357 "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = 10 : i64} : () -> ()
363 func.func @positive_int_attr_fail() {
364 // expected-error @+1 {{'i32attr' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive}}
365 "test.positive_int_attr"() {i32attr = 0 : i32, i64attr = 5: i64} : () -> ()
371 func.func @positive_int_attr_fail() {
372 // expected-error @+1 {{'i64attr' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive}}
373 "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = 0: i64} : () -> ()
379 func.func @positive_int_attr_fail() {
380 // expected-error @+1 {{'i32attr' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive}}
381 "test.positive_int_attr"() {i32attr = -10 : i32, i64attr = 5 : i64} : () -> ()
387 func.func @positive_int_attr_fail() {
388 // expected-error @+1 {{'i64attr' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive}}
389 "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = -10 : i64} : () -> ()
395 //===----------------------------------------------------------------------===//
396 // Test TypeArrayAttr
397 //===----------------------------------------------------------------------===//
399 func.func @correct_type_array_attr_pass() {
400 // CHECK: test.type_array_attr
401 "test.type_array_attr"() {attr = [i32, f32]} : () -> ()
407 func.func @non_type_in_type_array_attr_fail() {
408 // expected-error @+1 {{'attr' failed to satisfy constraint: type array attribute}}
409 "test.type_array_attr"() {attr = [i32, 5 : i64]} : () -> ()
415 //===----------------------------------------------------------------------===//
416 // Test StringAttr with custom type
417 //===----------------------------------------------------------------------===//
419 // CHECK-LABEL: func @string_attr_custom_type
420 func.func @string_attr_custom_type() {
421 // CHECK: "string_data" : !foo.string
422 test.string_attr_with_type "string_data" : !foo.string
428 //===----------------------------------------------------------------------===//
430 //===----------------------------------------------------------------------===//
432 // CHECK-LABEL: func @allowed_cases_pass
433 func.func @allowed_cases_pass() {
434 // CHECK: test.i32_enum_attr
435 %0 = "test.i32_enum_attr"() {attr = 5: i32} : () -> i32
436 // CHECK: test.i32_enum_attr
437 %1 = "test.i32_enum_attr"() {attr = 10: i32} : () -> i32
443 func.func @disallowed_case7_fail() {
444 // expected-error @+1 {{allowed 32-bit signless integer cases: 5, 10}}
445 %0 = "test.i32_enum_attr"() {attr = 7: i32} : () -> i32
451 func.func @disallowed_case7_fail() {
452 // expected-error @+1 {{allowed 32-bit signless integer cases: 5, 10}}
453 %0 = "test.i32_enum_attr"() {attr = 5: i64} : () -> i32
459 //===----------------------------------------------------------------------===//
461 //===----------------------------------------------------------------------===//
463 // CHECK-LABEL: func @allowed_cases_pass
464 func.func @allowed_cases_pass() {
465 // CHECK: test.i64_enum_attr
466 %0 = "test.i64_enum_attr"() {attr = 5: i64} : () -> i32
467 // CHECK: test.i64_enum_attr
468 %1 = "test.i64_enum_attr"() {attr = 10: i64} : () -> i32
474 func.func @disallowed_case7_fail() {
475 // expected-error @+1 {{allowed 64-bit signless integer cases: 5, 10}}
476 %0 = "test.i64_enum_attr"() {attr = 7: i64} : () -> i32
482 func.func @disallowed_case7_fail() {
483 // expected-error @+1 {{allowed 64-bit signless integer cases: 5, 10}}
484 %0 = "test.i64_enum_attr"() {attr = 5: i32} : () -> i32
490 //===----------------------------------------------------------------------===//
492 //===----------------------------------------------------------------------===//
494 // CHECK-LABEL: func @allowed_cases_pass
495 func.func @allowed_cases_pass() {
496 // CHECK: test.op_with_bit_enum <read, write>
497 "test.op_with_bit_enum"() {value = #test.bit_enum<read, write>} : () -> ()
498 // CHECK: test.op_with_bit_enum <read, execute>
499 test.op_with_bit_enum <read,execute>
505 // CHECK-LABEL: func @allowed_cases_pass
506 func.func @allowed_cases_pass() {
507 // CHECK: test.op_with_bit_enum_vbar <user | group>
508 "test.op_with_bit_enum_vbar"() {
509 value = #test.bit_enum_vbar<user|group>
511 // CHECK: test.op_with_bit_enum_vbar <user | group | other>
512 test.op_with_bit_enum_vbar <user | group | other>
518 func.func @disallowed_case_sticky_fail() {
519 // expected-error@+2 {{expected test::TestBitEnum to be one of: read, write, execute}}
520 // expected-error@+1 {{failed to parse TestBitEnumAttr}}
521 "test.op_with_bit_enum"() {value = #test.bit_enum<sticky>} : () -> ()
526 //===----------------------------------------------------------------------===//
527 // Test FloatElementsAttr
528 //===----------------------------------------------------------------------===//
530 func.func @correct_type_pass() {
531 "test.float_elements_attr"() {
532 // CHECK: scalar_f32_attr = dense<5.000000e+00> : tensor<2xf32>
533 // CHECK: tensor_f64_attr = dense<6.000000e+00> : tensor<4x8xf64>
534 scalar_f32_attr = dense<5.0> : tensor<2xf32>,
535 tensor_f64_attr = dense<6.0> : tensor<4x8xf64>
542 func.func @wrong_element_type_pass() {
543 // expected-error @+1 {{failed to satisfy constraint: 32-bit float elements attribute of shape [2]}}
544 "test.float_elements_attr"() {
545 scalar_f32_attr = dense<5.0> : tensor<2xf64>,
546 tensor_f64_attr = dense<6.0> : tensor<4x8xf64>
553 func.func @correct_type_pass() {
554 // expected-error @+1 {{failed to satisfy constraint: 64-bit float elements attribute of shape [4, 8]}}
555 "test.float_elements_attr"() {
556 scalar_f32_attr = dense<5.0> : tensor<2xf32>,
557 tensor_f64_attr = dense<6.0> : tensor<4xf64>
564 func.func @tf32_elements_attr() {
565 // CHECK: "foo"() {attr = dense<4.000000e+00> : tensor<tf32>} : () -> ()
566 "foo"() {attr = dense<4.0> : tensor<tf32>} : () -> ()
572 //===----------------------------------------------------------------------===//
573 // Test StringElementsAttr
574 //===----------------------------------------------------------------------===//
576 func.func @simple_scalar_example() {
577 "test.string_elements_attr"() {
578 // CHECK: dense<"example">
579 scalar_string_attr = dense<"example"> : tensor<2x!unknown<"">>
586 func.func @escape_string_example() {
587 "test.string_elements_attr"() {
588 // CHECK: dense<"new\0Aline">
589 scalar_string_attr = dense<"new\nline"> : tensor<2x!unknown<"">>
596 func.func @simple_scalar_example() {
597 "test.string_elements_attr"() {
598 // CHECK: dense<["example1", "example2"]>
599 scalar_string_attr = dense<["example1", "example2"]> : tensor<2x!unknown<"">>
607 //===----------------------------------------------------------------------===//
608 // Test DenseArrayAttr
609 //===----------------------------------------------------------------------===//
611 // CHECK-LABEL: func @dense_array_attr
612 func.func @dense_array_attr() attributes {
613 // CHECK-SAME: emptyf32attr = array<f32>,
614 emptyf32attr = array<f32>,
615 // CHECK-SAME: emptyf64attr = array<f64>,
616 emptyf64attr = array<f64>,
617 // CHECK-SAME: emptyi16attr = array<i16>,
618 emptyi16attr = array<i16>,
619 // CHECK-SAME: emptyi1attr = array<i1>,
620 emptyi1attr = array<i1>,
621 // CHECK-SAME: emptyi32attr = array<i32>,
622 emptyi32attr = array<i32>,
623 // CHECK-SAME: emptyi64attr = array<i64>,
624 emptyi64attr = array<i64>,
625 // CHECK-SAME: emptyi8attr = array<i8>,
626 emptyi8attr = array<i8>,
627 // CHECK-SAME: f32attr = array<f32: 1.024000e+03, 4.530000e+02, -6.435000e+03>,
628 f32attr = array<f32: 1024., 453., -6435.>,
629 // CHECK-SAME: f64attr = array<f64: -1.420000e+02>,
630 f64attr = array<f64: -142.>,
631 // CHECK-SAME: i16attr = array<i16: 3, 5, -4, 10>,
632 i16attr = array<i16: 3, 5, -4, 10>,
633 // CHECK-SAME: i1attr = array<i1: true, false, true>,
634 i1attr = array<i1: true, false, true>,
635 // CHECK-SAME: i32attr = array<i32: 1024, 453, -6435>,
636 i32attr = array<i32: 1024, 453, -6435>,
637 // CHECK-SAME: i64attr = array<i64: -142>,
638 i64attr = array<i64: -142>,
639 // CHECK-SAME: i8attr = array<i8: 1, -2, 3>
640 i8attr = array<i8: 1, -2, 3>
642 // CHECK: test.dense_array_attr
643 test.dense_array_attr
644 // CHECK-SAME: i1attr = [true, false, true]
645 i1attr = [true, false, true]
646 // CHECK-SAME: i8attr = [1, -2, 3]
648 // CHECK-SAME: i16attr = [3, 5, -4, 10]
649 i16attr = [3, 5, -4, 10]
650 // CHECK-SAME: i32attr = [1024, 453, -6435]
651 i32attr = [1024, 453, -6435]
652 // CHECK-SAME: i64attr = [-142]
654 // CHECK-SAME: f32attr = [1.024000e+03, 4.530000e+02, -6.435000e+03]
655 f32attr = [1024., 453., -6435.]
656 // CHECK-SAME: f64attr = [-1.420000e+02]
658 // CHECK-SAME: emptyattr = []
661 // CHECK: array.sizes
662 // CHECK-SAME: i0 = array<i0: 0, 0>
663 // CHECK-SAME: ui0 = array<ui0: 0, 0>
664 // CHECK-SAME: si0 = array<si0: 0, 0>
665 // CHECK-SAME: i24 = array<i24: -42, 42, 8388607>
666 // CHECK-SAME: ui24 = array<ui24: 16777215>
667 // CHECK-SAME: si24 = array<si24: -8388608>
668 // CHECK-SAME: bf16 = array<bf16: 1.2{{[0-9]+}}e+00, 3.4{{[0-9]+}}e+00>
669 // CHECK-SAME: f16 = array<f16: 1.{{[0-9]+}}e+00, 3.{{[0-9]+}}e+00>
671 x0_i0 = array<i0: 0, 0>,
672 x1_ui0 = array<ui0: 0, 0>,
673 x2_si0 = array<si0: 0, 0>,
674 x3_i24 = array<i24: -42, 42, 8388607>,
675 x4_ui24 = array<ui24: 16777215>,
676 x5_si24 = array<si24: -8388608>,
677 x6_bf16 = array<bf16: 1.2, 3.4>,
678 x7_f16 = array<f16: 1., 3.>
686 func.func @test_invalid_bitwidth_type() {
687 // expected-error @below{{element type bitwidth must be a multiple of 8}}
688 "foo"() {tf32attr = array<tf32: 1024.0>} : () -> ()
694 func.func @testConfinedDenseArrayAttr() {
695 "test.confined_dense_array_attr"() {
696 i64attr = array<i64: 0, 2, 3>,
697 i32attr = array<i32: 1>,
698 emptyattr = array<i16>
705 func.func @testConfinedDenseArrayAttrDuplicateValues() {
706 // expected-error@+1{{'test.confined_dense_array_attr' op attribute 'i64attr' failed to satisfy constraint: i64 dense array attribute should be in increasing order}}
707 "test.confined_dense_array_attr"() {
708 emptyattr = array<i16>,
709 i32attr = array<i32: 1, 1>,
710 i64attr = array<i64: 0, 2, 2>
717 func.func @testConfinedDenseArrayAttrDecreasingOrder() {
718 // expected-error@+1{{'test.confined_dense_array_attr' op attribute 'i32attr' failed to satisfy constraint: i32 dense array attribute should be in non-decreasing order}}
719 "test.confined_dense_array_attr"() {
720 emptyattr = array<i16>,
721 i32attr = array<i32: 1, 0>,
722 i64attr = array<i64: 0, 2, 3>
729 func.func @testConfinedStrictlyPositiveDenseArrayAttr() {
730 "test.confined_strictly_positive_attr"() {
731 i8attr = array<i8: 2, 3>,
732 i16attr = array<i16: 20, 30>,
733 i32attr = array<i32: 1>,
734 i64attr = array<i64: 1, 2, 3>,
735 f32attr = array<f32: 1.1, 2.1>,
736 f64attr = array<f64: 2.1, 3.1>,
737 emptyattr = array<i16>
744 func.func @testConfinedStrictlyPositiveDenseArrayAttr() {
745 // expected-error@+1{{'test.confined_strictly_positive_attr' op attribute 'i64attr' failed to satisfy constraint: i64 dense array attribute whose value is positive}}
746 "test.confined_strictly_positive_attr"() {
747 i8attr = array<i8: 2, 3>,
748 i16attr = array<i16: 20, 30>,
749 i32attr = array<i32: 1>,
750 i64attr = array<i64: 0, 2, 3>,
751 f32attr = array<f32: 1.1, 2.1>,
752 f64attr = array<f64: 2.1, 3.1>,
753 emptyattr = array<i16>
760 func.func @testConfinedNonNegativeDenseArrayAttr() {
761 "test.confined_non_negative_attr"() {
762 i8attr = array<i8: 0, 3>,
763 i16attr = array<i16: 0, 30>,
764 i32attr = array<i32: 1>,
765 i64attr = array<i64: 1, 0, 3>,
766 f32attr = array<f32: 0.0, 2.1>,
767 f64attr = array<f64: 0.0, 3.1>,
768 emptyattr = array<i16>
775 func.func @testConfinedNonNegativeDenseArrayAttr() {
776 // expected-error@+1{{'test.confined_non_negative_attr' op attribute 'i64attr' failed to satisfy constraint: i64 dense array attribute whose value is non-negative}}
777 "test.confined_non_negative_attr"() {
778 i8attr = array<i8: 0, 3>,
779 i16attr = array<i16: 0, 30>,
780 i32attr = array<i32: 1>,
781 i64attr = array<i64: -1, 0, 3>,
782 f32attr = array<f32: 0.0, 2.1>,
783 f64attr = array<f64: 0.0, 3.1>,
784 emptyattr = array<i16>
791 //===----------------------------------------------------------------------===//
792 // Test SymbolRefAttr
793 //===----------------------------------------------------------------------===//
795 func.func @fn() { return }
797 // CHECK: test.symbol_ref_attr
798 "test.symbol_ref_attr"() {symbol = @fn} : () -> ()
802 //===----------------------------------------------------------------------===//
803 // Test IntElementsAttr
804 //===----------------------------------------------------------------------===//
806 func.func @correct_int_elements_attr_pass() {
807 "test.int_elements_attr"() {
808 // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xui32>,
809 any_i32_attr = dense<5> : tensor<1x2x3x4xui32>,
810 i32_attr = dense<5> : tensor<6xi32>
813 "test.int_elements_attr"() {
814 // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xsi32>,
815 any_i32_attr = dense<5> : tensor<1x2x3x4xsi32>,
816 i32_attr = dense<5> : tensor<6xi32>
819 "test.int_elements_attr"() {
820 // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xi32>,
821 any_i32_attr = dense<5> : tensor<1x2x3x4xi32>,
822 i32_attr = dense<5> : tensor<6xi32>
825 "test.index_elements_attr"() {
826 // CHECK: any_index_attr = dense<5> : tensor<1x2x3x4xindex>,
827 any_index_attr = dense<5> : tensor<1x2x3x4xindex>,
828 index_attr = dense<5> : tensor<6xindex>
831 "test.hex_index_elements_attr"() {
832 // CHECK: hex_index_attr = dense<"0x00000C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000080C0000000000001A150000000000005078000000000000B659010000000000ECBC010000000000FEC5010000000000342902000000000046320200000000007C950200000000008E9E020000000000C401030000000000D60A0300000000000C6E0300000000001E7703000000000054DA03000000000066E30300000000009C46040000000000AE4F040000000000E4B2040000000000F6BB0400000000002C1F050000000000628100000000000098E40000000000000E0C00000000000020150000000000005678000000000000BC59010000000000F2BC01000000000004C60100000000003A290200000000004C320200000000008295020000000000949E020000000000CA01030000000000DC0A030000000000126E03000000000024770300000000005ADA0300000000006CE3030000000000A246040000000000B44F040000000000EAB2040000000000FCBB040000000000321F05000000000068810000000000009EE40000000000"> : tensor<23x5xindex>
833 hex_index_attr = dense<"0x00000C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000080C0000000000001A150000000000005078000000000000B659010000000000ECBC010000000000FEC5010000000000342902000000000046320200000000007C950200000000008E9E020000000000C401030000000000D60A0300000000000C6E0300000000001E7703000000000054DA03000000000066E30300000000009C46040000000000AE4F040000000000E4B2040000000000F6BB0400000000002C1F050000000000628100000000000098E40000000000000E0C00000000000020150000000000005678000000000000BC59010000000000F2BC01000000000004C60100000000003A290200000000004C320200000000008295020000000000949E020000000000CA01030000000000DC0A030000000000126E03000000000024770300000000005ADA0300000000006CE3030000000000A246040000000000B44F040000000000EAB2040000000000FCBB040000000000321F05000000000068810000000000009EE40000000000"> : tensor<23x5xindex>
841 func.func @wrong_int_elements_attr_type_fail() {
842 // expected-error @+1 {{'any_i32_attr' failed to satisfy constraint: 32-bit integer elements attribute}}
843 "test.int_elements_attr"() {
844 any_i32_attr = dense<5.0> : tensor<1x2x3x4xf32>,
845 i32_attr = dense<5> : tensor<6xi32>
852 func.func @wrong_int_elements_attr_signedness_fail() {
853 // expected-error @+1 {{'i32_attr' failed to satisfy constraint: 32-bit signless integer elements attribute}}
854 "test.int_elements_attr"() {
855 any_i32_attr = dense<5> : tensor<1x2x3x4xi32>,
856 i32_attr = dense<5> : tensor<6xsi32>
863 //===----------------------------------------------------------------------===//
864 // Test Ranked IntElementsAttr
865 //===----------------------------------------------------------------------===//
867 func.func @correct_type_pass() {
868 "test.ranked_int_elements_attr"() {
869 // CHECK: matrix_i64_attr = dense<6> : tensor<4x8xi64>
870 // CHECK: vector_i32_attr = dense<5> : tensor<2xi32>
871 matrix_i64_attr = dense<6> : tensor<4x8xi64>,
872 vector_i32_attr = dense<5> : tensor<2xi32>
879 func.func @wrong_element_type_fail() {
880 // expected-error @+1 {{failed to satisfy constraint: 32-bit signless int elements attribute of shape [2]}}
881 "test.ranked_int_elements_attr"() {
882 matrix_i64_attr = dense<6> : tensor<4x8xi64>,
883 vector_i32_attr = dense<5> : tensor<2xi64>
890 func.func @wrong_shape_fail() {
891 // expected-error @+1 {{failed to satisfy constraint: 64-bit signless int elements attribute of shape [4, 8]}}
892 "test.ranked_int_elements_attr"() {
893 matrix_i64_attr = dense<6> : tensor<4xi64>,
894 vector_i32_attr = dense<5> : tensor<2xi32>
901 func.func @wrong_shape_fail() {
902 // expected-error @+1 {{failed to satisfy constraint: 32-bit signless int elements attribute of shape [2]}}
903 "test.ranked_int_elements_attr"() {
904 matrix_i64_attr = dense<6> : tensor<4x8xi64>,
905 vector_i32_attr = dense<5> : tensor<i32>
912 //===----------------------------------------------------------------------===//
913 // Test DefaultValuedAttr Printing
914 //===----------------------------------------------------------------------===//
916 // CHECK-LABEL: @default_value_printing
917 func.func @default_value_printing(%arg0 : i32) {
918 // The attribute SHOULD NOT be printed because it is equal to the default
919 // CHECK: test.default_value_print %arg0
920 "test.default_value_print"(%arg0) {"value_with_default" = 0 : i32} : (i32) -> ()
921 // The attribute SHOULD be printed because it is not equal to the default
922 // CHECK: test.default_value_print {value_with_default = 1 : i32} %arg0
923 "test.default_value_print"(%arg0) {"value_with_default" = 1 : i32} : (i32) -> ()
929 func.func @type_attr_of_fail() {
930 // expected-error @below {{failed to satisfy constraint: type attribute of 64-bit signless integer}}
931 test.type_attr_of i32