Debian Codegraph @

tests/cli/gc/invalid.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots %
2
3 ;; https://github.com/WebAssembly/gc/issues/516
4
5 (assert_invalid
6 (module
7 (func (param anyref) (result anyref)
8 ref.null struct
9 local.get 0
10 ;; The label pushes an anyref, even though we really have a structref.
11 br_on_null 0
12 drop
13 br_on_cast_fail 0 structref structref
14 )
15 )
16 "type mismatch: expected structref, found anyref"
17 )
18
19 (assert_invalid
20 (module
21 (func (param anyref) (result anyref)
22 ref.null struct
23 ;; Adding an `unreachable` shouldn't change the fact that the `br_on_null`
24 ;; pushes an `anyref` and the `br_on_cast_fail` expects a `structref`.
25 unreachable
26 local.get 0
27 br_on_null 0
28 drop
29 br_on_cast_fail 0 structref structref
30 )
31 )
32 "type mismatch: expected structref, found anyref"
33 )
34
35 (assert_invalid
36 (module
37 (type $t (func))
38 (func struct.new $t drop))
39 "expected struct type at index 0, found (func)")
40
41 (assert_invalid
42 (module
43 (type $t (struct))
44 (func struct.get $t 100))
45 "unknown field: field index out of bounds")
46
47 (assert_invalid
48 (module
49 (func struct.get 200 100))
50 "unknown type: type index out of bounds")
51
52 (assert_invalid
53 (module
54 (type $t (struct))
55 (func array.new $t drop))
56 "expected array type at index 0, found (struct)")
57
58 (assert_invalid
59 (module
60 (func array.new 100))
61 "unknown type: type index out of bounds")
62
63 (assert_invalid
64 (module
65 (type $t (struct))
66 (func (type $t)))
67 "type index 0 is not a function type")
68
69 (assert_invalid
70 (module
71 (type $t (struct))
72 (func block (type $t) end))
73 "expected func type at index 0, found (struct)")
74
75 (assert_invalid
76 (module
77 (func
78 block $l
79 unreachable
80 br_on_non_null $l
81 end
82 )
83 )
84 "type mismatch: br_on_non_null target has no label types")
85
86 (assert_invalid
87 (module
88 (func
89 block $l (result i32)
90 unreachable
91 br_on_non_null $l
92 end
93 )
94 )
95 "type mismatch: br_on_non_null target does not end with heap type")
96
97 (assert_invalid
98 (module
99 (type $t (struct (field (ref func))))
100 (func
101 struct.new_default $t
102 )
103 )
104 "invalid `struct.new_default`: (ref func) field is not defaultable")
105
106 (assert_invalid
107 (module
108 (type $t (struct (field $f i32)))
109 (func
110 unreachable
111 struct.get_u $t $f
112 )
113 )
114 "cannot use struct.get_u with non-packed storage types")
115
116 (assert_invalid
117 (module
118 (type $t (array (ref func)))
119 (func
120 array.new_default $t
121 )
122 )
123 "invalid `array.new_default`: (ref func) field is not defaultable")
124
125 (assert_invalid
126 (module
127 (type $t (array (ref func)))
128 (func
129 i32.const 0
130 i32.const 0
131 array.new_data $t $d
132 drop
133 )
134 (data $d "xxx")
135 )
136 "array.new_data can only create arrays with numeric and vector elements")
137
138 (assert_invalid
139 (module binary
140 "\00asm" "\01\00\00\00" ;; module header
141
142 "\01\07" ;; type section, 7 bytes
143 "\02" ;; 2 types
144 "\5e\7f\00" ;; (type (array i32))
145 "\60\00\00" ;; (type (func))
146
147 "\03\02" ;; func section, 2 bytes
148 "\01" ;; 1 func
149 "\01" ;; type 1
150
151 "\0a\0d" ;; code section, 13 bytes
152 "\01" ;; 1 count
153 "\0b" ;; 11-byte function
154 "\00" ;; no locals
155 "\41\00" ;; i32.const 0
156 "\41\00" ;; i32.const 0
157 "\fb\09\00\00" ;; array.new_data 0 0
158 "\1a" ;; drop
159 "\0b" ;; end
160
161 "\0b\06" ;; data section, 6 bytes
162 "\01" ;; 1 count
163 "\01" ;; passive
164 "\03xxx" ;; 3 bytes of data "xxx"
165 )
166 "data count section required")
167
168 ;; slightly modified version of the above with a data count section
169 (module binary
170 "\00asm" "\01\00\00\00" ;; module header
171
172 "\01\07" ;; type section, 7 bytes
173 "\02" ;; 2 types
174 "\5e\7f\00" ;; (type (array i32))
175 "\60\00\00" ;; (type (func))
176
177 "\03\02" ;; func section, 2 bytes
178 "\01" ;; 1 func
179 "\01" ;; type 1
180
181 "\0c\01" ;; data count section, 1 byte
182 "\01" ;; 1 data
183
184 "\0a\0d" ;; code section, 13 bytes
185 "\01" ;; 1 count
186 "\0b" ;; 11-byte function
187 "\00" ;; no locals
188 "\41\00" ;; i32.const 0
189 "\41\00" ;; i32.const 0
190 "\fb\09\00\00" ;; array.new_data 0 0
191 "\1a" ;; drop
192 "\0b" ;; end
193
194 "\0b\06" ;; data section, 6 bytes
195 "\01" ;; 1 count
196 "\01" ;; passive
197 "\03xxx" ;; 3 bytes of data "xxx"
198 )
199
200 (assert_invalid
201 (module
202 (type $t (array i8))
203 (func
204 i32.const 0
205 i32.const 0
206 array.new_data $t 100
207 drop
208 )
209 )
210 "unknown data segment 100")
211
212 (assert_invalid
213 (module
214 (type $t (array i8))
215 (func
216 i32.const 0
217 i32.const 0
218 array.new_elem $t $e
219 drop
220 )
221 (elem $e funcref)
222 )
223 "type mismatch: array.new_elem can only create arrays with reference elements")
224
225 (assert_invalid
226 (module
227 (type $t (array (ref any)))
228 (func
229 i32.const 0
230 i32.const 0
231 array.new_elem $t $e
232 drop
233 )
234 (elem $e funcref)
235 )
236 "invalid array.new_elem instruction: element segment 0 type mismatch: expected (ref any), found funcref")
237
238 (assert_invalid
239 (module
240 (type $t1 (array (mut i8)))
241 (type $t2 (array (mut i16)))
242 (func
243 unreachable
244 array.copy $t1 $t2
245 )
246 )
247 "array types do not match: expected i8, found i16")
248
249 (assert_invalid
250 (module
251 (type $t1 (array (mut i16)))
252 (type $t2 (array (mut i8)))
253 (func
254 unreachable
255 array.copy $t1 $t2
256 )
257 )
258 "array types do not match: expected i16, found i8")
259
260 (assert_invalid
261 (module
262 (type $t1 (array (mut i32)))
263 (type $t2 (array (mut i64)))
264 (func
265 unreachable
266 array.copy $t1 $t2
267 )
268 )
269 "array types do not match: expected i32, found i64")
270
271 (assert_invalid
272 (module
273 (type $t1 (array (mut i32)))
274 (type $t2 (array (mut i8)))
275 (func
276 unreachable
277 array.copy $t1 $t2
278 )
279 )
280 "array types do not match: expected i32, found i8")
281
282 (assert_invalid
283 (module
284 (type $t1 (array (mut i8)))
285 (type $t2 (array (mut i32)))
286 (func
287 unreachable
288 array.copy $t1 $t2
289 )
290 )
291 "array types do not match: expected i8, found i32")
292
293 (module
294 (type $t1 (array (mut i16)))
295 (type $t2 (array (mut i16)))
296 (func
297 unreachable
298 array.copy $t1 $t2
299 )
300 )
301
302 (assert_invalid
303 (module
304 (type $t1 (array (mut i8)))
305 (type $t2 (array (mut i32)))
306 (func
307 block
308 unreachable
309 br_on_cast_fail 0 anyref anyref
310 end
311 )
312 )
313 "type mismatch: expected a reference type, found nothing")
314
315 (assert_invalid
316 (module
317 (table 1 externref)
318 (func
319 i32.const 0
320 call_indirect
321 ))
322 "indirect calls must go through a table with type <= funcref")