brintos

brintos / llvm-project-archived public Read only

0
0
Text · 26.8 KiB · f285196 Raw
917 lines · plain
1// RUN: mlir-opt %s -split-input-file -verify-diagnostics2 3func.func @const_attribute_str() {4    // expected-error @+1 {{'emitc.constant' op string attributes are not supported, use #emitc.opaque instead}}                 5    %c0 = "emitc.constant"(){value = "NULL"} : () -> !emitc.ptr<i32>6    return7}8 9// -----10 11func.func @const_attribute_return_type_1() {12    // expected-error @+1 {{'emitc.constant' op requires attribute to either be an #emitc.opaque attribute or it's type ('i64') to match the op's result type ('i32')}}13    %c0 = "emitc.constant"(){value = 42: i64} : () -> i3214    return15}16 17// -----18 19func.func @const_attribute_return_type_2() {20    // expected-error @+1 {{'emitc.constant' op attribute 'value' failed to satisfy constraint: An opaque attribute or TypedAttr instance}}21    %c0 = "emitc.constant"(){value = unit} : () -> i3222    return23}24 25// -----26 27func.func @empty_constant() {28    // expected-error @+1 {{'emitc.constant' op value must not be empty}}29    %c0 = "emitc.constant"(){value = #emitc.opaque<"">} : () -> i3230    return31}32 33// -----34 35func.func @index_args_out_of_range_1() {36    // expected-error @+1 {{'emitc.call_opaque' op index argument is out of range}}37    emitc.call_opaque "test" () {args = [0 : index]} : () -> ()38    return39}40 41// -----42 43func.func @index_args_out_of_range_2(%arg : i32) {44    // expected-error @+1 {{'emitc.call_opaque' op index argument is out of range}}45    emitc.call_opaque "test" (%arg, %arg) {args = [2 : index]} : (i32, i32) -> ()46    return47}48 49// -----50 51func.func @empty_callee() {52    // expected-error @+1 {{'emitc.call_opaque' op callee must not be empty}}53    emitc.call_opaque "" () : () -> ()54    return55}56 57// -----58 59func.func @nonetype_arg(%arg : i32) {60    // expected-error @+1 {{'emitc.call_opaque' op array argument has no type}}61    emitc.call_opaque "nonetype_arg"(%arg) {args = [0 : index, [0, 1, 2]]} : (i32) -> i3262    return63}64 65// -----66 67func.func @array_template_arg(%arg : i32) {68    // expected-error @+1 {{'emitc.call_opaque' op template argument has invalid type}}69    emitc.call_opaque "nonetype_template_arg"(%arg) {template_args = [[0, 1, 2]]} : (i32) -> i3270    return71}72 73// -----74 75func.func @dense_template_argument(%arg : i32) {76    // expected-error @+1 {{'emitc.call_opaque' op template argument has invalid type}}77    emitc.call_opaque "dense_template_argument"(%arg) {template_args = [dense<[1.0, 1.0]> : tensor<2xf32>]} : (i32) -> i3278    return79}80 81// -----82 83func.func @array_result() {84    // expected-error @+1 {{'emitc.call_opaque' op cannot return array type}}85    emitc.call_opaque "array_result"() : () -> !emitc.array<4xi32>86    return87}88 89// -----90 91func.func @empty_operator() {92    %0 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>93    // expected-error @+1 {{'emitc.apply' op applicable operator must not be empty}}94    %1 = emitc.apply ""(%0) : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>95    return96}97 98// -----99 100func.func @illegal_operator() {101    %0 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>102    // expected-error @+1 {{'emitc.apply' op applicable operator is illegal}}103    %1 = emitc.apply "+"(%0) : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>104    return105}106 107// -----108 109func.func @var_attribute_return_type_1() {110    // expected-error @+1 {{'emitc.variable' op requires attribute to either be an #emitc.opaque attribute or it's type ('i64') to match the op's result type ('i32')}}111    %c0 = "emitc.variable"(){value = 42: i64} : () -> !emitc.lvalue<i32>112    return113}114 115// -----116 117func.func @var_attribute_return_type_2() {118    // expected-error @+1 {{'emitc.variable' op attribute 'value' failed to satisfy constraint: An opaque attribute or TypedAttr instance}}119    %c0 = "emitc.variable"(){value = unit} : () -> !emitc.lvalue<i32>120    return121}122 123// -----124 125func.func @cast_tensor(%arg : tensor<f32>) {126    // expected-error @+1 {{'emitc.cast' op operand type 'tensor<f32>' and result type 'tensor<f32>' are cast incompatible}}127    %1 = emitc.cast %arg: tensor<f32> to tensor<f32>128    return129}130 131// -----132 133func.func @cast_to_array(%arg : f32) {134    // expected-error @+1 {{'emitc.cast' op operand type 'f32' and result type '!emitc.array<4xf32>' are cast incompatible}}135    %1 = emitc.cast %arg: f32 to !emitc.array<4xf32>136    return137}138 139// -----140 141func.func @cast_multidimensional_array(%arg : !emitc.array<1x2xi32>) {142    // expected-error @+1 {{'emitc.cast' op operand type '!emitc.array<1x2xi32>' and result type '!emitc.ptr<i32>' are cast incompatible}}143    %1 = emitc.cast %arg: !emitc.array<1x2xi32> to !emitc.ptr<i32>144    return145}146 147// -----148 149func.func @cast_array_zero_rank(%arg : !emitc.array<0xi32>) {150    // expected-error @+1 {{'emitc.cast' op operand type '!emitc.array<0xi32>' and result type '!emitc.ptr<i32>' are cast incompatible}}151    %1 = emitc.cast %arg: !emitc.array<0xi32> to !emitc.ptr<i32>152    return153}154 155// -----156 157func.func @cast_array_to_pointer_types_mismatch(%arg : !emitc.array<3xi32>) {158    // expected-error @+1 {{'emitc.cast' op operand type '!emitc.array<3xi32>' and result type '!emitc.ptr<f16>' are cast incompatible}}159    %1 = emitc.cast %arg: !emitc.array<3xi32> to !emitc.ptr<f16>160    return161}162 163// -----164 165func.func @cast_pointer_to_array(%arg : !emitc.ptr<i32>) {166    // expected-error @+1 {{'emitc.cast' op operand type '!emitc.ptr<i32>' and result type '!emitc.array<3xi32>' are cast incompatible}}167    %1 = emitc.cast %arg: !emitc.ptr<i32> to !emitc.array<3xi32>168    return169}170 171// -----172 173func.func @add_two_pointers(%arg0: !emitc.ptr<f32>, %arg1: !emitc.ptr<f32>) {174    // expected-error @+1 {{'emitc.add' op requires that at most one operand is a pointer}}175    %1 = "emitc.add" (%arg0, %arg1) : (!emitc.ptr<f32>, !emitc.ptr<f32>) -> !emitc.ptr<f32>176    return177}178 179// -----180 181func.func @add_pointer_float(%arg0: !emitc.ptr<f32>, %arg1: f32) {182    // expected-error @+1 {{'emitc.add' op requires that one operand is an integer or of opaque type if the other is a pointer}}183    %1 = "emitc.add" (%arg0, %arg1) : (!emitc.ptr<f32>, f32) -> !emitc.ptr<f32>184    return185}186 187// -----188 189func.func @add_float_pointer(%arg0: f32, %arg1: !emitc.ptr<f32>) {190    // expected-error @+1 {{'emitc.add' op requires that one operand is an integer or of opaque type if the other is a pointer}}191    %1 = "emitc.add" (%arg0, %arg1) : (f32, !emitc.ptr<f32>) -> !emitc.ptr<f32>192    return193}194 195// -----196 197func.func @div_tensor(%arg0: tensor<i32>, %arg1: tensor<i32>) {198    // expected-error @+1 {{'emitc.div' op operand #0 must be floating-point type supported by EmitC or integer, index or opaque type supported by EmitC, but got 'tensor<i32>'}}199    %1 = "emitc.div" (%arg0, %arg1) : (tensor<i32>, tensor<i32>) -> tensor<i32>200    return201}202 203// -----204 205func.func @mul_tensor(%arg0: tensor<i32>, %arg1: tensor<i32>) {206    // expected-error @+1 {{'emitc.mul' op operand #0 must be floating-point type supported by EmitC or integer, index or opaque type supported by EmitC, but got 'tensor<i32>'}}207    %1 = "emitc.mul" (%arg0, %arg1) : (tensor<i32>, tensor<i32>) -> tensor<i32>208    return209}210 211// -----212 213func.func @rem_tensor(%arg0: tensor<i32>, %arg1: tensor<i32>) {214    // expected-error @+1 {{'emitc.rem' op operand #0 must be integer, index or opaque type supported by EmitC, but got 'tensor<i32>'}}215    %1 = "emitc.rem" (%arg0, %arg1) : (tensor<i32>, tensor<i32>) -> tensor<i32>216    return217}218 219// -----220 221func.func @rem_float(%arg0: f32, %arg1: f32) {222    // expected-error @+1 {{'emitc.rem' op operand #0 must be integer, index or opaque type supported by EmitC, but got 'f32'}}223    %1 = "emitc.rem" (%arg0, %arg1) : (f32, f32) -> f32224    return225}226 227// -----228 229func.func @sub_int_pointer(%arg0: i32, %arg1: !emitc.ptr<f32>) {230    // expected-error @+1 {{'emitc.sub' op rhs can only be a pointer if lhs is a pointer}}231    %1 = "emitc.sub" (%arg0, %arg1) : (i32, !emitc.ptr<f32>) -> !emitc.ptr<f32>232    return233}234 235 236// -----237 238func.func @sub_pointer_float(%arg0: !emitc.ptr<f32>, %arg1: f32) {239    // expected-error @+1 {{'emitc.sub' op requires that rhs is an integer, pointer or of opaque type if lhs is a pointer}}240    %1 = "emitc.sub" (%arg0, %arg1) : (!emitc.ptr<f32>, f32) -> !emitc.ptr<f32>241    return242}243 244// -----245 246func.func @sub_pointer_pointer(%arg0: !emitc.ptr<f32>, %arg1: !emitc.ptr<f32>) {247    // expected-error @+1 {{'emitc.sub' op requires that the result is an integer, ptrdiff_t or of opaque type if lhs and rhs are pointers}}248    %1 = "emitc.sub" (%arg0, %arg1) : (!emitc.ptr<f32>, !emitc.ptr<f32>) -> !emitc.ptr<f32>249    return250}251 252// -----253 254func.func @test_misplaced_yield() {255  // expected-error @+1 {{'emitc.yield' op expects parent op to be one of 'emitc.do, emitc.expression, emitc.for, emitc.if, emitc.switch'}}256  emitc.yield257  return258}259 260// -----261 262func.func @test_assign_to_block_argument(%arg0: f32) {263  %0 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<f32>264  cf.br ^bb1(%0 : !emitc.lvalue<f32>)265^bb1(%a : !emitc.lvalue<f32>):266  // expected-error @+1 {{'emitc.assign' op cannot assign to block argument}}267  emitc.assign %arg0 : f32 to %a : !emitc.lvalue<f32>268  func.return269}270 271// -----272 273func.func @test_assign_type_mismatch(%arg1: f32) {274  %v = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>275  // expected-error @+1 {{'emitc.assign' op requires value's type ('f32') to match variable's type ('i32')}}276  emitc.assign %arg1 : f32 to %v : !emitc.lvalue<i32>277  return278}279 280// -----281 282func.func @test_assign_to_array(%arg1: !emitc.array<4xi32>) {283  %v = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.array<4xi32>284  // expected-error @+1 {{invalid kind of type specified: expected emitc.lvalue, but found '!emitc.array<4xi32>'}}285  emitc.assign %arg1 : !emitc.array<4xi32> to %v : !emitc.array<4xi32>286  return287}288 289// -----290 291func.func @test_expression_no_yield() -> i32 {292  // expected-error @+1 {{'emitc.expression' op must yield a value at termination}}293  %r = emitc.expression : () -> i32 {294    %c7 = "emitc.constant"(){value = 7 : i32} : () -> i32295  }296  return %r : i32297}298 299// -----300 301func.func @test_expression_illegal_op(%arg0 : i1) -> i32 {302  // expected-error @+1 {{'emitc.expression' op contains an unsupported operation}}303  %r = emitc.expression : () -> i32 {304    %x = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>305    %y = emitc.load %x : <i32>306    emitc.yield %y : i32307  }308  return %r : i32309}310 311// -----312 313func.func @test_expression_no_use(%arg0: i32, %arg1: i32) -> i32 {314  // expected-error @+1 {{'emitc.expression' op contains an unused operation}}315  %r = emitc.expression %arg0, %arg1 : (i32, i32) -> i32 {316    %a = emitc.add %arg0, %arg1 : (i32, i32) -> i32317    %b = emitc.rem %arg0, %arg1 : (i32, i32) -> i32318    emitc.yield %a : i32319  }320  return %r : i32321}322 323// -----324 325func.func @test_expression_multiple_uses(%arg0: i32, %arg1: i32) -> i32 {326  // expected-error @+1 {{'emitc.expression' op requires exactly one use for operations with side effects}}327  %r = emitc.expression %arg0, %arg1 : (i32, i32) -> i32 {328    %a = emitc.call_opaque "foo"(%arg0, %arg1) : (i32, i32) -> i32329    %b = emitc.add %a, %arg0 : (i32, i32) -> i32330    %c = emitc.mul %b, %a : (i32, i32) -> i32331    emitc.yield %c : i32332  }333  return %r : i32334}335 336// -----337 338func.func @test_expression_multiple_results(%arg0: i32) -> i32 {339  // expected-error @+1 {{'emitc.expression' op requires exactly one result for each operation}}340  %r = emitc.expression %arg0 : (i32) -> i32 {341    %a:2 = emitc.call_opaque "bar" (%arg0) : (i32) -> (i32, i32)342    emitc.yield %a : i32343  }344  return %r : i32345}346 347// -----348 349emitc.func @test_expression_no_defining_op(%a : i32) {350  // expected-error @+1 {{'emitc.expression' op yielded value has no defining op}}351  %res = emitc.expression %a : (i32) -> i32 {352    emitc.yield %a : i32353  }354 355  return356}357 358// -----359 360emitc.func @test_expression_no_defining_op() {361  %cond = literal "true" : i1362  // expected-error @+1 {{'emitc.expression' op yielded value has no defining op}}363  %res = emitc.expression %cond : (i1) -> i1 {364    emitc.yield %cond : i1365  }366  return367}368 369// -----370 371emitc.func @test_expression_op_outside_expression() {372  %cond = literal "true" : i1373  %res = emitc.expression : () -> i1 {374    // expected-error @+1 {{use of undeclared SSA value name}}375    emitc.yield %cond : i1376  }377  return378}379 380// -----381 382// expected-error @+1 {{'emitc.func' op requires zero or exactly one result, but has 2}}383emitc.func @multiple_results(%0: i32) -> (i32, i32) {384  emitc.return %0 : i32385}386 387// -----388 389emitc.func @resulterror() -> i32 {390^bb42:391  emitc.return    // expected-error {{'emitc.return' op has 0 operands, but enclosing function (@resulterror) returns 1}}392}393 394// -----395 396emitc.func @return_type_mismatch() -> i32 {397  %0 = emitc.call_opaque "foo()"(): () -> f32398  emitc.return %0 : f32  // expected-error {{type of the return operand ('f32') doesn't match function result type ('i32') in function @return_type_mismatch}}399}400 401// -----402 403// expected-error@+1 {{'emitc.func' op cannot have lvalue type as argument}}404emitc.func @argument_type_lvalue(%arg : !emitc.lvalue<i32>) {405  emitc.return406}407 408// -----409 410// expected-error@+1 {{'emitc.func' op cannot return array type}}411emitc.func @return_type_array(%arg : !emitc.array<4xi32>) -> !emitc.array<4xi32> {412  emitc.return %arg : !emitc.array<4xi32>413}414 415// -----416 417func.func @return_inside_func.func(%0: i32) -> (i32) {418  // expected-error@+1 {{'emitc.return' op expects parent op 'emitc.func'}}419  emitc.return %0 : i32420}421// -----422 423// expected-error@+1 {{expected non-function type}}424emitc.func @func_variadic(...)425 426// -----427 428// expected-error@+1 {{'emitc.declare_func' op 'bar' does not reference a valid function}}429emitc.declare_func @bar430 431// -----432 433// expected-error@+1 {{'emitc.declare_func' op requires attribute 'sym_name'}}434"emitc.declare_func"()  : () -> ()435 436// -----437 438func.func @logical_and_resulterror(%arg0: i32, %arg1: i32) {439  // expected-error @+1 {{'emitc.logical_and' op result #0 must be 1-bit signless integer, but got 'i32'}}440  %0 = "emitc.logical_and"(%arg0, %arg1) : (i32, i32) -> i32441  return442}443 444// -----445 446func.func @logical_not_resulterror(%arg0: i32) {447  // expected-error @+1 {{'emitc.logical_not' op result #0 must be 1-bit signless integer, but got 'i32'}}448  %0 = "emitc.logical_not"(%arg0) : (i32) -> i32449  return450}451 452// -----453 454func.func @logical_or_resulterror(%arg0: i32, %arg1: i32) {455  // expected-error @+1 {{'emitc.logical_or' op result #0 must be 1-bit signless integer, but got 'i32'}}456  %0 = "emitc.logical_or"(%arg0, %arg1) : (i32, i32) -> i32457  return458}459 460// -----461 462func.func @test_subscript_array_indices_mismatch(%arg0: !emitc.array<4x8xf32>, %arg1: index) {463  // expected-error @+1 {{'emitc.subscript' op on array operand requires number of indices (1) to match the rank of the array type (2)}}464  %0 = emitc.subscript %arg0[%arg1] : (!emitc.array<4x8xf32>, index) -> !emitc.lvalue<f32>465  return466}467 468// -----469 470func.func @test_subscript_array_index_type_mismatch(%arg0: !emitc.array<4x8xf32>, %arg1: index, %arg2: f32) {471  // expected-error @+1 {{'emitc.subscript' op on array operand requires index operand 1 to be integer-like, but got 'f32'}}472  %0 = emitc.subscript %arg0[%arg1, %arg2] : (!emitc.array<4x8xf32>, index, f32) -> !emitc.lvalue<f32>473  return474}475 476// -----477 478func.func @test_subscript_array_type_mismatch(%arg0: !emitc.array<4x8xf32>, %arg1: index, %arg2: index) {479  // expected-error @+1 {{'emitc.subscript' op on array operand requires element type ('f32') and result type ('i32') to match}}480  %0 = emitc.subscript %arg0[%arg1, %arg2] : (!emitc.array<4x8xf32>, index, index) -> !emitc.lvalue<i32>481  return482}483 484// -----485 486func.func @test_subscript_ptr_indices_mismatch(%arg0: !emitc.ptr<f32>, %arg1: index) {487  // expected-error @+1 {{'emitc.subscript' op on pointer operand requires one index operand, but got 2}}488  %0 = emitc.subscript %arg0[%arg1, %arg1] : (!emitc.ptr<f32>, index, index) -> !emitc.lvalue<f32>489  return490}491 492// -----493 494func.func @test_subscript_ptr_index_type_mismatch(%arg0: !emitc.ptr<f32>, %arg1: f64) {495  // expected-error @+1 {{'emitc.subscript' op on pointer operand requires index operand to be integer-like, but got 'f64'}}496  %0 = emitc.subscript %arg0[%arg1] : (!emitc.ptr<f32>, f64) -> !emitc.lvalue<f32>497  return498}499 500// -----501 502func.func @test_subscript_ptr_type_mismatch(%arg0: !emitc.ptr<f32>, %arg1: index) {503  // expected-error @+1 {{'emitc.subscript' op on pointer operand requires pointee type ('f32') and result type ('f64') to match}}504  %0 = emitc.subscript %arg0[%arg1] : (!emitc.ptr<f32>, index) -> !emitc.lvalue<f64>505  return506}507 508// -----509 510// expected-error @+1 {{'emitc.global' op cannot have both static and extern specifiers}}511emitc.global extern static @uninit : i32512 513// -----514 515emitc.global @myglobal_array : !emitc.array<2xf32>516 517func.func @use_global() {518  // expected-error @+1 {{'emitc.get_global' op on array type expects result type '!emitc.array<3xf32>' to match type '!emitc.array<2xf32>' of the global @myglobal_array}}519  %0 = emitc.get_global @myglobal_array : !emitc.array<3xf32>520  return521}522 523// -----524 525emitc.global @myglobal_scalar : f32526 527func.func @use_global() {528  // expected-error @+1 {{'emitc.get_global' op on non-array type expects result inner type 'i32' to match type 'f32' of the global @myglobal_scalar}}529  %0 = emitc.get_global @myglobal_scalar : !emitc.lvalue<i32>530  return531}532 533// -----534 535emitc.global @myglobal_value : f32536 537func.func @use_global() {538  // expected-error @+1 {{'emitc.get_global' op on non-array type expects result type to be an lvalue type for the global @myglobal_value}}539  %0 = emitc.get_global @myglobal_value : !emitc.array<2xf32>540  return541}542 543// -----544 545func.func @member(%arg0: !emitc.lvalue<i32>) {546  // expected-error @+1 {{'emitc.member' op operand #0 must be emitc.lvalue of EmitC opaque type values, but got '!emitc.lvalue<i32>'}}547  %0 = "emitc.member" (%arg0) {member = "a"} : (!emitc.lvalue<i32>) -> !emitc.lvalue<i32>548  return549}550 551// -----552 553func.func @member_of_ptr(%arg0: !emitc.lvalue<i32>) {554  // expected-error @+1 {{'emitc.member_of_ptr' op operand #0 must be emitc.lvalue of EmitC opaque type or EmitC pointer type values, but got '!emitc.lvalue<i32>'}}555  %0 = "emitc.member_of_ptr" (%arg0) {member = "a"} : (!emitc.lvalue<i32>) -> !emitc.lvalue<i32>556  return557}558 559// -----560 561func.func @emitc_switch() {562  %0 = "emitc.constant"(){value = 1 : i16} : () -> i16563 564  // expected-error@+1 {{'emitc.switch' op expected region to end with emitc.yield, but got emitc.call_opaque}}565  emitc.switch %0 : i16566  case 2 {567    %1 = emitc.call_opaque "func_b" () : () -> i32568  }569  case 5 {570    %2 = emitc.call_opaque "func_a" () : () -> i32571    emitc.yield572  }573  default {574    %3 = "emitc.constant"(){value = 42.0 : f32} : () -> f32575    emitc.call_opaque "func2" (%3) : (f32) -> ()576    emitc.yield577  }578  return579}580 581// -----582 583func.func @emitc_switch() {584  %0 = "emitc.constant"(){value = 1 : i32} : () -> i32585 586  emitc.switch %0 : i32587  case 2 {588    %1 = emitc.call_opaque "func_b" () : () -> i32589    emitc.yield590  }591  // expected-error@+1 {{custom op 'emitc.switch' expected integer value}}592  case {593    %2 = emitc.call_opaque "func_a" () : () -> i32594    emitc.yield595  }596  default {597    %3 = "emitc.constant"(){value = 42.0 : f32} : () -> f32598    emitc.call_opaque "func2" (%3) : (f32) -> ()599    emitc.yield600  }601  return602}603 604// -----605 606func.func @emitc_switch() {607  %0 = "emitc.constant"(){value = 1 : i8} : () -> i8608 609  emitc.switch %0 : i8610  case 2 {611    %1 = emitc.call_opaque "func_b" () : () -> i32612    emitc.yield613  }614  case 3 {615    %2 = emitc.call_opaque "func_a" () : () -> i32616    emitc.yield617  }618  // expected-error@+1 {{custom op 'emitc.switch' expected 'default'}}619  return620}621 622// -----623 624func.func @emitc_switch() {625  %0 = "emitc.constant"(){value = 1 : i64} : () -> i64626 627  // expected-error@+1 {{'emitc.switch' op has duplicate case value: 2}}628  emitc.switch %0 : i64629  case 2 {630    %1 = emitc.call_opaque "func_b" () : () -> i32631    emitc.yield632  }633  case 2 {634    %2 = emitc.call_opaque "func_a" () : () -> i32635    emitc.yield636  }637  default {638    %3 = "emitc.constant"(){value = 42.0 : f32} : () -> f32639    emitc.call_opaque "func2" (%3) : (f32) -> ()640    emitc.yield641  }642  return643}644 645// -----646 647func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {648  // expected-error @+1 {{'emitc.verbatim' op requires operands for each placeholder in the format string}}649  emitc.verbatim "" args %arg0, %arg1 : !emitc.ptr<i32>, i32650  return651}652 653// -----654 655func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {656  // expected-error @+1 {{'emitc.verbatim' op expected '}' after unescaped '{' at end of string}}657  emitc.verbatim "{} + {} {" args %arg0, %arg1 : !emitc.ptr<i32>, i32658  return659}660 661// -----662 663func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {664  // expected-error @+1 {{'emitc.verbatim' op requires operands for each placeholder in the format string}}665  emitc.verbatim "abc" args %arg0, %arg1 : !emitc.ptr<i32>, i32666  return667}668 669// -----670 671func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {672  // expected-error @+1 {{'emitc.verbatim' op requires operands for each placeholder in the format string}}673  emitc.verbatim "{}" args %arg0, %arg1 : !emitc.ptr<i32>, i32674  return675}676 677// -----678 679func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {680  // expected-error @+1 {{'emitc.verbatim' op requires operands for each placeholder in the format string}}681  emitc.verbatim "{} {} {}" args %arg0, %arg1 : !emitc.ptr<i32>, i32682  return683}684 685// -----686 687func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {688  // expected-error @+1 {{'emitc.verbatim' op expected '}' after unescaped '{'}}689  emitc.verbatim "{ " args %arg0, %arg1 : !emitc.ptr<i32>, i32690  return691}692 693// -----694 695func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {696  // expected-error @+1 {{'emitc.verbatim' op expected '}' after unescaped '{'}}697  emitc.verbatim "{a} " args %arg0, %arg1 : !emitc.ptr<i32>, i32698  return699}700 701// -----702 703// expected-error @+1 {{'emitc.field' op field must be nested within an emitc.class operation}}704emitc.field @testField : !emitc.array<1xf32>705 706// -----707 708// expected-error @+1 {{'emitc.get_field' op  must be nested within an emitc.class operation}}709%1 = emitc.get_field @testField : !emitc.array<1xf32>710 711// -----712 713emitc.func @testMethod() {714  %0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t715  // expected-error @+1 {{'emitc.get_field' op  must be nested within an emitc.class operation}}716  %1 = get_field @testField : !emitc.array<1xf32>717  %2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>718  return719}720 721// -----722 723emitc.class @testClass {724  emitc.func @testMethod() {725    %0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t726    // expected-error @+1 {{'emitc.get_field' op field '@testField' not found in the class}}727    %1 = get_field @testField : !emitc.array<1xf32>728    %2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>729    return730  }731}732 733// -----734 735func.func @test_do(%arg0 : !emitc.ptr<i32>) {736  %1 = emitc.literal "1" : i32737  %2 = emitc.literal "2" : i32738 739  // expected-error @+1 {{'emitc.do' op condition region must contain exactly two operations: 'emitc.expression' followed by 'emitc.yield', but found 3 operations}}740  emitc.do {741    emitc.verbatim "printf(\"%d\", *{});" args %arg0 : !emitc.ptr<i32>742  } while {743    %r = emitc.expression %1, %2 : (i32, i32) -> i1 {744      %cmp = emitc.cmp eq, %1, %2 : (i32, i32) -> i1745      emitc.yield %cmp : i1746    }747 748    %3 = emitc.literal "3" : i32749    emitc.yield %r : i1750  }751 752  return753}754 755// -----756 757func.func @test_do(%arg0 : !emitc.ptr<i32>) {758  // expected-error @+1 {{'emitc.do' op expected first op in condition region to be 'emitc.expression', but got emitc.literal}}759  emitc.do {760    emitc.verbatim "printf(\"%d\", *{});" args %arg0 : !emitc.ptr<i32>761  } while {762    %true = emitc.literal "true" : i1763    emitc.yield %true : i1764  }765 766  return767}768 769// -----770 771func.func @test_do(%arg0 : !emitc.ptr<i32>) {772  %1 = emitc.literal "1" : i32773  %2 = emitc.literal "2" : i32774 775  // expected-error @+1 {{'emitc.do' op emitc.expression in condition region must return 'i1', but returns 'i32'}}776  emitc.do {777    emitc.verbatim "printf(\"%d\", *{});" args %arg0 : !emitc.ptr<i32>778  } while {779    %r = emitc.expression %1, %2 : (i32, i32) -> i32 {780      %add = emitc.add %1, %2 : (i32, i32) -> i32781      emitc.yield %add : i32782    }783 784    emitc.yield %r : i32785  }786 787  return788}789 790// -----791 792func.func @test_do(%arg0 : !emitc.ptr<i32>) {793  %1 = emitc.literal "1" : i32794  %2 = emitc.literal "2" : i32795 796  // expected-error @+1 {{'emitc.do' op expected last op in condition region to be 'emitc.yield', but got emitc.expression}}797  emitc.do {798    emitc.verbatim "printf(\"%d\", *{});" args %arg0 : !emitc.ptr<i32>799  } while {800    %r1 = emitc.expression %1, %2 : (i32, i32) -> i1 {801      %cmp = emitc.cmp eq, %1, %2 : (i32, i32) -> i1802      emitc.yield %cmp : i1803    }804 805    %r2 = emitc.expression %1, %2 : (i32, i32) -> i32 {806      %add = emitc.add %1, %2 : (i32, i32) -> i32807      emitc.yield %add : i32808    }809  }810 811  return812}813 814// -----815 816func.func @test_do(%arg0 : !emitc.ptr<i32>) {817  %1 = emitc.literal "1" : i32818  %2 = emitc.literal "2" : i32819 820  // expected-error @+1 {{'emitc.do' op expected condition region to return 1 value, but it returns 0 values}}821  emitc.do {822    emitc.verbatim "printf(\"%d\", *{});" args %arg0 : !emitc.ptr<i32>823  } while {824    %r = emitc.expression %1, %2 : (i32, i32) -> i1 {825      %cmp = emitc.cmp eq, %1, %2 : (i32, i32) -> i1826      emitc.yield %cmp : i1827    }828 829    emitc.yield830  }831 832  return833}834 835// -----836 837func.func @test_do(%arg0 : !emitc.ptr<i32>) {838  %1 = emitc.literal "1" : i32839  %2 = emitc.literal "2" : i32840 841  %true = emitc.literal "true" : i1842 843  // expected-error @+1 {{'emitc.yield' must return result of 'emitc.expression' from this condition region}}844  emitc.do {845    emitc.verbatim "printf(\"%d\", *{});" args %arg0 : !emitc.ptr<i32>846  } while {847    %r = emitc.expression %1, %2 : (i32, i32) -> i1 {848      %cmp = emitc.cmp eq, %1, %2 : (i32, i32) -> i1849      emitc.yield %cmp : i1850    }851 852    emitc.yield %true: i1853  }854 855  return856}857 858// -----859 860func.func @test_do(%arg0 : !emitc.ptr<i32>) {861  %1 = emitc.literal "1" : i32862  %2 = emitc.literal "2" : i32863 864  // expected-error @+1 {{'emitc.do' op body region must not contain terminator}}865  emitc.do {866    emitc.verbatim "printf(\"%d\", *{});" args %arg0 : !emitc.ptr<i32>867    emitc.yield868  } while {869    %r = emitc.expression %1, %2 : (i32, i32) -> i1 {870      %cmp = emitc.cmp eq, %1, %2 : (i32, i32) -> i1871      emitc.yield %cmp : i1872    }873 874    emitc.yield %r: i1875  }876 877  return878}879 880// -----881 882func.func @test_for_none_block_argument(%arg0: index) {883  // expected-error@+1 {{expected body to have a single block argument for the induction variable}}884  "emitc.for"(%arg0, %arg0, %arg0) (885    {886      emitc.yield887    }888  ) : (index, index, index) -> ()889  return890}891 892// -----893 894func.func @test_for_more_than_one_block_argument(%arg0: index) {895  // expected-error@+1 {{expected body to have a single block argument for the induction variable}}896  "emitc.for"(%arg0, %arg0, %arg0) (897    {898    ^bb0(%i0 : index, %i1 : index):899      emitc.yield900    }901  ) : (index, index, index) -> ()902  return903}904 905// -----906 907func.func @test_for_unmatch_type(%arg0: index) {908  // expected-error@+1 {{expected induction variable to be same type as bounds}}909  "emitc.for"(%arg0, %arg0, %arg0) (910    {911    ^bb0(%i0 : f32):912      emitc.yield913    }914  ) : (index, index, index) -> ()915  return916}917