1 // RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics
3 // Check different error cases.
5 func.func @bad_branch() {
7 cf.br ^missing // expected-error {{reference to an undefined block}}
12 func.func @block_redef() {
15 ^bb42: // expected-error {{redefinition of block '^bb42'}}
21 func.func @no_terminator() { // expected-error {{empty block: expect at least a terminator}}
31 func.func @block_no_rparen() {
32 ^bb42 (%bb42 : i32: // expected-error {{expected ')'}}
38 func.func @block_arg_no_ssaid() {
39 ^bb42 (i32): // expected-error {{expected SSA operand}}
45 func.func @block_arg_no_type() {
46 ^bb42 (%0): // expected-error {{expected ':' and type for SSA operand}}
52 func.func @block_arg_no_close_paren() {
54 cf.br ^bb2( // expected-error {{expected ':'}}
60 func.func @block_first_has_predecessor() {
61 // expected-error@-1 {{entry block of region may not have predecessors}}
70 func.func @no_return() {
71 %x = arith.constant 0 : i32
72 %y = arith.constant 1 : i32 // expected-error {{block with no terminator}}
77 func.func @no_terminator() {
80 %x = arith.constant 0 : i32
81 %y = arith.constant 1 : i32 // expected-error {{block with no terminator}}
86 func.func @no_block_arg_enclosing_parens() {
87 ^bb %x: i32 : // expected-error {{expected ':' after block name}}
93 func.func @bad_op_type() {
95 "foo"() : i32 // expected-error {{expected function type}}
100 func.func @no_terminator() {
103 ""() : ()->() // expected-error {{empty operation name is invalid}}
109 func.func @non_operation() {
110 test.asd // expected-error {{custom op 'test.asd' is unknown}}
115 func.func @unknown_dialect_operation() {
116 // expected-error@below {{Dialect `foo' not found for custom op 'foo.asd'}}
117 // expected-note-re@below {{Registered dialects:{{.*}} test{{.*}}}}
123 func.func @non_operation() {
124 // expected-error@+1 {{custom op 'asd' is unknown (tried 'func.asd' as well)}}
132 %1 = "foo"() : (i32)->i64 // expected-error {{expected 0 operand types but had 1}}
140 %x = "xxx"(){index = 0} : ()->i32 // expected-note {{previously defined here}}
141 %x = "xxx"(){index = 0} : ()->i32 // expected-error {{redefinition of SSA value '%x'}}
149 %x = "xxx"(%y) : (i32)->i32 // expected-error {{use of undeclared SSA value}}
155 func.func @malformed_type(%a : intt) { // expected-error {{expected non-function type}}
160 func.func @argError() {
161 ^bb1(%a: i64): // expected-note {{previously defined here}}
163 ^bb2(%a: i64): // expected-error{{redefinition of SSA value '%a'}}
169 func.func @br_mismatch() {
171 %0:2 = "foo"() : () -> (i1, i17)
172 // expected-error @+1 {{branch has 2 operands for successor #0, but target block has 1}}
173 cf.br ^bb1(%0#1, %0#0 : i17, i1)
181 func.func @succ_arg_type_mismatch() {
183 %0 = "getBool"() : () -> i1
184 // expected-error @+1 {{type mismatch for bb argument #0 of successor #0}}
194 func.func @condbr_notbool() {
196 %a = "foo"() : () -> i32 // expected-note {{prior use here}}
197 cf.cond_br %a, ^bb0, ^bb0 // expected-error {{use of value '%a' expects different type than prior uses: 'i1' vs 'i32'}}
202 func.func @condbr_badtype() {
204 %c = "foo"() : () -> i1
205 %a = "foo"() : () -> i32
206 cf.cond_br %c, ^bb0(%a, %a : i32, ^bb0) // expected-error {{expected non-function type}}
211 func.func @condbr_a_bb_is_not_a_type() {
213 %c = "foo"() : () -> i1
214 %a = "foo"() : () -> i32
215 cf.cond_br %c, ^bb0(%a, %a : i32, i32), i32 // expected-error {{expected block name}}
220 func.func @successors_in_non_terminator(%a : i32, %b : i32) {
221 %c = "arith.addi"(%a, %b)[^bb1] : () -> () // expected-error {{successors in non-terminator}}
230 %x = "xxx"(%y) : (i32)->i32 // expected-error {{use of undeclared SSA value name}}
237 %x = "xxx"(%y) : (i32)->i32 // expected-error {{use of undeclared SSA value name}}
243 func.func @duplicate_induction_var() {
244 affine.for %i = 1 to 10 { // expected-note {{previously referenced here}}
245 affine.for %i = 1 to 10 { // expected-error {{region entry argument '%i' is already in use}}
253 func.func @name_scope_failure() {
254 affine.for %i = 1 to 10 {
256 "xxx"(%i) : (index)->() // expected-error {{use of undeclared SSA value name}}
262 func.func @dominance_failure() {
264 "foo"(%x) : (i32) -> () // expected-error {{operand #0 does not dominate this use}}
267 %x = "bar"() : () -> i32 // expected-note {{operand defined here (op in the same region)}}
273 func.func @dominance_failure() {
275 "foo"(%x) : (i32) -> () // expected-error {{operand #0 does not dominate this use}}
276 %x = "bar"() : () -> i32 // expected-note {{operand defined here (op in the same block)}}
284 func.func @dominance_failure() {
286 "foo"(%x) : (i32) -> () // expected-error {{operand #0 does not dominate this use}}
288 %x = "bar"() : () -> i32 // expected-note {{operand defined here (op in a parent region)}}
294 func.func @dominance_failure() { // expected-note {{operand defined as a block argument (block #1 in the same region)}}
296 cf.br ^bb1(%x : i32) // expected-error {{operand #0 does not dominate this use}}
303 func.func @dominance_failure() { // expected-note {{operand defined as a block argument (block #1 in a parent region)}}
306 "foo"(%x) : (i32) -> () // expected-error {{operand #0 does not dominate this use}}
315 // expected-error@+1 {{expected three consecutive dots for an ellipsis}}
316 func.func @malformed_ellipsis_one(.)
320 // expected-error@+1 {{expected three consecutive dots for an ellipsis}}
321 func.func @malformed_ellipsis_two(..)
325 func.func private @redef() // expected-note {{see existing symbol definition here}}
326 func.func private @redef() // expected-error {{redefinition of symbol named 'redef'}}
330 func.func @calls(%arg0: i32) {
331 // expected-error@+1 {{expected non-function type}}
332 %z = "casdasda"(%x) : (ppop32) -> i32
337 // expected-error@+1 {{expected SSA operand}}
342 // This used to crash the parser, but should just error out by interpreting
343 // `tensor` as operator rather than as a type.
346 %18 = arith.cmpi slt, %idx, %idx : index
347 tensor<42 x index // expected-error {{custom op 'tensor' is unknown (tried 'func.tensor' as well)}}
353 func.func @f(%m : memref<?x?xf32>) {
354 affine.for %i0 = 0 to 42 {
355 // expected-note@+1 {{previously referenced here}}
356 %x = memref.load %m[%i0, %i1] : memref<?x?xf32>
358 // expected-error@+1 {{region entry argument '%i1' is already in use}}
359 affine.for %i1 = 0 to 42 {
366 func.func @dialect_type_empty_namespace(!<"">) -> () { // expected-error {{invalid type identifier}}
372 func.func @dialect_type_missing_greater(!foo<) -> () { // expected-error {{unbalanced '<' character in pretty dialect name}}
377 func.func @type_alias_unknown(!unknown_alias) -> () { // expected-error {{undefined symbol alias id 'unknown_alias'}}
383 // expected-error @+1 {{type names with a '.' are reserved for dialect-defined names}}
388 !missing_eq_alias i32 // expected-error {{expected '=' in type alias definition}}
392 !missing_type_alias = // expected-error {{expected non-function type}}
397 !redef_alias = i32 // expected-error {{redefinition of type alias id 'redef_alias'}}
401 func.func @invalid_nested_dominance() {
402 "test.ssacfg_region"() ({
403 // expected-error @+1 {{operand #0 does not dominate this use}}
404 "foo.use" (%1) : (i32) -> ()
408 // expected-note @+1 {{operand defined here}}
409 %1 = arith.constant 0 : i32
410 "foo.yield" () : () -> ()
417 // expected-error @+1 {{unbalanced '<' character in pretty dialect name}}
418 func.func @invalid_unknown_type_dialect_name() -> !invalid.dialect<!x@#]!@#>
422 // expected-error @+1 {{expected '<' in tuple type}}
423 func.func @invalid_tuple_missing_less(tuple i32>)
427 // expected-error @+1 {{expected '>' in tuple type}}
428 func.func @invalid_tuple_missing_greater(tuple<i32)
432 // Should not crash because of deletion order here.
433 func.func @invalid_region_dominance() {
434 "foo.use" (%1) : (i32) -> ()
436 %1 = arith.constant 0 : i32 // This value is used outside of the region.
437 "foo.yield" () : () -> ()
439 // expected-error @+1 {{expected operation name in quotes}}
440 %2 = arith.constant 1 i32 // Syntax error causes region deletion.
447 // Should not crash because of deletion order here.
448 func.func @invalid_region_block() {
449 "foo.branch"()[^bb2] : () -> () // Attempt to jump into the region.
454 "foo.yield"() : () -> ()
456 // expected-error @+1 {{expected operation name in quotes}}
457 %2 = arith.constant 1 i32 // Syntax error causes region deletion.
463 // Should not crash because of deletion order here.
464 func.func @invalid_region_dominance() {
465 "foo.use" (%1) : (i32) -> ()
468 %1 = arith.constant 0 : i32 // This value is used outside of the region.
469 "foo.yield" () : () -> ()
472 // expected-error @+1 {{expected operation name in quotes}}
473 %2 = arith.constant 1 i32 // Syntax error causes region deletion.
480 func.func @unfinished_region_list() {
481 // expected-error@+1 {{expected ')' to end region list}}
482 "region"() ({},{},{} : () -> ()
487 func.func @multi_result_missing_count() {
488 // expected-error@+1 {{expected integer number of results}}
489 %0: = "foo" () : () -> (i32, i32)
495 func.func @multi_result_zero_count() {
496 // expected-error@+1 {{expected named operation to have at least 1 result}}
497 %0:0 = "foo" () : () -> (i32, i32)
503 func.func @multi_result_invalid_identifier() {
504 // expected-error@+1 {{expected valid ssa identifier}}
505 %0, = "foo" () : () -> (i32, i32)
511 func.func @multi_result_mismatch_count() {
512 // expected-error@+1 {{operation defines 2 results but was provided 1 to bind}}
513 %0:1 = "foo" () : () -> (i32, i32)
519 func.func @multi_result_mismatch_count() {
520 // expected-error@+1 {{operation defines 2 results but was provided 3 to bind}}
521 %0, %1, %3 = "foo" () : () -> (i32, i32)
527 func.func @no_result_with_name() {
528 // expected-error@+1 {{cannot name an operation with no results}}
529 %0 = "foo" () : () -> ()
535 func.func @conflicting_names() {
536 // expected-note@+1 {{previously defined here}}
537 %foo, %bar = "foo" () : () -> (i32, i32)
539 // expected-error@+1 {{redefinition of SSA value '%bar'}}
540 %bar, %baz = "foo" () : () -> (i32, i32)
546 func.func @ssa_name_missing_eq() {
547 // expected-error@+1 {{expected '=' after SSA name}}
548 %0:2 "foo" () : () -> (i32, i32)
554 // expected-error @+1 {{attribute names with a '.' are reserved for dialect-defined names}}
559 func.func @invalid_region_dominance() {
560 "test.ssacfg_region"() ({
561 // expected-error @+1 {{operand #0 does not dominate this use}}
562 "foo.use" (%def) : (i32) -> ()
563 "foo.yield" () : () -> ()
565 // expected-note @+1 {{operand defined here}}
566 %def = "foo.def" () : () -> i32
573 func.func @invalid_region_dominance() {
574 // expected-note @+1 {{operand defined here}}
575 %def = "test.ssacfg_region"() ({
576 // expected-error @+1 {{operand #0 does not dominate this use}}
577 "foo.use" (%def) : (i32) -> ()
578 "foo.yield" () : () -> ()
585 // expected-error @+1 {{unbalanced '<' character in pretty dialect name}}
586 func.func @bad_arrow(%arg : !unreg.ptr<(i32)->)
590 func.func @forward_reference_type_check() -> (i8) {
594 // expected-note @+1 {{previously used here with type 'i8'}}
598 // expected-error @+1 {{definition of SSA value '%1#0' has type 'f32'}}
599 %1 = "bar"() : () -> (f32)
605 func.func @dominance_error_in_unreachable_op() -> i1 {
606 %c = arith.constant false
609 "test.ssacfg_region" () ({ // unreachable
611 // expected-error @+1 {{operand #0 does not dominate this use}}
612 %2:3 = "bar"(%1) : (i64) -> (i1,i1,i1)
617 %1 = "foo"() : ()->i64 // expected-note {{operand defined here}}
624 func.func @invalid_region_dominance_with_dominance_free_regions() {
626 "foo.use" (%1) : (i32) -> ()
628 %1 = arith.constant 0 : i32 // This value is used outside of the region.
629 "foo.yield" () : () -> ()
631 // expected-error @+1 {{expected operation name in quotes}}
632 %2 = arith.constant 1 i32 // Syntax error causes region deletion.
640 // expected-error@+1 {{expected valid attribute name}}
645 // This makes sure we emit an error at the end of the correct line, the : is
646 // expected at the end of foo, not on the return line.
647 func.func @error_at_end_of_line() {
648 // expected-error@+1 {{expected ':' followed by operation type}}
655 // This makes sure we emit an error at the end of the correct line, the : is
656 // expected at the end of foo, not on the return line.
657 func.func @error_at_end_of_line() {
659 // expected-error@-1 {{expected ':' followed by operation type}}
661 // This is a comment and so is the thing above.
667 // This makes sure we emit an error at the end of the correct line, the : is
668 // expected at the end of foo, not on the return line.
669 // This shows that it backs up to before the comment.
670 func.func @error_at_end_of_line() {
671 %0 = "foo"() // expected-error {{expected ':' followed by operation type}}
677 @foo // expected-error {{expected operation name in quotes}}