Debian Codegraph @

internal/integration_test/spectest/v2/testdata/data.wast

raw
1 ;; Test the data section
2
3 ;; Syntax
4
5 (module
6 (memory $m 1)
7 (data (i32.const 0))
8 (data (i32.const 1) "a" "" "bcd")
9 (data (offset (i32.const 0)))
10 (data (offset (i32.const 0)) "" "a" "bc" "")
11 (data (memory 0) (i32.const 0))
12 (data (memory 0x0) (i32.const 1) "a" "" "bcd")
13 (data (memory 0x000) (offset (i32.const 0)))
14 (data (memory 0) (offset (i32.const 0)) "" "a" "bc" "")
15 (data (memory $m) (i32.const 0))
16 (data (memory $m) (i32.const 1) "a" "" "bcd")
17 (data (memory $m) (offset (i32.const 0)))
18 (data (memory $m) (offset (i32.const 0)) "" "a" "bc" "")
19 (data)
20 (data "a" "" "bcd")
21 (data $d1 (i32.const 0))
22 (data $d2 (i32.const 1) "a" "" "bcd")
23 (data $d3 (offset (i32.const 0)))
24 (data $d4 (offset (i32.const 0)) "" "a" "bc" "")
25 (data $d5 (memory 0) (i32.const 0))
26 (data $d6 (memory 0x0) (i32.const 1) "a" "" "bcd")
27 (data $d7 (memory 0x000) (offset (i32.const 0)))
28 (data $d8 (memory 0) (offset (i32.const 0)) "" "a" "bc" "")
29 (data $d9 (memory $m) (i32.const 0))
30 (data $d10 (memory $m) (i32.const 1) "a" "" "bcd")
31 (data $d11 (memory $m) (offset (i32.const 0)))
32 (data $d12 (memory $m) (offset (i32.const 0)) "" "a" "bc" "")
33 (data $d13)
34 (data $d14 "a" "" "bcd")
35 )
36
37 ;; Basic use
38
39 (module
40 (memory 1)
41 (data (i32.const 0) "a")
42 )
43 (module
44 (import "spectest" "memory" (memory 1))
45 (data (i32.const 0) "a")
46 )
47
48 (module
49 (memory 1)
50 (data (i32.const 0) "a")
51 (data (i32.const 3) "b")
52 (data (i32.const 100) "cde")
53 (data (i32.const 5) "x")
54 (data (i32.const 3) "c")
55 )
56 (module
57 (import "spectest" "memory" (memory 1))
58 (data (i32.const 0) "a")
59 (data (i32.const 1) "b")
60 (data (i32.const 2) "cde")
61 (data (i32.const 3) "f")
62 (data (i32.const 2) "g")
63 (data (i32.const 1) "h")
64 )
65
66 (module
67 (global (import "spectest" "global_i32") i32)
68 (memory 1)
69 (data (global.get 0) "a")
70 )
71 (module
72 (global (import "spectest" "global_i32") i32)
73 (import "spectest" "memory" (memory 1))
74 (data (global.get 0) "a")
75 )
76
77 (module
78 (global $g (import "spectest" "global_i32") i32)
79 (memory 1)
80 (data (global.get $g) "a")
81 )
82 (module
83 (global $g (import "spectest" "global_i32") i32)
84 (import "spectest" "memory" (memory 1))
85 (data (global.get $g) "a")
86 )
87
88 (assert_invalid
89 (module (memory 1) (global i32 (i32.const 0)) (data (global.get 0) "a"))
90 "unknown global"
91 )
92 (assert_invalid
93 (module (memory 1) (global $g i32 (i32.const 0)) (data (global.get $g) "a"))
94 "unknown global"
95 )
96
97
98 ;; Corner cases
99
100 (module
101 (memory 1)
102 (data (i32.const 0) "a")
103 (data (i32.const 0xffff) "b")
104 )
105 (module
106 (import "spectest" "memory" (memory 1))
107 (data (i32.const 0) "a")
108 (data (i32.const 0xffff) "b")
109 )
110
111 (module
112 (memory 2)
113 (data (i32.const 0x1_ffff) "a")
114 )
115
116 (module
117 (memory 0)
118 (data (i32.const 0))
119 )
120 (module
121 (import "spectest" "memory" (memory 0))
122 (data (i32.const 0))
123 )
124
125 (module
126 (memory 0 0)
127 (data (i32.const 0))
128 )
129
130 (module
131 (memory 1)
132 (data (i32.const 0x1_0000) "")
133 )
134
135 (module
136 (memory 0)
137 (data (i32.const 0) "" "")
138 )
139 (module
140 (import "spectest" "memory" (memory 0))
141 (data (i32.const 0) "" "")
142 )
143
144 (module
145 (memory 0 0)
146 (data (i32.const 0) "" "")
147 )
148
149 (module
150 (import "spectest" "memory" (memory 0))
151 (data (i32.const 0) "a")
152 )
153
154 (module
155 (import "spectest" "memory" (memory 0 3))
156 (data (i32.const 0) "a")
157 )
158
159 (module
160 (global (import "spectest" "global_i32") i32)
161 (import "spectest" "memory" (memory 0))
162 (data (global.get 0) "a")
163 )
164
165 (module
166 (global (import "spectest" "global_i32") i32)
167 (import "spectest" "memory" (memory 0 3))
168 (data (global.get 0) "a")
169 )
170
171 (module
172 (import "spectest" "memory" (memory 0))
173 (data (i32.const 1) "a")
174 )
175
176 (module
177 (import "spectest" "memory" (memory 0 3))
178 (data (i32.const 1) "a")
179 )
180
181 ;; Invalid bounds for data
182
183 (assert_trap
184 (module
185 (memory 0)
186 (data (i32.const 0) "a")
187 )
188 "out of bounds memory access"
189 )
190
191 (assert_trap
192 (module
193 (memory 0 0)
194 (data (i32.const 0) "a")
195 )
196 "out of bounds memory access"
197 )
198
199 (assert_trap
200 (module
201 (memory 0 1)
202 (data (i32.const 0) "a")
203 )
204 "out of bounds memory access"
205 )
206 (assert_trap
207 (module
208 (memory 0)
209 (data (i32.const 1))
210 )
211 "out of bounds memory access"
212 )
213 (assert_trap
214 (module
215 (memory 0 1)
216 (data (i32.const 1))
217 )
218 "out of bounds memory access"
219 )
220
221 ;; This seems to cause a time-out on Travis.
222 (;assert_unlinkable
223 (module
224 (memory 0x10000)
225 (data (i32.const 0xffffffff) "ab")
226 )
227 "" ;; either out of memory or out of bounds
228 ;)
229
230 (assert_trap
231 (module
232 (global (import "spectest" "global_i32") i32)
233 (memory 0)
234 (data (global.get 0) "a")
235 )
236 "out of bounds memory access"
237 )
238
239 (assert_trap
240 (module
241 (memory 1 2)
242 (data (i32.const 0x1_0000) "a")
243 )
244 "out of bounds memory access"
245 )
246 (assert_trap
247 (module
248 (import "spectest" "memory" (memory 1))
249 (data (i32.const 0x1_0000) "a")
250 )
251 "out of bounds memory access"
252 )
253
254 (assert_trap
255 (module
256 (memory 2)
257 (data (i32.const 0x2_0000) "a")
258 )
259 "out of bounds memory access"
260 )
261
262 (assert_trap
263 (module
264 (memory 2 3)
265 (data (i32.const 0x2_0000) "a")
266 )
267 "out of bounds memory access"
268 )
269
270 (assert_trap
271 (module
272 (memory 1)
273 (data (i32.const -1) "a")
274 )
275 "out of bounds memory access"
276 )
277 (assert_trap
278 (module
279 (import "spectest" "memory" (memory 1))
280 (data (i32.const -1) "a")
281 )
282 "out of bounds memory access"
283 )
284
285 (assert_trap
286 (module
287 (memory 2)
288 (data (i32.const -100) "a")
289 )
290 "out of bounds memory access"
291 )
292 (assert_trap
293 (module
294 (import "spectest" "memory" (memory 1))
295 (data (i32.const -100) "a")
296 )
297 "out of bounds memory access"
298 )
299
300 ;; Data without memory
301
302 (assert_invalid
303 (module
304 (data (i32.const 0) "")
305 )
306 "unknown memory"
307 )
308
309 ;; Data segment with memory index 1 (only memory 0 available)
310 (assert_invalid
311 (module binary
312 "\00asm" "\01\00\00\00"
313 "\05\03\01" ;; memory section
314 "\00\00" ;; memory 0
315 "\0b\07\01" ;; data section
316 "\02\01\41\00\0b" ;; active data segment 0 for memory 1
317 "\00" ;; empty vec(byte)
318 )
319 "unknown memory 1"
320 )
321
322 ;; Data segment with memory index 0 (no memory section)
323 (assert_invalid
324 (module binary
325 "\00asm" "\01\00\00\00"
326 "\0b\06\01" ;; data section
327 "\00\41\00\0b" ;; active data segment 0 for memory 0
328 "\00" ;; empty vec(byte)
329 )
330 "unknown memory 0"
331 )
332
333 ;; Data segment with memory index 1 (no memory section)
334 (assert_invalid
335 (module binary
336 "\00asm" "\01\00\00\00"
337 "\0b\07\01" ;; data section
338 "\02\01\41\00\0b" ;; active data segment 0 for memory 1
339 "\00" ;; empty vec(byte)
340 )
341 "unknown memory 1"
342 )
343
344 ;; Data segment with memory index 1 and vec(byte) as above,
345 ;; only memory 0 available.
346 (assert_invalid
347 (module binary
348 "\00asm" "\01\00\00\00"
349 "\05\03\01" ;; memory section
350 "\00\00" ;; memory 0
351 "\0b\45\01" ;; data section
352 "\02" ;; active segment
353 "\01" ;; memory index
354 "\41\00\0b" ;; offset constant expression
355 "\3e" ;; vec(byte) length
356 "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f"
357 "\10\11\12\13\14\15\16\17\18\19\1a\1b\1c\1d\1e\1f"
358 "\20\21\22\23\24\25\26\27\28\29\2a\2b\2c\2d\2e\2f"
359 "\30\31\32\33\34\35\36\37\38\39\3a\3b\3c\3d"
360 )
361 "unknown memory 1"
362 )
363
364 ;; Data segment with memory index 1 and specially crafted vec(byte) after.
365 ;; This is to detect incorrect validation where memory index is interpreted
366 ;; as a flag followed by "\41" interpreted as the size of vec(byte)
367 ;; with the expected number of bytes following.
368 (assert_invalid
369 (module binary
370 "\00asm" "\01\00\00\00"
371 "\0b\45\01" ;; data section
372 "\02" ;; active segment
373 "\01" ;; memory index
374 "\41\00\0b" ;; offset constant expression
375 "\3e" ;; vec(byte) length
376 "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f"
377 "\10\11\12\13\14\15\16\17\18\19\1a\1b\1c\1d\1e\1f"
378 "\20\21\22\23\24\25\26\27\28\29\2a\2b\2c\2d\2e\2f"
379 "\30\31\32\33\34\35\36\37\38\39\3a\3b\3c\3d"
380 )
381 "unknown memory 1"
382 )
383
384
385 ;; Invalid offsets
386
387 (assert_invalid
388 (module
389 (memory 1)
390 (data (i64.const 0))
391 )
392 "type mismatch"
393 )
394
395 (assert_invalid
396 (module
397 (memory 1)
398 (data (ref.null func))
399 )
400 "type mismatch"
401 )
402
403 (assert_invalid
404 (module
405 (memory 1)
406 (data (offset (;empty instruction sequence;)))
407 )
408 "type mismatch"
409 )
410
411 (assert_invalid
412 (module
413 (memory 1)
414 (data (offset (i32.const 0) (i32.const 0)))
415 )
416 "type mismatch"
417 )
418
419 (assert_invalid
420 (module
421 (global (import "test" "global-i32") i32)
422 (memory 1)
423 (data (offset (global.get 0) (global.get 0)))
424 )
425 "type mismatch"
426 )
427
428 (assert_invalid
429 (module
430 (global (import "test" "global-i32") i32)
431 (memory 1)
432 (data (offset (global.get 0) (i32.const 0)))
433 )
434 "type mismatch"
435 )
436
437 (assert_invalid
438 (module
439 (memory 1)
440 (data (i32.ctz (i32.const 0)))
441 )
442 "constant expression required"
443 )
444
445 (assert_invalid
446 (module
447 (memory 1)
448 (data (nop))
449 )
450 "constant expression required"
451 )
452
453 (assert_invalid
454 (module
455 (memory 1)
456 (data (offset (nop) (i32.const 0)))
457 )
458 "constant expression required"
459 )
460
461 (assert_invalid
462 (module
463 (memory 1)
464 (data (offset (i32.const 0) (nop)))
465 )
466 "constant expression required"
467 )
468
469 (assert_invalid
470 (module
471 (global $g (import "test" "g") (mut i32))
472 (memory 1)
473 (data (global.get $g))
474 )
475 "constant expression required"
476 )
477
478 (assert_invalid
479 (module
480 (memory 1)
481 (data (global.get 0))
482 )
483 "unknown global 0"
484 )
485
486 (assert_invalid
487 (module
488 (global (import "test" "global-i32") i32)
489 (memory 1)
490 (data (global.get 1))
491 )
492 "unknown global 1"
493 )
494
495 (assert_invalid
496 (module
497 (global (import "test" "global-mut-i32") (mut i32))
498 (memory 1)
499 (data (global.get 0))
500 )
501 "constant expression required"
502 )