-
Notifications
You must be signed in to change notification settings - Fork 57
/
bulk.wast
351 lines (290 loc) · 12.9 KB
/
bulk.wast
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
;; segment syntax
(module
(memory 1)
(data "foo"))
(module
(table 3 funcref)
(elem funcref (ref.func 0) (ref.null func) (ref.func 1))
(func)
(func))
;; memory.fill
(module
(memory 1)
(func (export "fill") (param i32 i32 i32)
(memory.fill
(local.get 0)
(local.get 1)
(local.get 2)))
(func (export "load8_u") (param i32) (result i32)
(i32.load8_u (local.get 0)))
)
;; Basic fill test.
(invoke "fill" (i32.const 1) (i32.const 0xff) (i32.const 3))
(assert_return (invoke "load8_u" (i32.const 0)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 1)) (i32.const 0xff))
(assert_return (invoke "load8_u" (i32.const 2)) (i32.const 0xff))
(assert_return (invoke "load8_u" (i32.const 3)) (i32.const 0xff))
(assert_return (invoke "load8_u" (i32.const 4)) (i32.const 0))
;; Fill value is stored as a byte.
(invoke "fill" (i32.const 0) (i32.const 0xbbaa) (i32.const 2))
(assert_return (invoke "load8_u" (i32.const 0)) (i32.const 0xaa))
(assert_return (invoke "load8_u" (i32.const 1)) (i32.const 0xaa))
;; Fill all of memory
(invoke "fill" (i32.const 0) (i32.const 0) (i32.const 0x10000))
;; Out-of-bounds writes trap, and nothing is written
(assert_trap (invoke "fill" (i32.const 0xff00) (i32.const 1) (i32.const 0x101))
"out of bounds memory access")
(assert_return (invoke "load8_u" (i32.const 0xff00)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 0xffff)) (i32.const 0))
;; Succeed when writing 0 bytes at the end of the region.
(invoke "fill" (i32.const 0x10000) (i32.const 0) (i32.const 0))
;; Writing 0 bytes outside the memory traps.
(assert_trap (invoke "fill" (i32.const 0x10001) (i32.const 0) (i32.const 0))
"out of bounds memory access")
;; memory.copy
(module
(memory (data "\aa\bb\cc\dd"))
(func (export "copy") (param i32 i32 i32)
(memory.copy
(local.get 0)
(local.get 1)
(local.get 2)))
(func (export "load8_u") (param i32) (result i32)
(i32.load8_u (local.get 0)))
)
;; Non-overlapping copy.
(invoke "copy" (i32.const 10) (i32.const 0) (i32.const 4))
(assert_return (invoke "load8_u" (i32.const 9)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 10)) (i32.const 0xaa))
(assert_return (invoke "load8_u" (i32.const 11)) (i32.const 0xbb))
(assert_return (invoke "load8_u" (i32.const 12)) (i32.const 0xcc))
(assert_return (invoke "load8_u" (i32.const 13)) (i32.const 0xdd))
(assert_return (invoke "load8_u" (i32.const 14)) (i32.const 0))
;; Overlap, source > dest
(invoke "copy" (i32.const 8) (i32.const 10) (i32.const 4))
(assert_return (invoke "load8_u" (i32.const 8)) (i32.const 0xaa))
(assert_return (invoke "load8_u" (i32.const 9)) (i32.const 0xbb))
(assert_return (invoke "load8_u" (i32.const 10)) (i32.const 0xcc))
(assert_return (invoke "load8_u" (i32.const 11)) (i32.const 0xdd))
(assert_return (invoke "load8_u" (i32.const 12)) (i32.const 0xcc))
(assert_return (invoke "load8_u" (i32.const 13)) (i32.const 0xdd))
;; Overlap, source < dest
(invoke "copy" (i32.const 10) (i32.const 7) (i32.const 6))
(assert_return (invoke "load8_u" (i32.const 10)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 11)) (i32.const 0xaa))
(assert_return (invoke "load8_u" (i32.const 12)) (i32.const 0xbb))
(assert_return (invoke "load8_u" (i32.const 13)) (i32.const 0xcc))
(assert_return (invoke "load8_u" (i32.const 14)) (i32.const 0xdd))
(assert_return (invoke "load8_u" (i32.const 15)) (i32.const 0xcc))
(assert_return (invoke "load8_u" (i32.const 16)) (i32.const 0))
;; Copy ending at memory limit is ok.
(invoke "copy" (i32.const 0xff00) (i32.const 0) (i32.const 0x100))
(invoke "copy" (i32.const 0xfe00) (i32.const 0xff00) (i32.const 0x100))
;; Succeed when copying 0 bytes at the end of the region.
(invoke "copy" (i32.const 0x10000) (i32.const 0) (i32.const 0))
(invoke "copy" (i32.const 0) (i32.const 0x10000) (i32.const 0))
;; Copying 0 bytes outside the memory traps.
(assert_trap (invoke "copy" (i32.const 0x10001) (i32.const 0) (i32.const 0))
"out of bounds memory access")
(assert_trap (invoke "copy" (i32.const 0) (i32.const 0x10001) (i32.const 0))
"out of bounds memory access")
;; memory.init
(module
(memory 1)
(data "\aa\bb\cc\dd")
(func (export "init") (param i32 i32 i32)
(memory.init 0
(local.get 0)
(local.get 1)
(local.get 2)))
(func (export "load8_u") (param i32) (result i32)
(i32.load8_u (local.get 0)))
)
(invoke "init" (i32.const 0) (i32.const 1) (i32.const 2))
(assert_return (invoke "load8_u" (i32.const 0)) (i32.const 0xbb))
(assert_return (invoke "load8_u" (i32.const 1)) (i32.const 0xcc))
(assert_return (invoke "load8_u" (i32.const 2)) (i32.const 0))
;; Init ending at memory limit and segment limit is ok.
(invoke "init" (i32.const 0xfffc) (i32.const 0) (i32.const 4))
;; Out-of-bounds writes trap, and nothing is written.
(assert_trap (invoke "init" (i32.const 0xfffe) (i32.const 0) (i32.const 3))
"out of bounds memory access")
(assert_return (invoke "load8_u" (i32.const 0xfffe)) (i32.const 0xcc))
(assert_return (invoke "load8_u" (i32.const 0xffff)) (i32.const 0xdd))
;; Succeed when writing 0 bytes at the end of either region.
(invoke "init" (i32.const 0x10000) (i32.const 0) (i32.const 0))
(invoke "init" (i32.const 0) (i32.const 4) (i32.const 0))
;; Writing 0 bytes outside the memory traps.
(assert_trap (invoke "init" (i32.const 0x10001) (i32.const 0) (i32.const 0))
"out of bounds memory access")
(assert_trap (invoke "init" (i32.const 0) (i32.const 5) (i32.const 0))
"out of bounds memory access")
;; data.drop
(module
(memory 1)
(data $p "x")
(data $a (memory 0) (i32.const 0) "x")
(func (export "drop_passive") (data.drop $p))
(func (export "init_passive") (param $len i32)
(memory.init $p (i32.const 0) (i32.const 0) (local.get $len)))
(func (export "drop_active") (data.drop $a))
(func (export "init_active") (param $len i32)
(memory.init $a (i32.const 0) (i32.const 0) (local.get $len)))
)
(invoke "init_passive" (i32.const 1))
(invoke "drop_passive")
(invoke "drop_passive")
(assert_return (invoke "init_passive" (i32.const 0)))
(assert_trap (invoke "init_passive" (i32.const 1)) "out of bounds memory access")
(invoke "init_passive" (i32.const 0))
(invoke "drop_active")
(assert_return (invoke "init_active" (i32.const 0)))
(assert_trap (invoke "init_active" (i32.const 1)) "out of bounds memory access")
(invoke "init_active" (i32.const 0))
;; Test that the data segment index is properly encoded as an unsigned (not
;; signed) LEB.
(module
;; 65 data segments. 64 is the smallest positive number that is encoded
;; differently as a signed LEB.
(data "") (data "") (data "") (data "") (data "") (data "") (data "") (data "")
(data "") (data "") (data "") (data "") (data "") (data "") (data "") (data "")
(data "") (data "") (data "") (data "") (data "") (data "") (data "") (data "")
(data "") (data "") (data "") (data "") (data "") (data "") (data "") (data "")
(data "") (data "") (data "") (data "") (data "") (data "") (data "") (data "")
(data "") (data "") (data "") (data "") (data "") (data "") (data "") (data "")
(data "") (data "") (data "") (data "") (data "") (data "") (data "") (data "")
(data "") (data "") (data "") (data "") (data "") (data "") (data "") (data "")
(data "")
(func (data.drop 64)))
;; No memory is required for the data.drop instruction.
(module (data "goodbye") (func (data.drop 0)))
;; table.init
(module
(table 3 funcref)
(elem funcref
(ref.func $zero) (ref.func $one) (ref.func $zero) (ref.func $one))
(func $zero (result i32) (i32.const 0))
(func $one (result i32) (i32.const 1))
(func (export "init") (param i32 i32 i32)
(table.init 0
(local.get 0)
(local.get 1)
(local.get 2)))
(func (export "call") (param i32) (result i32)
(call_indirect (result i32)
(local.get 0)))
)
;; Out-of-bounds stores trap, and nothing is written.
(assert_trap (invoke "init" (i32.const 2) (i32.const 0) (i32.const 2))
"out of bounds table access")
(assert_trap (invoke "call" (i32.const 2))
"uninitialized element 2")
(invoke "init" (i32.const 0) (i32.const 1) (i32.const 2))
(assert_return (invoke "call" (i32.const 0)) (i32.const 1))
(assert_return (invoke "call" (i32.const 1)) (i32.const 0))
(assert_trap (invoke "call" (i32.const 2)) "uninitialized element")
;; Init ending at table limit and segment limit is ok.
(invoke "init" (i32.const 1) (i32.const 2) (i32.const 2))
;; Succeed when storing 0 elements at the end of either region.
(invoke "init" (i32.const 3) (i32.const 0) (i32.const 0))
(invoke "init" (i32.const 0) (i32.const 4) (i32.const 0))
;; Writing 0 elements outside the table traps.
(assert_trap (invoke "init" (i32.const 4) (i32.const 0) (i32.const 0))
"out of bounds table access")
(assert_trap (invoke "init" (i32.const 0) (i32.const 5) (i32.const 0))
"out of bounds table access")
;; elem.drop
(module
(table 1 funcref)
(func $f)
(elem $p funcref (ref.func $f))
(elem $a (table 0) (i32.const 0) func $f)
(func (export "drop_passive") (elem.drop $p))
(func (export "init_passive") (param $len i32)
(table.init $p (i32.const 0) (i32.const 0) (local.get $len))
)
(func (export "drop_active") (elem.drop $a))
(func (export "init_active") (param $len i32)
(table.init $a (i32.const 0) (i32.const 0) (local.get $len))
)
)
(invoke "init_passive" (i32.const 1))
(invoke "drop_passive")
(invoke "drop_passive")
(assert_return (invoke "init_passive" (i32.const 0)))
(assert_trap (invoke "init_passive" (i32.const 1)) "out of bounds table access")
(invoke "init_passive" (i32.const 0))
(invoke "drop_active")
(assert_return (invoke "init_active" (i32.const 0)))
(assert_trap (invoke "init_active" (i32.const 1)) "out of bounds table access")
(invoke "init_active" (i32.const 0))
;; Test that the elem segment index is properly encoded as an unsigned (not
;; signed) LEB.
(module
;; 65 elem segments. 64 is the smallest positive number that is encoded
;; differently as a signed LEB.
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref) (elem funcref) (elem funcref) (elem funcref)
(elem funcref)
(func (elem.drop 64)))
;; No table is required for the elem.drop instruction.
(module (elem funcref (ref.func 0)) (func (elem.drop 0)))
;; table.copy
(module
(table 10 funcref)
(elem (i32.const 0) $zero $one $two)
(func $zero (result i32) (i32.const 0))
(func $one (result i32) (i32.const 1))
(func $two (result i32) (i32.const 2))
(func (export "copy") (param i32 i32 i32)
(table.copy
(local.get 0)
(local.get 1)
(local.get 2)))
(func (export "call") (param i32) (result i32)
(call_indirect (result i32)
(local.get 0)))
)
;; Non-overlapping copy.
(invoke "copy" (i32.const 3) (i32.const 0) (i32.const 3))
;; Now [$zero, $one, $two, $zero, $one, $two, ...]
(assert_return (invoke "call" (i32.const 3)) (i32.const 0))
(assert_return (invoke "call" (i32.const 4)) (i32.const 1))
(assert_return (invoke "call" (i32.const 5)) (i32.const 2))
;; Overlap, source > dest
(invoke "copy" (i32.const 0) (i32.const 1) (i32.const 3))
;; Now [$one, $two, $zero, $zero, $one, $two, ...]
(assert_return (invoke "call" (i32.const 0)) (i32.const 1))
(assert_return (invoke "call" (i32.const 1)) (i32.const 2))
(assert_return (invoke "call" (i32.const 2)) (i32.const 0))
;; Overlap, source < dest
(invoke "copy" (i32.const 2) (i32.const 0) (i32.const 3))
;; Now [$one, $two, $one, $two, $zero, $two, ...]
(assert_return (invoke "call" (i32.const 2)) (i32.const 1))
(assert_return (invoke "call" (i32.const 3)) (i32.const 2))
(assert_return (invoke "call" (i32.const 4)) (i32.const 0))
;; Copy ending at table limit is ok.
(invoke "copy" (i32.const 6) (i32.const 8) (i32.const 2))
(invoke "copy" (i32.const 8) (i32.const 6) (i32.const 2))
;; Succeed when copying 0 elements at the end of the region.
(invoke "copy" (i32.const 10) (i32.const 0) (i32.const 0))
(invoke "copy" (i32.const 0) (i32.const 10) (i32.const 0))
;; Fail on out-of-bounds when copying 0 elements outside of table.
(assert_trap (invoke "copy" (i32.const 11) (i32.const 0) (i32.const 0))
"out of bounds table access")
(assert_trap (invoke "copy" (i32.const 0) (i32.const 11) (i32.const 0))
"out of bounds table access")