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@+1 {{expected floating-point elements, but parsed integer}}
49 "foo"(){bar = dense<[4]> : tensor<1xf32>} : () -> ()
54 func.func @elementsattr_toolarge1() -> () {
55 "foo"(){bar = dense<[777]> : tensor<1xi8>} : () -> () // expected-error {{integer constant out of range}}
60 // expected-error@+1 {{parsed zero elements, but type ('tensor<i64>') expected at least 1}}
61 #attr = dense<> : tensor<i64>
65 func.func @elementsattr_toolarge2() -> () {
66 "foo"(){bar = dense<[-777]> : tensor<1xi8>} : () -> () // expected-error {{integer constant out of range}}
71 "foo"(){bar = dense<[()]> : tensor<complex<i64>>} : () -> () // expected-error {{expected element literal of primitive type}}
75 "foo"(){bar = dense<[(10)]> : tensor<complex<i64>>} : () -> () // expected-error {{expected ',' between complex elements}}
79 "foo"(){bar = dense<[(10,)]> : tensor<complex<i64>>} : () -> () // expected-error {{expected element literal of primitive type}}
83 "foo"(){bar = dense<[(10,10]> : tensor<complex<i64>>} : () -> () // expected-error {{expected ')' after complex elements}}
88 // expected-error @+1 {{expected element literal of primitive type}}
89 "fooi64"(){bar = sparse<vector<1xi64>,[,[,1]
93 func.func @invalid_tensor_literal() {
94 // expected-error @+1 {{expected 1-d tensor for sparse element values}}
95 "foof16"(){bar = sparse<[[0, 0, 0]], [[-2.0]]> : vector<1x1x1xf16>} : () -> ()
99 func.func @invalid_tensor_literal() {
100 // expected-error @+1 {{expected element literal of primitive type}}
101 "fooi16"(){bar = sparse<[[1, 1, 0], [0, 1, 0], [0,, [[0, 0, 0]], [-2.0]> : tensor<2x2x2xi16>} : () -> ()
105 func.func @invalid_tensor_literal() {
106 // expected-error @+1 {{sparse index #0 is not contained within the value shape, with index=[1, 1], and type='tensor<1x1xi16>'}}
107 "fooi16"(){bar = sparse<1, 10> : tensor<1x1xi16>} : () -> ()
111 func.func @hexadecimal_float_leading_minus() {
112 // expected-error @+1 {{hexadecimal float literal should not have a leading minus}}
113 "foo"() {value = -0x7fff : f16} : () -> ()
118 func.func @hexadecimal_float_literal_overflow() {
119 // expected-error @+1 {{hexadecimal float constant out of range for type}}
120 "foo"() {value = 0xffffffff : f16} : () -> ()
125 func.func @decimal_float_literal() {
126 // expected-error @+2 {{unexpected decimal integer literal for a floating point value}}
127 // expected-note @+1 {{add a trailing dot to make the literal a float}}
128 "foo"() {value = 42 : f32} : () -> ()
133 func.func @float_in_int_tensor() {
134 // expected-error @+1 {{expected integer elements, but parsed floating-point}}
135 "foo"() {bar = dense<[42.0, 42]> : tensor<2xi32>} : () -> ()
140 func.func @float_in_bool_tensor() {
141 // expected-error @+1 {{expected integer elements, but parsed floating-point}}
142 "foo"() {bar = dense<[true, 42.0]> : tensor<2xi1>} : () -> ()
147 func.func @decimal_int_in_float_tensor() {
148 // expected-error @+1 {{expected floating-point elements, but parsed integer}}
149 "foo"() {bar = dense<[42, 42.0]> : tensor<2xf32>} : () -> ()
154 func.func @bool_in_float_tensor() {
155 // expected-error @+1 {{expected floating-point elements, but parsed integer}}
156 "foo"() {bar = dense<[42.0, true]> : tensor<2xf32>} : () -> ()
161 func.func @hexadecimal_float_leading_minus_in_tensor() {
162 // expected-error @+1 {{hexadecimal float literal should not have a leading minus}}
163 "foo"() {bar = dense<-0x7FFFFFFF> : tensor<2xf32>} : () -> ()
168 // Check that we report an error when a value could be parsed, but does not fit
169 // into the specified type.
170 func.func @hexadecimal_float_too_wide_for_type_in_tensor() {
171 // expected-error @+1 {{hexadecimal float constant out of range for type}}
172 "foo"() {bar = dense<0x7FF0000000000000> : tensor<2xf32>} : () -> ()
177 // Check that we report an error when a value is too wide to be parsed.
178 func.func @hexadecimal_float_too_wide_in_tensor() {
179 // expected-error @+1 {{hexadecimal float constant out of range for type}}
180 "foo"() {bar = dense<0x7FFFFFF0000000000000> : tensor<2xf32>} : () -> ()
185 func.func @integer_too_wide_in_tensor() {
186 // expected-error @+1 {{integer constant out of range for type}}
187 "foo"() {bar = dense<0xFFFFFFFFFFFFFF> : tensor<2xi16>} : () -> ()
192 func.func @bool_literal_in_non_bool_tensor() {
193 // expected-error @+1 {{expected i1 type for 'true' or 'false' values}}
194 "foo"() {bar = dense<true> : tensor<2xi16>} : () -> ()
199 func.func @negative_value_in_unsigned_int_attr() {
200 // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
201 "foo"() {bar = -5 : ui32} : () -> ()
206 func.func @negative_value_in_unsigned_vector_attr() {
207 // expected-error @+1 {{expected unsigned integer elements, but parsed negative value}}
208 "foo"() {bar = dense<[5, -5]> : vector<2xui32>} : () -> ()
213 func.func @large_bound() {
214 "test.out_of_range_attribute"() {
215 // expected-error @+1 {{integer constant out of range for attribute}}
223 func.func @large_bound() {
224 "test.out_of_range_attribute"() {
225 // expected-error @+1 {{integer constant out of range for attribute}}
233 func.func @large_bound() {
234 "test.out_of_range_attribute"() {
235 // expected-error @+1 {{integer constant out of range for attribute}}
243 func.func @large_bound() {
244 "test.out_of_range_attribute"() {
245 // expected-error @+1 {{integer constant out of range for attribute}}
253 func.func @large_bound() {
254 "test.out_of_range_attribute"() {
255 // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
263 func.func @large_bound() {
264 "test.out_of_range_attribute"() {
265 // expected-error @+1 {{integer constant out of range for attribute}}
273 func.func @large_bound() {
274 "test.out_of_range_attribute"() {
275 // expected-error @+1 {{integer constant out of range for attribute}}
283 func.func @large_bound() {
284 "test.out_of_range_attribute"() {
285 // expected-error @+1 {{integer constant out of range for attribute}}
293 func.func @large_bound() {
294 "test.out_of_range_attribute"() {
295 // expected-error @+1 {{integer constant out of range for attribute}}
303 func.func @large_bound() {
304 "test.out_of_range_attribute"() {
305 // expected-error @+1 {{integer constant out of range for attribute}}
313 func.func @large_bound() {
314 "test.out_of_range_attribute"() {
315 // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
323 func.func @large_bound() {
324 "test.out_of_range_attribute"() {
325 // expected-error @+1 {{integer constant out of range for attribute}}
333 func.func @large_bound() {
334 "test.out_of_range_attribute"() {
335 // expected-error @+1 {{integer constant out of range for attribute}}
336 attr = -2147483649 : i32
343 func.func @large_bound() {
344 "test.out_of_range_attribute"() {
345 // expected-error @+1 {{integer constant out of range for attribute}}
346 attr = 4294967296 : i32
353 func.func @large_bound() {
354 "test.out_of_range_attribute"() {
355 // expected-error @+1 {{integer constant out of range for attribute}}
356 attr = -2147483649 : si32
363 func.func @large_bound() {
364 "test.out_of_range_attribute"() {
365 // expected-error @+1 {{integer constant out of range for attribute}}
366 attr = 2147483648 : si32
373 func.func @large_bound() {
374 "test.out_of_range_attribute"() {
375 // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
383 func.func @large_bound() {
384 "test.out_of_range_attribute"() {
385 // expected-error @+1 {{integer constant out of range for attribute}}
386 attr = 4294967296 : ui32
393 func.func @large_bound() {
394 "test.out_of_range_attribute"() {
395 // expected-error @+1 {{integer constant out of range for attribute}}
396 attr = -9223372036854775809 : i64
403 func.func @large_bound() {
404 "test.out_of_range_attribute"() {
405 // expected-error @+1 {{integer constant out of range for attribute}}
406 attr = 18446744073709551616 : i64
413 func.func @large_bound() {
414 "test.out_of_range_attribute"() {
415 // expected-error @+1 {{integer constant out of range for attribute}}
416 attr = -9223372036854775809 : si64
423 func.func @large_bound() {
424 "test.out_of_range_attribute"() {
425 // expected-error @+1 {{integer constant out of range for attribute}}
426 attr = 9223372036854775808 : si64
433 func.func @large_bound() {
434 "test.out_of_range_attribute"() {
435 // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
443 func.func @large_bound() {
444 "test.out_of_range_attribute"() {
445 // expected-error @+1 {{integer constant out of range for attribute}}
446 attr = 18446744073709551616 : ui64
453 func.func @really_large_bound() {
454 "test.out_of_range_attribute"() {
455 // expected-error @+1 {{integer constant out of range for attribute}}
456 attr = 79228162514264337593543950336 : ui96
463 func.func @really_large_bound() {
464 "test.out_of_range_attribute"() {
465 // expected-error @+1 {{integer constant out of range for attribute}}
466 attr = 79228162514264337593543950336 : i96
473 func.func @really_large_bound() {
474 "test.out_of_range_attribute"() {
475 // expected-error @+1 {{integer constant out of range for attribute}}
476 attr = 39614081257132168796771975168 : si96
483 func.func @duplicate_dictionary_attr_key() {
484 // expected-error @+1 {{duplicate key 'a' in dictionary attribute}}
485 "foo.op"() {a, a} : () -> ()
490 // expected-error@+1 {{expected ',' or ']'}}
495 " // expected-error {{expected}}
500 // expected-error@+1 {{expected '"' in string literal}}
503 " // expected-error {{expected}}
507 // expected-error@+1 {{expected '<' after 'dense_resource'}}
508 #attr = dense_resource>
512 // expected-error@+1 {{expected '>'}}
513 #attr = dense_resource<resource
517 // expected-error@+1 {{expected ':'}}
518 #attr = dense_resource<resource>
522 // expected-error@+1 {{`dense_resource` expected a shaped type}}
523 #attr = dense_resource<resource> : i32
527 // expected-error@below {{expected '<' after 'array'}}
532 // expected-error@below {{expected integer or float type}}
533 #attr = array<vector<i32>>
537 // expected-error@below {{element type bitwidth must be a multiple of 8}}
542 // expected-error@below {{expected ':' after dense array type}}
547 // expected-error@below {{expected '>' to close an array attribute}}
552 // expected-error@below {{expected '[' after 'distinct'}}
557 // expected-error@below {{expected distinct ID}}
562 // expected-error@below {{expected an unsigned 64-bit integer}}
563 #attr = distinct[0xAAAABBBBEEEEFFFF1]
567 // expected-error@below {{expected ']' to close distinct ID}}
572 // expected-error@below {{expected '<' after distinct ID}}
577 // expected-error@below {{expected attribute}}
578 #attr = distinct[8]<attribute
582 // expected-error@below {{expected '>' to close distinct attribute}}
583 #attr = distinct[8]<@foo]
587 #attr = distinct[0]<42 : i32>
588 // expected-error@below {{referenced attribute does not match previous definition: 42 : i32}}
589 #attr1 = distinct[0]<43 : i32>