brintos

brintos / llvm-project-archived public Read only

0
0
Text · 15.4 KiB · 89077ef Raw
702 lines · plain
1// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics2 3// Check different error cases.4 5func.func @bad_branch() {6^bb12:7  cf.br ^missing  // expected-error {{reference to an undefined block}}8}9 10// -----11 12func.func @block_redef() {13^bb42:14  return15^bb42:        // expected-error {{redefinition of block '^bb42'}}16  return17}18 19// -----20 21func.func @no_terminator() {   // expected-error {{empty block: expect at least a terminator}}22^bb40:23  return24^bb41:25^bb42:26  return27}28 29// -----30 31func.func @block_no_rparen() {32^bb42 (%bb42 : i32: // expected-error {{expected ')'}}33  return34}35 36// -----37 38func.func @block_arg_no_ssaid() {39^bb42 (i32): // expected-error {{expected SSA operand}}40  return41}42 43// -----44 45func.func @block_arg_no_type() {46^bb42 (%0): // expected-error {{expected ':' and type for SSA operand}}47  return48}49 50// -----51 52func.func @block_arg_no_close_paren() {53^bb42:54  cf.br ^bb2( // expected-error {{expected ':'}}55  return56}57 58// -----59 60func.func @block_first_has_predecessor() {61// expected-error@-1 {{entry block of region may not have predecessors}}62^bb42:63  cf.br ^bb4364^bb43:65  cf.br ^bb4266}67 68// -----69 70func.func @no_return() {71  %x = arith.constant 0 : i3272  %y = arith.constant 1 : i32  // expected-error {{block with no terminator}}73}74 75// -----76 77func.func @no_terminator() {78  cf.br ^bb179^bb1:80  %x = arith.constant 0 : i3281  %y = arith.constant 1 : i32  // expected-error {{block with no terminator}}82}83 84// -----85 86func.func @no_block_arg_enclosing_parens() {87^bb %x: i32 : // expected-error {{expected ':' after block name}}88  return89}90 91// -----92 93func.func @bad_op_type() {94^bb40:95  "foo"() : i32  // expected-error {{expected function type}}96  return97}98// -----99 100func.func @no_terminator() {101^bb40:102  "foo"() : ()->()103  ""() : ()->()  // expected-error {{empty operation name is invalid}}104  return105}106 107// -----108 109func.func @non_operation() {110  test.asd   // expected-error {{custom op 'test.asd' is unknown}}111}112 113// -----114 115func.func @unknown_dialect_operation() {116  // expected-error@below {{Dialect `foo' not found for custom op 'foo.asd'}}117  // expected-note-re@below {{Available dialects:{{.*}} test{{.*}}}}118  foo.asd119}120 121// -----122 123func.func @non_operation() {124  // expected-error@+1 {{custom op 'asd' is unknown (tried 'func.asd' as well)}}125  asd126}127 128// -----129 130func.func @test() {131^bb40:132  %1 = "foo"() : (i32)->i64 // expected-error {{expected 0 operand types but had 1}}133  return134}135 136// -----137 138func.func @redef() {139^bb42:140  %x = "xxx"(){index = 0} : ()->i32 // expected-note {{previously defined here}}141  %x = "xxx"(){index = 0} : ()->i32 // expected-error {{redefinition of SSA value '%x'}}142  return143}144 145// -----146 147func.func @undef() {148^bb42:149  %x = "xxx"(%y) : (i32)->i32   // expected-error {{use of undeclared SSA value}}150  return151}152 153// -----154 155func.func @malformed_type(%a : intt) { // expected-error {{expected non-function type}}156}157 158// -----159 160func.func @argError() {161^bb1(%a: i64):  // expected-note {{previously defined here}}162  cf.br ^bb2163^bb2(%a: i64):  // expected-error{{redefinition of SSA value '%a'}}164  return165}166 167// -----168 169func.func @br_mismatch() {170^bb0: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)174 175^bb1(%x: i17):176  return177}178 179// -----180 181func.func @succ_arg_type_mismatch() {182^bb0:183  %0 = "getBool"() : () -> i1184  // expected-error @+1 {{type mismatch for bb argument #0 of successor #0}}185  cf.br ^bb1(%0 : i1)186 187^bb1(%x: i32):188  return189}190 191 192// -----193 194func.func @condbr_notbool() {195^bb0: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'}}198}199 200// -----201 202func.func @condbr_badtype() {203^bb0:204  %c = "foo"() : () -> i1205  %a = "foo"() : () -> i32206  cf.cond_br %c, ^bb0(%a, %a : i32, ^bb0) // expected-error {{expected non-function type}}207}208 209// -----210 211func.func @condbr_a_bb_is_not_a_type() {212^bb0:213  %c = "foo"() : () -> i1214  %a = "foo"() : () -> i32215  cf.cond_br %c, ^bb0(%a, %a : i32, i32), i32 // expected-error {{expected block name}}216}217 218// -----219 220func.func @successors_in_non_terminator(%a : i32, %b : i32) {221  %c = "arith.addi"(%a, %b)[^bb1] : () -> () // expected-error {{successors in non-terminator}}222^bb1:223  return224}225 226// -----227 228func.func @undef() {229^bb0:230  %x = "xxx"(%y) : (i32)->i32   // expected-error {{use of undeclared SSA value name}}231  return232}233 234// -----235 236func.func @undef() {237  %x = "xxx"(%y) : (i32)->i32   // expected-error {{use of undeclared SSA value name}}238  return239}240 241// -----242 243func.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}}246    }247  }248  return249}250 251// -----252 253func.func @name_scope_failure() {254  affine.for %i = 1 to 10 {255  }256  "xxx"(%i) : (index)->()   // expected-error {{use of undeclared SSA value name}}257  return258}259 260// -----261 262func.func @dominance_failure() {263^bb0:264  "foo"(%x) : (i32) -> ()    // expected-error {{operand #0 does not dominate this use}}265  cf.br ^bb1266^bb1:267  %x = "bar"() : () -> i32    // expected-note {{operand defined here (op in the same region)}}268  return269}270 271// -----272 273func.func @dominance_failure() {274^bb0: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)}}277  cf.br ^bb1278^bb1:279  return280}281 282// -----283 284func.func @dominance_failure() {285  "foo"() ({286    "foo"(%x) : (i32) -> ()    // expected-error {{operand #0 does not dominate this use}}287  }) : () -> ()288  %x = "bar"() : () -> i32    // expected-note {{operand defined here (op in a parent region)}}289  return290}291 292// -----293 294func.func @dominance_failure() {  //  expected-note {{operand defined as a block argument (block #1 in the same region)}}295^bb0:296  cf.br ^bb1(%x : i32)    // expected-error {{operand #0 does not dominate this use}}297^bb1(%x : i32):298  return299}300 301// -----302 303func.func @dominance_failure() {  //  expected-note {{operand defined as a block argument (block #1 in a parent region)}}304^bb0:305  %f = "foo"() ({306    "foo"(%x) : (i32) -> ()    // expected-error {{operand #0 does not dominate this use}}307  }) : () -> (i32)308  cf.br ^bb1(%f : i32)309^bb1(%x : i32):310  return311}312 313// -----314 315// expected-error@+1 {{expected three consecutive dots for an ellipsis}}316func.func @malformed_ellipsis_one(.)317 318// -----319 320// expected-error@+1 {{expected three consecutive dots for an ellipsis}}321func.func @malformed_ellipsis_two(..)322 323// -----324 325func.func private @redef()  // expected-note {{see existing symbol definition here}}326func.func private @redef()  // expected-error {{redefinition of symbol named 'redef'}}327 328// -----329 330func.func @calls(%arg0: i32) {331  // expected-error@+1 {{expected non-function type}}332  %z = "casdasda"(%x) : (ppop32) -> i32333}334 335// -----336 337// expected-error@+1 {{expected SSA operand}}338func.func @n(){^b(339 340// -----341 342// This used to crash the parser, but should just error out by interpreting343// `tensor` as operator rather than as a type.344func.func @f(f32) {345^bb0(%a : f32):346  %18 = arith.cmpi slt, %idx, %idx : index347  tensor<42 x index  // expected-error {{custom op 'tensor' is unknown (tried 'func.tensor' as well)}}348  return349}350 351// -----352 353func.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>357  }358  // expected-error@+1 {{region entry argument '%i1' is already in use}}359  affine.for %i1 = 0 to 42 {360  }361  return362}363 364// -----365 366func.func @dialect_type_empty_namespace(!<"">) -> () { // expected-error {{invalid type identifier}}367  return368}369 370// -----371 372func.func @dialect_type_missing_greater(!foo<) -> () { // expected-error {{unbalanced '<' character in pretty dialect name}}373  return374 375// -----376 377func.func @type_alias_unknown(!unknown_alias) -> () { // expected-error {{undefined symbol alias id 'unknown_alias'}}378  return379}380 381// -----382 383// expected-error @+1 {{type names with a '.' are reserved for dialect-defined names}}384!foo.bar = i32385 386// -----387 388!missing_eq_alias i32 // expected-error {{expected '=' in type alias definition}}389 390// -----391 392!missing_type_alias = // expected-error {{expected non-function type}}393 394// -----395 396!redef_alias = i32397!redef_alias = i32 // expected-error {{redefinition of type alias id 'redef_alias'}}398 399// -----400 401func.func @invalid_nested_dominance() {402  "test.ssacfg_region"() ({403    // expected-error @+1 {{operand #0 does not dominate this use}}404    "foo.use" (%1) : (i32) -> ()405    cf.br ^bb2406 407  ^bb2:408    // expected-note @+1 {{operand defined here}}409    %1 = arith.constant 0 : i32410    "foo.yield" () : () -> ()411  }) : () -> ()412  return413}414 415// -----416 417// expected-error @+1 {{unbalanced '<' character in pretty dialect name}}418func.func @invalid_unknown_type_dialect_name() -> !invalid.dialect<!x@#]!@#>419 420// -----421 422// expected-error @+1 {{expected '<' in tuple type}}423func.func @invalid_tuple_missing_less(tuple i32>)424 425// -----426 427// expected-error @+1 {{expected '>' in tuple type}}428func.func @invalid_tuple_missing_greater(tuple<i32)429 430// -----431 432// Should not crash because of deletion order here.433func.func @invalid_region_dominance() {434  "foo.use" (%1) : (i32) -> ()435  "foo.region"() ({436    %1 = arith.constant 0 : i32  // This value is used outside of the region.437    "foo.yield" () : () -> ()438  }, {439    // expected-error @+1 {{expected operation name in quotes}}440    %2 = arith.constant 1 i32  // Syntax error causes region deletion.441  }) : () -> ()442  return443}444 445// -----446 447// Should not crash because of deletion order here.448func.func @invalid_region_block() {449  "foo.branch"()[^bb2] : () -> ()  // Attempt to jump into the region.450 451^bb1:452  "foo.region"() ({453    ^bb2:454      "foo.yield"() : () -> ()455  }, {456    // expected-error @+1 {{expected operation name in quotes}}457    %2 = arith.constant 1 i32  // Syntax error causes region deletion.458  }) : () -> ()459}460 461// -----462 463// Should not crash because of deletion order here.464func.func @invalid_region_dominance() {465  "foo.use" (%1) : (i32) -> ()466  "foo.region"() ({467    "foo.region"() ({468      %1 = arith.constant 0 : i32  // This value is used outside of the region.469      "foo.yield" () : () -> ()470    }) : () -> ()471  }, {472    // expected-error @+1 {{expected operation name in quotes}}473    %2 = arith.constant 1 i32  // Syntax error causes region deletion.474  }) : () -> ()475  return476}477 478// -----479 480func.func @unfinished_region_list() {481  // expected-error@+1 {{expected ')' to end region list}}482  "region"() ({},{},{} : () -> ()483}484 485// -----486 487func.func @multi_result_missing_count() {488  // expected-error@+1 {{expected integer number of results}}489  %0: = "foo" () : () -> (i32, i32)490  return491}492 493// -----494 495func.func @multi_result_zero_count() {496  // expected-error@+1 {{expected named operation to have at least 1 result}}497  %0:0 = "foo" () : () -> (i32, i32)498  return499}500 501// -----502 503func.func @multi_result_invalid_identifier() {504  // expected-error@+1 {{expected valid ssa identifier}}505  %0, = "foo" () : () -> (i32, i32)506  return507}508 509// -----510 511func.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)514  return515}516 517// -----518 519func.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)522  return523}524 525// -----526 527func.func @no_result_with_name() {528  // expected-error@+1 {{cannot name an operation with no results}}529  %0 = "foo" () : () -> ()530  return531}532 533// -----534 535func.func @conflicting_names() {536  // expected-note@+1 {{previously defined here}}537  %foo, %bar  = "foo" () : () -> (i32, i32)538 539  // expected-error@+1 {{redefinition of SSA value '%bar'}}540  %bar, %baz  = "foo" () : () -> (i32, i32)541  return542}543 544// -----545 546func.func @ssa_name_missing_eq() {547  // expected-error@+1 {{expected '=' after SSA name}}548  %0:2 "foo" () : () -> (i32, i32)549  return550}551 552// -----553 554// expected-error @+1 {{attribute names with a '.' are reserved for dialect-defined names}}555#foo.attr = i32556 557// -----558 559func.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" () : () -> ()564  }, {565    // expected-note @+1 {{operand defined here}}566    %def = "foo.def" () : () -> i32567  }) : () -> ()568  return569}570 571// -----572 573func.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" () : () -> ()579  }) : () -> (i32)580  return581}582 583// -----584 585// expected-error @+1 {{unbalanced '<' character in pretty dialect name}}586func.func @bad_arrow(%arg : !unreg.ptr<(i32)->)587 588// -----589 590func.func @forward_reference_type_check() -> (i8) {591  cf.br ^bb2592 593^bb1:594  // expected-note @+1 {{previously used here with type 'i8'}}595  return %1 : i8596 597^bb2:598  // expected-error @+1 {{definition of SSA value '%1#0' has type 'f32'}}599  %1 = "bar"() : () -> (f32)600  cf.br ^bb1601}602 603// -----604 605func.func @dominance_error_in_unreachable_op() -> i1 {606  %c = arith.constant false607  return %c : i1608^bb0:609  "test.ssacfg_region" () ({ // unreachable610    ^bb1:611// expected-error @+1 {{operand #0 does not dominate this use}}612      %2:3 = "bar"(%1) : (i64) -> (i1,i1,i1)613      cf.br ^bb4614    ^bb2:615      cf.br ^bb2616    ^bb4:617      %1 = "foo"() : ()->i64   // expected-note {{operand defined here}}618  }) : () -> ()619  return %c : i1620}621 622// -----623 624func.func @invalid_region_dominance_with_dominance_free_regions() {625  test.graph_region {626    "foo.use" (%1) : (i32) -> ()627    "foo.region"() ({628      %1 = arith.constant 0 : i32  // This value is used outside of the region.629      "foo.yield" () : () -> ()630    }, {631      // expected-error @+1 {{expected operation name in quotes}}632      %2 = arith.constant 1 i32  // Syntax error causes region deletion.633    }) : () -> ()634  }635  return636}637 638// -----639 640// expected-error@+1 {{expected valid attribute name}}641"t"(){""}642 643// -----644 645// expected-error @below {{expected bare identifier or keyword}}646test.parse_custom_operation_name_api(@foo) {}647 648// -----649 650// expected-error @below {{expected bare identifier or keyword}}651test.parse_custom_operation_name_api(42) {}652 653// -----654 655// This makes sure we emit an error at the end of the correct line, the : is656// expected at the end of foo, not on the return line.657func.func @error_at_end_of_line() {658  // expected-error@+1 {{expected ':' followed by operation type}}659  %0 = "foo"()660  return661}662 663// -----664 665// This makes sure we emit an error at the end of the correct line, the : is666// expected at the end of foo, not on the return line.667func.func @error_at_end_of_line() {668  %0 = "foo"()669  // expected-error@-1 {{expected ':' followed by operation type}}670 671  // This is a comment and so is the thing above.672  return673}674 675// -----676 677// This makes sure we emit an error at the end of the correct line, the : is678// expected at the end of foo, not on the return line.679// This shows that it backs up to before the comment.680func.func @error_at_end_of_line() {681  %0 = "foo"()  // expected-error {{expected ':' followed by operation type}}682  return683}684 685// -----686 687@foo   // expected-error {{expected operation name in quotes}}688 689// -----690 691func.func @drop_references_on_block_parse_error(){692  "test.user"(%i, %1) : (index, index) -> ()693  "test.op_with_region"() ({694  ^bb0(%i : index):695    // expected-error @below{{expected operation name in quotes}}696    %1 = "test.foo"() : () -> (index)697    // Syntax error to abort parsing this block.698    123699  }) : () -> ()700  return701}702