[SLP]Fix PR104422: Wrong value truncation
[llvm-project.git] / mlir / test / IR / invalid-builtin-attributes.mlir
blob431c7b12b8f5fe7950db49de03204b2f9ae131dd
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}}
7 // -----
9 func.func @elementsattr_non_ranked() -> () {
10   "foo"(){bar = dense<[4]> : tensor<?xi32>} : () -> () // expected-error {{elements literal type must have static shape}}
13 // -----
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])}}
19 // -----
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}}
25 // -----
27 func.func @elementsattr_badtoken() -> () {
28   "foo"(){bar = dense<[tf_opaque]> : tensor<1xi32>} : () -> () // expected-error {{expected element literal of primitive type}}
31 // -----
33 func.func @elementsattr_floattype1() -> () {
34   // expected-error@+1 {{expected integer elements, but parsed floating-point}}
35   "foo"(){bar = dense<[4.0]> : tensor<1xi32>} : () -> ()
38 // -----
40 func.func @elementsattr_floattype1() -> () {
41   // expected-error@+1 {{expected integer elements, but parsed floating-point}}
42   "foo"(){bar = dense<4.0> : tensor<i32>} : () -> ()
45 // -----
47 func.func @elementsattr_floattype2() -> () {
48   // expected-error@+1 {{expected floating-point elements, but parsed integer}}
49   "foo"(){bar = dense<[4]> : tensor<1xf32>} : () -> ()
52 // -----
54 func.func @elementsattr_toolarge1() -> () {
55   "foo"(){bar = dense<[777]> : tensor<1xi8>} : () -> () // expected-error {{integer constant out of range}}
58 // -----
60 // expected-error@+1 {{parsed zero elements, but type ('tensor<i64>') expected at least 1}}
61 #attr = dense<> : tensor<i64>
63 // -----
65 func.func @elementsattr_toolarge2() -> () {
66   "foo"(){bar = dense<[-777]> : tensor<1xi8>} : () -> () // expected-error {{integer constant out of range}}
69 // -----
71 "foo"(){bar = dense<[()]> : tensor<complex<i64>>} : () -> () // expected-error {{expected element literal of primitive type}}
73 // -----
75 "foo"(){bar = dense<[(10)]> : tensor<complex<i64>>} : () -> () // expected-error {{expected ',' between complex elements}}
77 // -----
79 "foo"(){bar = dense<[(10,)]> : tensor<complex<i64>>} : () -> () // expected-error {{expected element literal of primitive type}}
81 // -----
83 "foo"(){bar = dense<[(10,10]> : tensor<complex<i64>>} : () -> () // expected-error {{expected ')' after complex elements}}
85 // -----
87 func.func @mi() {
88   // expected-error @+1 {{expected element literal of primitive type}}
89   "fooi64"(){bar = sparse<vector<1xi64>,[,[,1]
91 // -----
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>} : () -> ()
97 // -----
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>} : () -> ()
103 // -----
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>} : () -> ()
109 // -----
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} : () -> ()
116 // -----
118 func.func @hexadecimal_float_literal_overflow() {
119   // expected-error @+1 {{hexadecimal float constant out of range for type}}
120   "foo"() {value = 0xffffffff : f16} : () -> ()
123 // -----
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} : () -> ()
131 // -----
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>} : () -> ()
138 // -----
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>} : () -> ()
145 // -----
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>} : () -> ()
152 // -----
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>} : () -> ()
159 // -----
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>} : () -> ()
166 // -----
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>} : () -> ()
175 // -----
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>} : () -> ()
183 // -----
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>} : () -> ()
190 // -----
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>} : () -> ()
197 // -----
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} : () -> ()
204 // -----
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>} : () -> ()
211 // -----
213 func.func @large_bound() {
214   "test.out_of_range_attribute"() {
215     // expected-error @+1 {{integer constant out of range for attribute}}
216     attr = -129 : i8
217   } : () -> ()
218   return
221 // -----
223 func.func @large_bound() {
224   "test.out_of_range_attribute"() {
225     // expected-error @+1 {{integer constant out of range for attribute}}
226     attr = 256 : i8
227   } : () -> ()
228   return
231 // -----
233 func.func @large_bound() {
234   "test.out_of_range_attribute"() {
235     // expected-error @+1 {{integer constant out of range for attribute}}
236     attr = -129 : si8
237   } : () -> ()
238   return
241 // -----
243 func.func @large_bound() {
244   "test.out_of_range_attribute"() {
245     // expected-error @+1 {{integer constant out of range for attribute}}
246     attr = 129 : si8
247   } : () -> ()
248   return
251 // -----
253 func.func @large_bound() {
254   "test.out_of_range_attribute"() {
255     // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
256     attr = -1 : ui8
257   } : () -> ()
258   return
261 // -----
263 func.func @large_bound() {
264   "test.out_of_range_attribute"() {
265     // expected-error @+1 {{integer constant out of range for attribute}}
266     attr = 256 : ui8
267   } : () -> ()
268   return
271 // -----
273 func.func @large_bound() {
274   "test.out_of_range_attribute"() {
275     // expected-error @+1 {{integer constant out of range for attribute}}
276     attr = -32769 : i16
277   } : () -> ()
278   return
281 // -----
283 func.func @large_bound() {
284   "test.out_of_range_attribute"() {
285     // expected-error @+1 {{integer constant out of range for attribute}}
286     attr = 65536 : i16
287   } : () -> ()
288   return
291 // -----
293 func.func @large_bound() {
294   "test.out_of_range_attribute"() {
295     // expected-error @+1 {{integer constant out of range for attribute}}
296     attr = -32769 : si16
297   } : () -> ()
298   return
301 // -----
303 func.func @large_bound() {
304   "test.out_of_range_attribute"() {
305     // expected-error @+1 {{integer constant out of range for attribute}}
306     attr = 32768 : si16
307   } : () -> ()
308   return
311 // -----
313 func.func @large_bound() {
314   "test.out_of_range_attribute"() {
315     // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
316     attr = -1 : ui16
317   } : () -> ()
318   return
321 // -----
323 func.func @large_bound() {
324   "test.out_of_range_attribute"() {
325     // expected-error @+1 {{integer constant out of range for attribute}}
326     attr = 65536: ui16
327   } : () -> ()
328   return
331 // -----
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
337   } : () -> ()
338   return
341 // -----
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
347   } : () -> ()
348   return
351 // -----
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
357   } : () -> ()
358   return
361 // -----
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
367   } : () -> ()
368   return
371 // -----
373 func.func @large_bound() {
374   "test.out_of_range_attribute"() {
375     // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
376     attr = -1 : ui32
377   } : () -> ()
378   return
381 // -----
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
387   } : () -> ()
388   return
391 // -----
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
397   } : () -> ()
398   return
401 // -----
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
407   } : () -> ()
408   return
411 // -----
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
417   } : () -> ()
418   return
421 // -----
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
427   } : () -> ()
428   return
431 // -----
433 func.func @large_bound() {
434   "test.out_of_range_attribute"() {
435     // expected-error @+1 {{negative integer literal not valid for unsigned integer type}}
436     attr = -1 : ui64
437   } : () -> ()
438   return
441 // -----
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
447   } : () -> ()
448   return
451 // -----
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
457   } : () -> ()
458   return
461 // -----
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
467   } : () -> ()
468   return
471 // -----
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
477   } : () -> ()
478   return
481 // -----
483 func.func @duplicate_dictionary_attr_key() {
484   // expected-error @+1 {{duplicate key 'a' in dictionary attribute}}
485   "foo.op"() {a, a} : () -> ()
488 // -----
490 // expected-error@+1 {{expected ',' or ']'}}
491 "f"() { b = [@m:
493 // -----
495 "       // expected-error {{expected}}
498 // -----
500 // expected-error@+1 {{expected '"' in string literal}}
501 "J// -----
503 "       // expected-error {{expected}}
505 // -----
507 // expected-error@+1 {{expected '<' after 'dense_resource'}}
508 #attr = dense_resource>
510 // -----
512 // expected-error@+1 {{expected '>'}}
513 #attr = dense_resource<resource
515 // -----
517 // expected-error@+1 {{expected ':'}}
518 #attr = dense_resource<resource>
520 // -----
522 // expected-error@+1 {{`dense_resource` expected a shaped type}}
523 #attr = dense_resource<resource> : i32
525 // -----
527 // expected-error@below {{expected '<' after 'array'}}
528 #attr = array
530 // -----
532 // expected-error@below {{expected integer or float type}}
533 #attr = array<vector<i32>>
535 // -----
537 // expected-error@below {{element type bitwidth must be a multiple of 8}}
538 #attr = array<i7>
540 // -----
542 // expected-error@below {{expected ':' after dense array type}}
543 #attr = array<i8)
545 // -----
547 // expected-error@below {{expected '>' to close an array attribute}}
548 #attr = array<i8: 1)
550 // -----
552 // expected-error@below {{expected '[' after 'distinct'}}
553 #attr = distinct<
555 // -----
557 // expected-error@below {{expected distinct ID}}
558 #attr = distinct[i8
560 // -----
562 // expected-error@below {{expected an unsigned 64-bit integer}}
563 #attr = distinct[0xAAAABBBBEEEEFFFF1]
565 // -----
567 // expected-error@below {{expected ']' to close distinct ID}}
568 #attr = distinct[8)
570 // -----
572 // expected-error@below {{expected '<' after distinct ID}}
573 #attr = distinct[8](
575 // -----
577 // expected-error@below {{expected attribute}}
578 #attr = distinct[8]<attribute
580 // -----
582 // expected-error@below {{expected '>' to close distinct attribute}}
583 #attr = distinct[8]<@foo]
585 // -----
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>
591 // -----