150
|
1 // RUN: mlir-opt %s -split-input-file -verify-diagnostics | FileCheck %s
|
|
2
|
|
3 //===----------------------------------------------------------------------===//
|
|
4 // Test Non-negative Int Attr
|
|
5 //===----------------------------------------------------------------------===//
|
|
6
|
|
7 func @non_negative_int_attr_pass() {
|
|
8 // CHECK: test.non_negative_int_attr
|
|
9 "test.non_negative_int_attr"() {i32attr = 5 : i32, i64attr = 10 : i64} : () -> ()
|
|
10 // CHECK: test.non_negative_int_attr
|
|
11 "test.non_negative_int_attr"() {i32attr = 0 : i32, i64attr = 0 : i64} : () -> ()
|
|
12 return
|
|
13 }
|
|
14
|
|
15 // -----
|
|
16
|
|
17 func @negative_int_attr_fail() {
|
|
18 // expected-error @+1 {{'i32attr' failed to satisfy constraint: non-negative 32-bit integer attribute}}
|
|
19 "test.non_negative_int_attr"() {i32attr = -5 : i32, i64attr = 10 : i64} : () -> ()
|
|
20 return
|
|
21 }
|
|
22
|
|
23 // -----
|
|
24
|
|
25 func @negative_int_attr_fail() {
|
|
26 // expected-error @+1 {{'i64attr' failed to satisfy constraint: non-negative 64-bit integer attribute}}
|
|
27 "test.non_negative_int_attr"() {i32attr = 5 : i32, i64attr = -10 : i64} : () -> ()
|
|
28 return
|
|
29 }
|
|
30
|
|
31 // -----
|
|
32
|
|
33 //===----------------------------------------------------------------------===//
|
|
34 // Test Positive Int Attr
|
|
35 //===----------------------------------------------------------------------===//
|
|
36
|
|
37 func @positive_int_attr_pass() {
|
|
38 // CHECK: test.positive_int_attr
|
|
39 "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = 10 : i64} : () -> ()
|
|
40 return
|
|
41 }
|
|
42
|
|
43 // -----
|
|
44
|
|
45 func @positive_int_attr_fail() {
|
|
46 // expected-error @+1 {{'i32attr' failed to satisfy constraint: positive 32-bit integer attribute}}
|
|
47 "test.positive_int_attr"() {i32attr = 0 : i32, i64attr = 5: i64} : () -> ()
|
|
48 return
|
|
49 }
|
|
50
|
|
51 // -----
|
|
52
|
|
53 func @positive_int_attr_fail() {
|
|
54 // expected-error @+1 {{'i64attr' failed to satisfy constraint: positive 64-bit integer attribute}}
|
|
55 "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = 0: i64} : () -> ()
|
|
56 return
|
|
57 }
|
|
58
|
|
59 // -----
|
|
60
|
|
61 func @positive_int_attr_fail() {
|
|
62 // expected-error @+1 {{'i32attr' failed to satisfy constraint: positive 32-bit integer attribute}}
|
|
63 "test.positive_int_attr"() {i32attr = -10 : i32, i64attr = 5 : i64} : () -> ()
|
|
64 return
|
|
65 }
|
|
66
|
|
67 // -----
|
|
68
|
|
69 func @positive_int_attr_fail() {
|
|
70 // expected-error @+1 {{'i64attr' failed to satisfy constraint: positive 64-bit integer attribute}}
|
|
71 "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = -10 : i64} : () -> ()
|
|
72 return
|
|
73 }
|
|
74
|
|
75 // -----
|
|
76
|
|
77 //===----------------------------------------------------------------------===//
|
|
78 // Test TypeArrayAttr
|
|
79 //===----------------------------------------------------------------------===//
|
|
80
|
|
81 func @correct_type_array_attr_pass() {
|
|
82 // CHECK: test.type_array_attr
|
|
83 "test.type_array_attr"() {attr = [i32, f32]} : () -> ()
|
|
84 return
|
|
85 }
|
|
86
|
|
87 // -----
|
|
88
|
|
89 func @non_type_in_type_array_attr_fail() {
|
|
90 // expected-error @+1 {{'attr' failed to satisfy constraint: type array attribute}}
|
|
91 "test.type_array_attr"() {attr = [i32, 5 : i64]} : () -> ()
|
|
92 return
|
|
93 }
|
|
94
|
|
95 // -----
|
|
96
|
|
97 //===----------------------------------------------------------------------===//
|
|
98 // Test StringAttr with custom type
|
|
99 //===----------------------------------------------------------------------===//
|
|
100
|
|
101 // CHECK-LABEL: func @string_attr_custom_type
|
|
102 func @string_attr_custom_type() {
|
|
103 // CHECK: "string_data" : !foo.string
|
|
104 test.string_attr_with_type "string_data"
|
|
105 return
|
|
106 }
|
|
107
|
|
108 // -----
|
|
109
|
|
110 //===----------------------------------------------------------------------===//
|
|
111 // Test StrEnumAttr
|
|
112 //===----------------------------------------------------------------------===//
|
|
113
|
|
114 // CHECK-LABEL: func @allowed_cases_pass
|
|
115 func @allowed_cases_pass() {
|
|
116 // CHECK: test.str_enum_attr
|
|
117 %0 = "test.str_enum_attr"() {attr = "A"} : () -> i32
|
|
118 // CHECK: test.str_enum_attr
|
|
119 %1 = "test.str_enum_attr"() {attr = "B"} : () -> i32
|
|
120 return
|
|
121 }
|
|
122
|
|
123 // -----
|
|
124
|
|
125 func @disallowed_case_fail() {
|
|
126 // expected-error @+1 {{allowed string cases: 'A', 'B'}}
|
|
127 %0 = "test.str_enum_attr"() {attr = 7: i32} : () -> i32
|
|
128 return
|
|
129 }
|
|
130
|
|
131 // -----
|
|
132
|
|
133 //===----------------------------------------------------------------------===//
|
|
134 // Test I32EnumAttr
|
|
135 //===----------------------------------------------------------------------===//
|
|
136
|
|
137 // CHECK-LABEL: func @allowed_cases_pass
|
|
138 func @allowed_cases_pass() {
|
|
139 // CHECK: test.i32_enum_attr
|
|
140 %0 = "test.i32_enum_attr"() {attr = 5: i32} : () -> i32
|
|
141 // CHECK: test.i32_enum_attr
|
|
142 %1 = "test.i32_enum_attr"() {attr = 10: i32} : () -> i32
|
|
143 return
|
|
144 }
|
|
145
|
|
146 // -----
|
|
147
|
|
148 func @disallowed_case7_fail() {
|
|
149 // expected-error @+1 {{allowed 32-bit integer cases: 5, 10}}
|
|
150 %0 = "test.i32_enum_attr"() {attr = 7: i32} : () -> i32
|
|
151 return
|
|
152 }
|
|
153
|
|
154 // -----
|
|
155
|
|
156 func @disallowed_case7_fail() {
|
|
157 // expected-error @+1 {{allowed 32-bit integer cases: 5, 10}}
|
|
158 %0 = "test.i32_enum_attr"() {attr = 5: i64} : () -> i32
|
|
159 return
|
|
160 }
|
|
161
|
|
162 // -----
|
|
163
|
|
164 //===----------------------------------------------------------------------===//
|
|
165 // Test I64EnumAttr
|
|
166 //===----------------------------------------------------------------------===//
|
|
167
|
|
168 // CHECK-LABEL: func @allowed_cases_pass
|
|
169 func @allowed_cases_pass() {
|
|
170 // CHECK: test.i64_enum_attr
|
|
171 %0 = "test.i64_enum_attr"() {attr = 5: i64} : () -> i32
|
|
172 // CHECK: test.i64_enum_attr
|
|
173 %1 = "test.i64_enum_attr"() {attr = 10: i64} : () -> i32
|
|
174 return
|
|
175 }
|
|
176
|
|
177 // -----
|
|
178
|
|
179 func @disallowed_case7_fail() {
|
|
180 // expected-error @+1 {{allowed 64-bit integer cases: 5, 10}}
|
|
181 %0 = "test.i64_enum_attr"() {attr = 7: i64} : () -> i32
|
|
182 return
|
|
183 }
|
|
184
|
|
185 // -----
|
|
186
|
|
187 func @disallowed_case7_fail() {
|
|
188 // expected-error @+1 {{allowed 64-bit integer cases: 5, 10}}
|
|
189 %0 = "test.i64_enum_attr"() {attr = 5: i32} : () -> i32
|
|
190 return
|
|
191 }
|
|
192
|
|
193 // -----
|
|
194
|
|
195 //===----------------------------------------------------------------------===//
|
|
196 // Test FloatElementsAttr
|
|
197 //===----------------------------------------------------------------------===//
|
|
198
|
|
199 func @correct_type_pass() {
|
|
200 "test.float_elements_attr"() {
|
|
201 // CHECK: scalar_f32_attr = dense<5.000000e+00> : tensor<2xf32>
|
|
202 // CHECK: tensor_f64_attr = dense<6.000000e+00> : tensor<4x8xf64>
|
|
203 scalar_f32_attr = dense<5.0> : tensor<2xf32>,
|
|
204 tensor_f64_attr = dense<6.0> : tensor<4x8xf64>
|
|
205 } : () -> ()
|
|
206 return
|
|
207 }
|
|
208
|
|
209 // -----
|
|
210
|
|
211 func @wrong_element_type_pass() {
|
|
212 // expected-error @+1 {{failed to satisfy constraint: 32-bit float elements attribute of shape [2]}}
|
|
213 "test.float_elements_attr"() {
|
|
214 scalar_f32_attr = dense<5.0> : tensor<2xf64>,
|
|
215 tensor_f64_attr = dense<6.0> : tensor<4x8xf64>
|
|
216 } : () -> ()
|
|
217 return
|
|
218 }
|
|
219
|
|
220 // -----
|
|
221
|
|
222 func @correct_type_pass() {
|
|
223 // expected-error @+1 {{failed to satisfy constraint: 64-bit float elements attribute of shape [4, 8]}}
|
|
224 "test.float_elements_attr"() {
|
|
225 scalar_f32_attr = dense<5.0> : tensor<2xf32>,
|
|
226 tensor_f64_attr = dense<6.0> : tensor<4xf64>
|
|
227 } : () -> ()
|
|
228 return
|
|
229 }
|
|
230
|
|
231 // -----
|
|
232
|
|
233 //===----------------------------------------------------------------------===//
|
|
234 // Test SymbolRefAttr
|
|
235 //===----------------------------------------------------------------------===//
|
|
236
|
|
237 func @fn() { return }
|
|
238
|
|
239 // CHECK: test.symbol_ref_attr
|
|
240 "test.symbol_ref_attr"() {symbol = @fn} : () -> ()
|
|
241
|
|
242 // -----
|
|
243
|
|
244 // expected-error @+1 {{referencing to a 'FuncOp' symbol}}
|
|
245 "test.symbol_ref_attr"() {symbol = @foo} : () -> ()
|
|
246
|
|
247 // -----
|
|
248
|
|
249 //===----------------------------------------------------------------------===//
|
|
250 // Test IntElementsAttr
|
|
251 //===----------------------------------------------------------------------===//
|
|
252
|
|
253 func @correct_type_pass() {
|
|
254 "test.int_elements_attr"() {
|
|
255 // CHECK: matrix_i64_attr = dense<6> : tensor<4x8xi64>
|
|
256 // CHECK: vector_i32_attr = dense<5> : tensor<2xi32>
|
|
257 matrix_i64_attr = dense<6> : tensor<4x8xi64>,
|
|
258 vector_i32_attr = dense<5> : tensor<2xi32>
|
|
259 } : () -> ()
|
|
260 return
|
|
261 }
|
|
262
|
|
263 // -----
|
|
264
|
|
265 func @wrong_element_type_fail() {
|
|
266 // expected-error @+1 {{failed to satisfy constraint: 32-bit int elements attribute of shape [2]}}
|
|
267 "test.int_elements_attr"() {
|
|
268 matrix_i64_attr = dense<6> : tensor<4x8xi64>,
|
|
269 vector_i32_attr = dense<5> : tensor<2xi64>
|
|
270 } : () -> ()
|
|
271 return
|
|
272 }
|
|
273
|
|
274 // -----
|
|
275
|
|
276 func @wrong_shape_fail() {
|
|
277 // expected-error @+1 {{failed to satisfy constraint: 64-bit int elements attribute of shape [4, 8]}}
|
|
278 "test.int_elements_attr"() {
|
|
279 matrix_i64_attr = dense<6> : tensor<4xi64>,
|
|
280 vector_i32_attr = dense<5> : tensor<2xi32>
|
|
281 } : () -> ()
|
|
282 return
|
|
283 }
|
|
284
|
|
285 // -----
|
|
286
|
|
287 func @wrong_shape_fail() {
|
|
288 // expected-error @+1 {{failed to satisfy constraint: 32-bit int elements attribute of shape [2]}}
|
|
289 "test.int_elements_attr"() {
|
|
290 matrix_i64_attr = dense<6> : tensor<4x8xi64>,
|
|
291 vector_i32_attr = dense<5> : tensor<i32>
|
|
292 } : () -> ()
|
|
293 return
|
|
294 }
|
|
295
|