1// RUN: mlir-tblgen -gen-op-decls -asmformat-error-is-fatal=false -I %S/../../include %s -o=%t 2>&1 | FileCheck %s 2 3include "mlir/IR/OpBase.td" 4 5def TestDialect : Dialect { 6 let name = "test"; 7} 8class TestFormat_Op<string fmt, list<Trait> traits = []> 9 : Op<TestDialect, "format_op", traits> { 10 let assemblyFormat = fmt; 11} 12 13//===----------------------------------------------------------------------===// 14// Format ambiguity caused by attribute followed by colon literal 15//===----------------------------------------------------------------------===// 16 17// Test attribute followed by a colon. 18// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 19def AmbiguousTypeA : TestFormat_Op<[{ 20 $attr `:` attr-dict 21}]>, Arguments<(ins AnyAttr:$attr)>; 22 23// Test optional attribute followed by colon. 24// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 25def AmbiguousTypeB : TestFormat_Op<[{ 26 (`foo` $attr^)? `:` attr-dict 27}]>, Arguments<(ins OptionalAttr<AnyAttr>:$attr)>; 28 29// Test attribute followed by whitespace and then colon. 30// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 31def AmbiguousTypeC : TestFormat_Op<[{ 32 $attr ` ` `:` attr-dict 33}]>, Arguments<(ins AnyAttr:$attr)>; 34 35// Test attribute followed by optional dictionary and then colon. 36// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 37def AmbiguousTypeD : TestFormat_Op<[{ 38 $attr attr-dict `:` 39}]>, Arguments<(ins AnyAttr:$attr)>; 40 41// Test attribute followed by optional group and then colon. 42// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 43def AmbiguousTypeE : TestFormat_Op<[{ 44 $attr ($a^)? `:` attr-dict type($a) 45}]>, Arguments<(ins AnyAttr:$attr, Optional<I32>:$a)>; 46 47// Test attribute followed by optional group with literals and then colon. 48// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 49def AmbiguousTypeF : TestFormat_Op<[{ 50 $attr (`(` $a^ `)`)? `:` attr-dict (`(` type($a)^ `)`)? 51}]>, Arguments<(ins AnyAttr:$attr, Optional<I32>:$a)>; 52 53// Test attribute followed by optional group with else group. 54// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 55def AmbiguousTypeG : TestFormat_Op<[{ 56 $attr (`(` $a^ `)`) : (`foo`)? `:` attr-dict (`(` type($a)^ `)`)? 57}]>, Arguments<(ins AnyAttr:$attr, Optional<I32>:$a)>; 58 59// Test attribute followed by optional group with colon. 60// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 61def AmbiguousTypeH : TestFormat_Op<[{ 62 $attr (`:` $a^ `)`)? attr-dict (`(` type($a)^ `)`)? 63}]>, Arguments<(ins AnyAttr:$attr, Optional<I32>:$a)>; 64 65// Test attribute followed by optional group with colon in else group. 66// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 67def AmbiguousTypeI : TestFormat_Op<[{ 68 $attr (`(` $a^ `)`) : (`:`)? attr-dict (`(` type($a)^ `)`)? 69}]>, Arguments<(ins AnyAttr:$attr, Optional<I32>:$a)>; 70 71// Test attribute followed by two optional groups and then a colon. 72// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 73def AmbiguousTypeJ : TestFormat_Op<[{ 74 $attr (`(` $a^ type($a) `)`) : (`foo`)? ` ` attr-dict (`(` $b^ type($b) `)`)? 75 `:` 76}], [AttrSizedOperandSegments]>, 77 Arguments<(ins AnyAttr:$attr, Optional<I32>:$a, Optional<I32>:$b)>; 78 79// Test attribute followed by two optional groups and then a colon in the else 80// group. 81// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 82def AmbiguousTypeK : TestFormat_Op<[{ 83 $attr (`(` $a^ type($a) `)`) : (`foo`)? ` ` attr-dict 84 (`(` $b^ type($b) `)`) : (`:`)? 85}], [AttrSizedOperandSegments]>, 86 Arguments<(ins AnyAttr:$attr, Optional<I32>:$a, Optional<I32>:$b)>; 87 88// Test attribute followed by two optional groups with guarded colons but then a 89// colon. 90// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 91def AmbiguousTypeL : TestFormat_Op<[{ 92 $attr (`(` $a^ `:` type($a) `)`) : (`foo` `:`)? ` ` attr-dict 93 (`(` $b^ `:` type($b) `)`) : (`foo` `:`)? `:` 94}], [AttrSizedOperandSegments]>, 95 Arguments<(ins AnyAttr:$attr, Optional<I32>:$a, Optional<I32>:$b)>; 96 97// Test optional attribute followed by optional groups with a colon along one 98// path. 99// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 100def AmbiguousTypeM : TestFormat_Op<[{ 101 (`(` $attr^ ` `)? (`(` $a^ `:` type($a) `)`) : (`foo` `:`)? ` ` attr-dict 102 (`(` $b^ `:` type($b) `)`) : (`foo` `:`)? `:` 103}], [AttrSizedOperandSegments]>, 104 Arguments<(ins OptionalAttr<AnyAttr>:$attr, Optional<I32>:$a, 105 Optional<I32>:$b)>; 106 107// Test optional attribute followed by optional groups with a colon along one 108// path inside an optional group. 109// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 110def AmbiguousTypeN : TestFormat_Op<[{ 111 (`(` $attr^ ` `)? (`(` $a^ `:` type($a) `)`) : (`foo` `:`)? ` ` attr-dict 112 (`(` $b^ `:` type($b) `)`) : (`:`)? 113}], [AttrSizedOperandSegments]>, 114 Arguments<(ins OptionalAttr<AnyAttr>:$attr, Optional<I32>:$a, 115 Optional<I32>:$b)>; 116 117// Test attribute followed by optional attribute, operand, successor, region, 118// and a colon. 119// CHECK: error: format ambiguity caused by `:` literal found after attribute `attr` 120def AmbiguousTypeO : TestFormat_Op<[{ 121 $attr attr-dict $a $b $c $d $e `:` 122}], [AttrSizedOperandSegments]> { 123 let arguments = (ins AnyAttr:$attr, OptionalAttr<I32Attr>:$a, 124 Optional<I32>:$b, Variadic<I32>:$c); 125 let successors = (successor VariadicSuccessor<AnySuccessor>:$d); 126 let regions = (region VariadicRegion<AnyRegion>:$e); 127} 128 129// Test two attributes, where the second one is ambiguous. 130// CHECK: error: format ambiguity caused by `:` literal found after attribute `b` 131def AmbiguousTypeP : TestFormat_Op<[{ 132 $a attr-dict `(` `:` $b (`:` $c^)? 133}]>, Arguments<(ins AnyAttr:$a, AnyAttr:$b, Optional<I32>:$c)>; 134 135// Test two attributes, where the second one is ambiguous. 136// CHECK: error: format ambiguity caused by `:` literal found after attribute `b` 137def AmbiguousTypeQ : TestFormat_Op<[{ 138 $a attr-dict (`(` $c^ `:`)? `(` `:` $b `:` 139}]>, Arguments<(ins AnyAttr:$a, AnyAttr:$b, Optional<I32>:$c)>; 140 141// CHECK-NOT: error 142 143// Test attribute followed by two optional groups with guarded colons. 144def ValidTypeA : TestFormat_Op<[{ 145 $attr (`(` $a^ `:` type($a) `)`) : (`foo` `:`)? ` ` attr-dict 146 (`(` $b^ `:` type($b) `)`) : (`foo` `:`)? ` ` `(` `:` 147}], [AttrSizedOperandSegments]>, 148 Arguments<(ins AnyAttr:$attr, Optional<I32>:$a, Optional<I32>:$b)>; 149 150// Test optional attribute followed by two optional groups with guarded colons. 151def ValidTypeB : TestFormat_Op<[{ 152 (`(` $attr^ ` `)? (`(` $a^ `:` type($a) `)`) : (`foo` `:`)? ` ` attr-dict 153 (`(` $b^ `:` type($b) `)`) : (`foo` `:`)? ` ` `(` `:` 154}], [AttrSizedOperandSegments]>, 155 Arguments<(ins OptionalAttr<AnyAttr>:$attr, Optional<I32>:$a, 156 Optional<I32>:$b)>; 157 158// Test optional attribute guarded colon along within segment. 159def ValidTypeC : TestFormat_Op<[{ 160 (`(` $attr^ `)`) : (`:`)? attr-dict `:` 161}]>, Arguments<(ins OptionalAttr<AnyAttr>:$attr)>; 162 163// Test optional group guard blocks colon. 164def ValidTypeD : TestFormat_Op<[{ 165 $a attr-dict ($c^ `:`)? 166}]>, Arguments<(ins AnyAttr:$a, Optional<I32>:$c)>; 167