1 // RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics
3 func.func @elementsattr_non_tensor_type() -> () {
4 "foo"(){bar = dense<[4]> : i32} : () -> () // expected-error {{elements literal must be a shaped type}}
9 func.func @elementsattr_non_ranked() -> () {
10 "foo"(){bar = dense<[4]> : tensor<?xi32>} : () -> () // expected-error {{elements literal type must have static shape}}
15 func.func @elementsattr_shape_mismatch() -> () {
16 "foo"(){bar = dense<[4]> : tensor<5xi32>} : () -> () // expected-error {{inferred shape of elements literal ([1]) does not match type ([5])}}
21 func.func @elementsattr_invalid() -> () {
22 "foo"(){bar = dense<[4, [5]]> : tensor<2xi32>} : () -> () // expected-error {{tensor literal is invalid; ranks are not consistent between elements}}
27 func.func @elementsattr_badtoken() -> () {
28 "foo"(){bar = dense<[tf_opaque]> : tensor<1xi32>} : () -> () // expected-error {{expected element literal of primitive type}}
33 func.func @elementsattr_floattype1() -> () {
34 // expected-error@+1 {{expected integer elements, but parsed floating-point}}
35 "foo"(){bar = dense<[4.0]> : tensor<1xi32>} : () -> ()
40 func.func @elementsattr_floattype1() -> () {
41 // expected-error@+1 {{expected integer elements, but parsed floating-point}}
42 "foo"(){bar = dense<4.0> : tensor<i32>} : () -> ()
47 func.func @elementsattr_floattype2() -> () {
48 // expected-error@below {{unexpected decimal integer literal for a floating point value}}
49 // expected-note@below {{add a trailing dot to make the literal a float}}
50 "foo"(){bar = dense<[4]> : tensor<1xf32>} : () -> ()
55 func.func @elementsattr_toolarge1() -> () {
56 "foo"(){bar = dense<[777]> : tensor<1xi8>} : () -> () // expected-error {{integer constant out of range}}
61 // expected-error@+1 {{parsed zero elements, but type ('tensor<i64>') expected at least 1}}
62 #attr = dense<> : tensor<i64>
66 func.func @elementsattr_toolarge2() -> () {
67 "foo"(){bar = dense<[-777]> : tensor<1xi8>} : () -> () // expected-error {{integer constant out of range}}
72 "foo"(){bar = dense<[()]> : tensor<complex<i64>>} : () -> () // expected-error {{expected element literal of primitive type}}
76 "foo"(){bar = dense<[(10)]> : tensor<complex<i64>>} : () -> () // expected-error {{expected ',' between complex elements}}
80 "foo"(){bar = dense<[(10,)]> : tensor<complex<i64>>} : () -> () // expected-error {{expected element literal of primitive type}}
84 "foo"(){bar = dense<[(10,10]> : tensor<complex<i64>>} : () -> () // expected-error {{expected ')' after complex elements}}
89 // expected-error @+1 {{expected element literal of primitive type}}
90 "fooi64"(){bar = sparse<vector<1xi64>,[,[,1]
94 func.func @invalid_tensor_literal() {
95 // expected-error @+1 {{expected 1-d tensor for sparse element values}}
96 "foof16"(){bar = sparse<[[0, 0, 0]], [[-2.0]]> : vector<1x1x1xf16>} : () -> ()
100 func.func @invalid_tensor_literal() {
101 // expected-error @+1 {{expected element literal of primitive type}}
102 "fooi16"(){bar = sparse<[[1, 1, 0], [0, 1, 0], [0,, [[0, 0, 0]], [-2.0]> : tensor<2x2x2xi16>} : () -> ()
106 func.func @invalid_tensor_literal() {
107 // expected-error @+1 {{sparse index #0 is not contained within the value shape, with index=[1, 1], and type='tensor<1x1xi16>'}}
108 "fooi16"(){bar = sparse<1, 10> : tensor<1x1xi16>} : () -> ()
112 func.func @hexadecimal_float_leading_minus() {
113 // expected-error @+1 {{hexadecimal float literal should not have a leading minus}}
114 "foo"() {value = -0x7fff : f16} : () -> ()
119 func.func @hexadecimal_float_literal_overflow() {
120 // expected-error @+1 {{hexadecimal float constant out of range for type}}
121 "foo"() {value = 0xffffffff : f16} : () -> ()
126 func.func @decimal_float_literal() {
127 // expected-error @+2 {{unexpected decimal integer literal for a floating point value}}
128 // expected-note @+1 {{add a trailing dot to make the literal a float}}
129 "foo"() {value = 42 : f32} : () -> ()
134 func.func @float_in_int_tensor() {
135 // expected-error @+1 {{expected integer elements, but parsed floating-point}}
136 "foo"() {bar = dense<[42.0, 42]> : tensor<2xi32>} : () -> ()
141 func.func @float_in_bool_tensor() {
142 // expected-error@below {{expected integer elements, but parsed floating-point}}
143 "foo"() {bar = dense<[true, 42.0]> : tensor<2xi1>} : () -> ()
148 func.func @decimal_int_in_float_tensor() {
149 // expected-error@below {{unexpected decimal integer literal for a floating point value}}
150 // expected-note@below {{add a trailing dot to make the literal a float}}
151 "foo"() {bar = dense<[42, 42.0]> : tensor<2xf32>} : () -> ()
156 func.func @bool_in_float_tensor() {
157 // expected-error @+1 {{expected floating point literal}}
158 "foo"() {bar = dense<[42.0, true]> : tensor<2xf32>} : () -> ()
163 func.func @hexadecimal_float_leading_minus_in_tensor() {
164 // expected-error @+1 {{hexadecimal float literal should not have a leading minus}}
165 "foo"() {bar = dense<-0x7FFFFFFF> : tensor<2xf32>} : () -> ()
170 // Check that we report an error when a value could be parsed, but does not fit
171 // into the specified type.
172 func.func @hexadecimal_float_too_wide_for_type_in_tensor() {
173 // expected-error @+1 {{hexadecimal float constant out of range for type}}
174 "foo"() {bar = dense<0x7FF0000000000000> : tensor<2xf32>} : () -> ()
179 // Check that we report an error when a value is too wide to be parsed.
180 func.func @hexadecimal_float_too_wide_in_tensor() {
181 // expected-error @+1 {{hexadecimal float constant out of range for type}}
182 "foo"() {bar = dense<0x7FFFFFF0000000000000> : tensor<2xf32>} : () -> ()
187 func.func @integer_too_wide_in_tensor() {
188 // expected-error @+1 {{integer constant out of range for type}}
189 "foo"() {bar = dense<0xFFFFFFFFFFFFFF> : tensor<2xi16>} : () -> ()
194 func.func @bool_literal_in_non_bool_tensor() {
195 // expected-error @+1 {{expected i1 type for 'true' or 'false' values}}
196 "foo"() {bar = dense<true> : tensor<2xi16>} : () -> ()
201 func.func @negative_value_in_unsigned_int_attr() {
202 // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
203 "foo"() {bar = -5 : ui32} : () -> ()
208 func.func @negative_value_in_unsigned_vector_attr() {
209 // expected-error @+1 {{expected unsigned integer elements, but parsed negative value}}
210 "foo"() {bar = dense<[5, -5]> : vector<2xui32>} : () -> ()
215 func.func @large_bound() {
216 "test.out_of_range_attribute"() {
217 // expected-error @+1 {{integer constant out of range for attribute}}
225 func.func @large_bound() {
226 "test.out_of_range_attribute"() {
227 // expected-error @+1 {{integer constant out of range for attribute}}
235 func.func @large_bound() {
236 "test.out_of_range_attribute"() {
237 // expected-error @+1 {{integer constant out of range for attribute}}
245 func.func @large_bound() {
246 "test.out_of_range_attribute"() {
247 // expected-error @+1 {{integer constant out of range for attribute}}
255 func.func @large_bound() {
256 "test.out_of_range_attribute"() {
257 // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
265 func.func @large_bound() {
266 "test.out_of_range_attribute"() {
267 // expected-error @+1 {{integer constant out of range for attribute}}
275 func.func @large_bound() {
276 "test.out_of_range_attribute"() {
277 // expected-error @+1 {{integer constant out of range for attribute}}
285 func.func @large_bound() {
286 "test.out_of_range_attribute"() {
287 // expected-error @+1 {{integer constant out of range for attribute}}
295 func.func @large_bound() {
296 "test.out_of_range_attribute"() {
297 // expected-error @+1 {{integer constant out of range for attribute}}
305 func.func @large_bound() {
306 "test.out_of_range_attribute"() {
307 // expected-error @+1 {{integer constant out of range for attribute}}
315 func.func @large_bound() {
316 "test.out_of_range_attribute"() {
317 // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
325 func.func @large_bound() {
326 "test.out_of_range_attribute"() {
327 // expected-error @+1 {{integer constant out of range for attribute}}
335 func.func @large_bound() {
336 "test.out_of_range_attribute"() {
337 // expected-error @+1 {{integer constant out of range for attribute}}
338 attr = -2147483649 : i32
345 func.func @large_bound() {
346 "test.out_of_range_attribute"() {
347 // expected-error @+1 {{integer constant out of range for attribute}}
348 attr = 4294967296 : i32
355 func.func @large_bound() {
356 "test.out_of_range_attribute"() {
357 // expected-error @+1 {{integer constant out of range for attribute}}
358 attr = -2147483649 : si32
365 func.func @large_bound() {
366 "test.out_of_range_attribute"() {
367 // expected-error @+1 {{integer constant out of range for attribute}}
368 attr = 2147483648 : si32
375 func.func @large_bound() {
376 "test.out_of_range_attribute"() {
377 // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
385 func.func @large_bound() {
386 "test.out_of_range_attribute"() {
387 // expected-error @+1 {{integer constant out of range for attribute}}
388 attr = 4294967296 : ui32
395 func.func @large_bound() {
396 "test.out_of_range_attribute"() {
397 // expected-error @+1 {{integer constant out of range for attribute}}
398 attr = -9223372036854775809 : i64
405 func.func @large_bound() {
406 "test.out_of_range_attribute"() {
407 // expected-error @+1 {{integer constant out of range for attribute}}
408 attr = 18446744073709551616 : i64
415 func.func @large_bound() {
416 "test.out_of_range_attribute"() {
417 // expected-error @+1 {{integer constant out of range for attribute}}
418 attr = -9223372036854775809 : si64
425 func.func @large_bound() {
426 "test.out_of_range_attribute"() {
427 // expected-error @+1 {{integer constant out of range for attribute}}
428 attr = 9223372036854775808 : si64
435 func.func @large_bound() {
436 "test.out_of_range_attribute"() {
437 // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
445 func.func @large_bound() {
446 "test.out_of_range_attribute"() {
447 // expected-error @+1 {{integer constant out of range for attribute}}
448 attr = 18446744073709551616 : ui64
455 func.func @really_large_bound() {
456 "test.out_of_range_attribute"() {
457 // expected-error @+1 {{integer constant out of range for attribute}}
458 attr = 79228162514264337593543950336 : ui96
465 func.func @really_large_bound() {
466 "test.out_of_range_attribute"() {
467 // expected-error @+1 {{integer constant out of range for attribute}}
468 attr = 79228162514264337593543950336 : i96
475 func.func @really_large_bound() {
476 "test.out_of_range_attribute"() {
477 // expected-error @+1 {{integer constant out of range for attribute}}
478 attr = 39614081257132168796771975168 : si96
485 func.func @duplicate_dictionary_attr_key() {
486 // expected-error @+1 {{duplicate key 'a' in dictionary attribute}}
487 "foo.op"() {a, a} : () -> ()
492 // expected-error@+1 {{expected ',' or ']'}}
497 " // expected-error {{expected}}
502 // expected-error@+1 {{expected '"' in string literal}}
505 " // expected-error {{expected}}
509 // expected-error@+1 {{expected '<' after 'dense_resource'}}
510 #attr = dense_resource>
514 // expected-error@+1 {{expected '>'}}
515 #attr = dense_resource<resource
519 // expected-error@+1 {{expected ':'}}
520 #attr = dense_resource<resource>
524 // expected-error@+1 {{`dense_resource` expected a shaped type}}
525 #attr = dense_resource<resource> : i32
529 // expected-error@below {{expected '<' after 'array'}}
534 // expected-error@below {{expected integer or float type}}
535 #attr = array<vector<i32>>
539 // expected-error@below {{element type bitwidth must be a multiple of 8}}
544 // expected-error@below {{expected ':' after dense array type}}
549 // expected-error@below {{expected '>' to close an array attribute}}
554 // expected-error@below {{expected '[' after 'distinct'}}
559 // expected-error@below {{expected distinct ID}}
564 // expected-error@below {{expected an unsigned 64-bit integer}}
565 #attr = distinct[0xAAAABBBBEEEEFFFF1]
569 // expected-error@below {{expected ']' to close distinct ID}}
574 // expected-error@below {{expected '<' after distinct ID}}
579 // expected-error@below {{expected attribute}}
580 #attr = distinct[8]<attribute
584 // expected-error@below {{expected '>' to close distinct attribute}}
585 #attr = distinct[8]<@foo]
589 #attr = distinct[0]<42 : i32>
590 // expected-error@below {{referenced attribute does not match previous definition: 42 : i32}}
591 #attr1 = distinct[0]<43 : i32>