1 // RUN: mlir-tblgen -gen-op-decls -asmformat-error-is-fatal=false -I %S/../../include %s -o=%t 2>&1 | FileCheck %s
3 include "mlir/IR/OpBase.td"
5 def TestDialect : Dialect {
8 class TestFormat_Op<string fmt, list<Trait> traits = []>
9 : Op<TestDialect, "format_op", traits> {
10 let assemblyFormat = fmt;
13 //===----------------------------------------------------------------------===//
14 // Format ambiguity caused by attribute followed by colon literal
15 //===----------------------------------------------------------------------===//
17 // Test attribute followed by a colon.
18 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
19 def AmbiguousTypeA : TestFormat_Op<[{
21 }]>, Arguments<(ins AnyAttr:$attr)>;
23 // Test optional attribute followed by colon.
24 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
25 def AmbiguousTypeB : TestFormat_Op<[{
26 (`foo` $attr^)? `:` attr-dict
27 }]>, Arguments<(ins OptionalAttr<AnyAttr>:$attr)>;
29 // Test attribute followed by whitespace and then colon.
30 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
31 def AmbiguousTypeC : TestFormat_Op<[{
32 $attr ` ` `:` attr-dict
33 }]>, Arguments<(ins AnyAttr:$attr)>;
35 // Test attribute followed by optional dictionary and then colon.
36 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
37 def AmbiguousTypeD : TestFormat_Op<[{
39 }]>, Arguments<(ins AnyAttr:$attr)>;
41 // Test attribute followed by optional group and then colon.
42 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
43 def AmbiguousTypeE : TestFormat_Op<[{
44 $attr ($a^)? `:` attr-dict type($a)
45 }]>, Arguments<(ins AnyAttr:$attr, Optional<I32>:$a)>;
47 // Test attribute followed by optional group with literals and then colon.
48 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
49 def AmbiguousTypeF : TestFormat_Op<[{
50 $attr (`(` $a^ `)`)? `:` attr-dict (`(` type($a)^ `)`)?
51 }]>, Arguments<(ins AnyAttr:$attr, Optional<I32>:$a)>;
53 // Test attribute followed by optional group with else group.
54 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
55 def AmbiguousTypeG : TestFormat_Op<[{
56 $attr (`(` $a^ `)`) : (`foo`)? `:` attr-dict (`(` type($a)^ `)`)?
57 }]>, Arguments<(ins AnyAttr:$attr, Optional<I32>:$a)>;
59 // Test attribute followed by optional group with colon.
60 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
61 def AmbiguousTypeH : TestFormat_Op<[{
62 $attr (`:` $a^ `)`)? attr-dict (`(` type($a)^ `)`)?
63 }]>, Arguments<(ins AnyAttr:$attr, Optional<I32>:$a)>;
65 // Test attribute followed by optional group with colon in else group.
66 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
67 def AmbiguousTypeI : TestFormat_Op<[{
68 $attr (`(` $a^ `)`) : (`:`)? attr-dict (`(` type($a)^ `)`)?
69 }]>, Arguments<(ins AnyAttr:$attr, Optional<I32>:$a)>;
71 // Test attribute followed by two optional groups and then a colon.
72 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
73 def AmbiguousTypeJ : TestFormat_Op<[{
74 $attr (`(` $a^ type($a) `)`) : (`foo`)? ` ` attr-dict (`(` $b^ type($b) `)`)?
76 }], [AttrSizedOperandSegments]>,
77 Arguments<(ins AnyAttr:$attr, Optional<I32>:$a, Optional<I32>:$b)>;
79 // Test attribute followed by two optional groups and then a colon in the else
81 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
82 def 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)>;
88 // Test attribute followed by two optional groups with guarded colons but then a
90 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
91 def 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)>;
97 // Test optional attribute followed by optional groups with a colon along one
99 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
100 def 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,
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`
110 def 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,
117 // Test attribute followed by optional attribute, operand, successor, region,
119 // CHECK: error: format ambiguity caused by `:` literal found after attribute `attr`
120 def 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);
129 // Test two attributes, where the second one is ambiguous.
130 // CHECK: error: format ambiguity caused by `:` literal found after attribute `b`
131 def AmbiguousTypeP : TestFormat_Op<[{
132 $a attr-dict `(` `:` $b (`:` $c^)?
133 }]>, Arguments<(ins AnyAttr:$a, AnyAttr:$b, Optional<I32>:$c)>;
135 // Test two attributes, where the second one is ambiguous.
136 // CHECK: error: format ambiguity caused by `:` literal found after attribute `b`
137 def AmbiguousTypeQ : TestFormat_Op<[{
138 $a attr-dict (`(` $c^ `:`)? `(` `:` $b `:`
139 }]>, Arguments<(ins AnyAttr:$a, AnyAttr:$b, Optional<I32>:$c)>;
143 // Test attribute followed by two optional groups with guarded colons.
144 def 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)>;
150 // Test optional attribute followed by two optional groups with guarded colons.
151 def 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,
158 // Test optional attribute guarded colon along within segment.
159 def ValidTypeC : TestFormat_Op<[{
160 (`(` $attr^ `)`) : (`:`)? attr-dict `:`
161 }]>, Arguments<(ins OptionalAttr<AnyAttr>:$attr)>;
163 // Test optional group guard blocks colon.
164 def ValidTypeD : TestFormat_Op<[{
165 $a attr-dict ($c^ `:`)?
166 }]>, Arguments<(ins AnyAttr:$a, Optional<I32>:$c)>;