...
1;; Test alignment annotation rules
2
3(module (memory 0) (func (drop (i32.load8_s align=1 (i32.const 0)))))
4(module (memory 0) (func (drop (i32.load8_u align=1 (i32.const 0)))))
5(module (memory 0) (func (drop (i32.load16_s align=2 (i32.const 0)))))
6(module (memory 0) (func (drop (i32.load16_u align=2 (i32.const 0)))))
7(module (memory 0) (func (drop (i32.load align=4 (i32.const 0)))))
8(module (memory 0) (func (drop (i64.load8_s align=1 (i32.const 0)))))
9(module (memory 0) (func (drop (i64.load8_u align=1 (i32.const 0)))))
10(module (memory 0) (func (drop (i64.load16_s align=2 (i32.const 0)))))
11(module (memory 0) (func (drop (i64.load16_u align=2 (i32.const 0)))))
12(module (memory 0) (func (drop (i64.load32_s align=4 (i32.const 0)))))
13(module (memory 0) (func (drop (i64.load32_u align=4 (i32.const 0)))))
14(module (memory 0) (func (drop (i64.load align=8 (i32.const 0)))))
15(module (memory 0) (func (drop (f32.load align=4 (i32.const 0)))))
16(module (memory 0) (func (drop (f64.load align=8 (i32.const 0)))))
17(module (memory 0) (func (i32.store8 align=1 (i32.const 0) (i32.const 1))))
18(module (memory 0) (func (i32.store16 align=2 (i32.const 0) (i32.const 1))))
19(module (memory 0) (func (i32.store align=4 (i32.const 0) (i32.const 1))))
20(module (memory 0) (func (i64.store8 align=1 (i32.const 0) (i64.const 1))))
21(module (memory 0) (func (i64.store16 align=2 (i32.const 0) (i64.const 1))))
22(module (memory 0) (func (i64.store32 align=4 (i32.const 0) (i64.const 1))))
23(module (memory 0) (func (i64.store align=8 (i32.const 0) (i64.const 1))))
24(module (memory 0) (func (f32.store align=4 (i32.const 0) (f32.const 1.0))))
25(module (memory 0) (func (f64.store align=8 (i32.const 0) (f64.const 1.0))))
26
27(assert_malformed
28 (module quote
29 "(module (memory 0) (func (drop (i32.load8_s align=0 (i32.const 0)))))"
30 )
31 "alignment"
32)
33(assert_malformed
34 (module quote
35 "(module (memory 0) (func (drop (i32.load8_s align=7 (i32.const 0)))))"
36 )
37 "alignment"
38)
39(assert_malformed
40 (module quote
41 "(module (memory 0) (func (drop (i32.load8_u align=0 (i32.const 0)))))"
42 )
43 "alignment"
44)
45(assert_malformed
46 (module quote
47 "(module (memory 0) (func (drop (i32.load8_u align=7 (i32.const 0)))))"
48 )
49 "alignment"
50)
51(assert_malformed
52 (module quote
53 "(module (memory 0) (func (drop (i32.load16_s align=0 (i32.const 0)))))"
54 )
55 "alignment"
56)
57(assert_malformed
58 (module quote
59 "(module (memory 0) (func (drop (i32.load16_s align=7 (i32.const 0)))))"
60 )
61 "alignment"
62)
63(assert_malformed
64 (module quote
65 "(module (memory 0) (func (drop (i32.load16_u align=0 (i32.const 0)))))"
66 )
67 "alignment"
68)
69(assert_malformed
70 (module quote
71 "(module (memory 0) (func (drop (i32.load16_u align=7 (i32.const 0)))))"
72 )
73 "alignment"
74)
75(assert_malformed
76 (module quote
77 "(module (memory 0) (func (drop (i32.load align=0 (i32.const 0)))))"
78 )
79 "alignment"
80)
81(assert_malformed
82 (module quote
83 "(module (memory 0) (func (drop (i32.load align=7 (i32.const 0)))))"
84 )
85 "alignment"
86)
87(assert_malformed
88 (module quote
89 "(module (memory 0) (func (drop (i64.load8_s align=0 (i32.const 0)))))"
90 )
91 "alignment"
92)
93(assert_malformed
94 (module quote
95 "(module (memory 0) (func (drop (i64.load8_s align=7 (i32.const 0)))))"
96 )
97 "alignment"
98)
99(assert_malformed
100 (module quote
101 "(module (memory 0) (func (drop (i64.load8_u align=0 (i32.const 0)))))"
102 )
103 "alignment"
104)
105(assert_malformed
106 (module quote
107 "(module (memory 0) (func (drop (i64.load8_u align=7 (i32.const 0)))))"
108 )
109 "alignment"
110)
111(assert_malformed
112 (module quote
113 "(module (memory 0) (func (drop (i64.load16_s align=0 (i32.const 0)))))"
114 )
115 "alignment"
116)
117(assert_malformed
118 (module quote
119 "(module (memory 0) (func (drop (i64.load16_s align=7 (i32.const 0)))))"
120 )
121 "alignment"
122)
123(assert_malformed
124 (module quote
125 "(module (memory 0) (func (drop (i64.load16_u align=0 (i32.const 0)))))"
126 )
127 "alignment"
128)
129(assert_malformed
130 (module quote
131 "(module (memory 0) (func (drop (i64.load16_u align=7 (i32.const 0)))))"
132 )
133 "alignment"
134)
135(assert_malformed
136 (module quote
137 "(module (memory 0) (func (drop (i64.load32_s align=0 (i32.const 0)))))"
138 )
139 "alignment"
140)
141(assert_malformed
142 (module quote
143 "(module (memory 0) (func (drop (i64.load32_s align=7 (i32.const 0)))))"
144 )
145 "alignment"
146)
147(assert_malformed
148 (module quote
149 "(module (memory 0) (func (drop (i64.load32_u align=0 (i32.const 0)))))"
150 )
151 "alignment"
152)
153(assert_malformed
154 (module quote
155 "(module (memory 0) (func (drop (i64.load32_u align=7 (i32.const 0)))))"
156 )
157 "alignment"
158)
159(assert_malformed
160 (module quote
161 "(module (memory 0) (func (drop (i64.load align=0 (i32.const 0)))))"
162 )
163 "alignment"
164)
165(assert_malformed
166 (module quote
167 "(module (memory 0) (func (drop (i64.load align=7 (i32.const 0)))))"
168 )
169 "alignment"
170)
171(assert_malformed
172 (module quote
173 "(module (memory 0) (func (drop (f32.load align=0 (i32.const 0)))))"
174 )
175 "alignment"
176)
177(assert_malformed
178 (module quote
179 "(module (memory 0) (func (drop (f32.load align=7 (i32.const 0)))))"
180 )
181 "alignment"
182)
183(assert_malformed
184 (module quote
185 "(module (memory 0) (func (drop (f64.load align=0 (i32.const 0)))))"
186 )
187 "alignment"
188)
189(assert_malformed
190 (module quote
191 "(module (memory 0) (func (drop (f64.load align=7 (i32.const 0)))))"
192 )
193 "alignment"
194)
195
196(assert_malformed
197 (module quote
198 "(module (memory 0) (func (i32.store8 align=0 (i32.const 0) (i32.const 0))))"
199 )
200 "alignment"
201)
202(assert_malformed
203 (module quote
204 "(module (memory 0) (func (i32.store8 align=7 (i32.const 0) (i32.const 0))))"
205 )
206 "alignment"
207)
208(assert_malformed
209 (module quote
210 "(module (memory 0) (func (i32.store16 align=0 (i32.const 0) (i32.const 0))))"
211 )
212 "alignment"
213)
214(assert_malformed
215 (module quote
216 "(module (memory 0) (func (i32.store16 align=7 (i32.const 0) (i32.const 0))))"
217 )
218 "alignment"
219)
220(assert_malformed
221 (module quote
222 "(module (memory 0) (func (i32.store align=0 (i32.const 0) (i32.const 0))))"
223 )
224 "alignment"
225)
226(assert_malformed
227 (module quote
228 "(module (memory 0) (func (i32.store align=7 (i32.const 0) (i32.const 0))))"
229 )
230 "alignment"
231)
232(assert_malformed
233 (module quote
234 "(module (memory 0) (func (i64.store8 align=0 (i32.const 0) (i64.const 0))))"
235 )
236 "alignment"
237)
238(assert_malformed
239 (module quote
240 "(module (memory 0) (func (i64.store8 align=7 (i32.const 0) (i64.const 0))))"
241 )
242 "alignment"
243)
244(assert_malformed
245 (module quote
246 "(module (memory 0) (func (i64.store16 align=0 (i32.const 0) (i64.const 0))))"
247 )
248 "alignment"
249)
250(assert_malformed
251 (module quote
252 "(module (memory 0) (func (i64.store16 align=7 (i32.const 0) (i64.const 0))))"
253 )
254 "alignment"
255)
256(assert_malformed
257 (module quote
258 "(module (memory 0) (func (i64.store32 align=0 (i32.const 0) (i64.const 0))))"
259 )
260 "alignment"
261)
262(assert_malformed
263 (module quote
264 "(module (memory 0) (func (i64.store32 align=7 (i32.const 0) (i64.const 0))))"
265 )
266 "alignment"
267)
268(assert_malformed
269 (module quote
270 "(module (memory 0) (func (i64.store align=0 (i32.const 0) (i64.const 0))))"
271 )
272 "alignment"
273)
274(assert_malformed
275 (module quote
276 "(module (memory 0) (func (i64.store align=7 (i32.const 0) (i64.const 0))))"
277 )
278 "alignment"
279)
280(assert_malformed
281 (module quote
282 "(module (memory 0) (func (f32.store align=0 (i32.const 0) (f32.const 0))))"
283 )
284 "alignment"
285)
286(assert_malformed
287 (module quote
288 "(module (memory 0) (func (f32.store align=7 (i32.const 0) (f32.const 0))))"
289 )
290 "alignment"
291)
292(assert_malformed
293 (module quote
294 "(module (memory 0) (func (f64.store align=0 (i32.const 0) (f32.const 0))))"
295 )
296 "alignment"
297)
298(assert_malformed
299 (module quote
300 "(module (memory 0) (func (f64.store align=7 (i32.const 0) (f32.const 0))))"
301 )
302 "alignment"
303)
304
305(assert_invalid
306 (module (memory 0) (func (drop (i32.load8_s align=2 (i32.const 0)))))
307 "alignment must not be larger than natural"
308)
309(assert_invalid
310 (module (memory 0) (func (drop (i32.load8_u align=2 (i32.const 0)))))
311 "alignment must not be larger than natural"
312)
313(assert_invalid
314 (module (memory 0) (func (drop (i32.load16_s align=4 (i32.const 0)))))
315 "alignment must not be larger than natural"
316)
317(assert_invalid
318 (module (memory 0) (func (drop (i32.load16_u align=4 (i32.const 0)))))
319 "alignment must not be larger than natural"
320)
321(assert_invalid
322 (module (memory 0) (func (drop (i32.load align=8 (i32.const 0)))))
323 "alignment must not be larger than natural"
324)
325(assert_invalid
326 (module (memory 0) (func (drop (i64.load8_s align=2 (i32.const 0)))))
327 "alignment must not be larger than natural"
328)
329(assert_invalid
330 (module (memory 0) (func (drop (i64.load8_u align=2 (i32.const 0)))))
331 "alignment must not be larger than natural"
332)
333(assert_invalid
334 (module (memory 0) (func (drop (i64.load16_s align=4 (i32.const 0)))))
335 "alignment must not be larger than natural"
336)
337(assert_invalid
338 (module (memory 0) (func (drop (i64.load16_u align=4 (i32.const 0)))))
339 "alignment must not be larger than natural"
340)
341(assert_invalid
342 (module (memory 0) (func (drop (i64.load32_s align=8 (i32.const 0)))))
343 "alignment must not be larger than natural"
344)
345(assert_invalid
346 (module (memory 0) (func (drop (i64.load32_u align=8 (i32.const 0)))))
347 "alignment must not be larger than natural"
348)
349(assert_invalid
350 (module (memory 0) (func (drop (i64.load align=16 (i32.const 0)))))
351 "alignment must not be larger than natural"
352)
353(assert_invalid
354 (module (memory 0) (func (drop (f32.load align=8 (i32.const 0)))))
355 "alignment must not be larger than natural"
356)
357(assert_invalid
358 (module (memory 0) (func (drop (f64.load align=16 (i32.const 0)))))
359 "alignment must not be larger than natural"
360)
361
362(assert_invalid
363 (module (memory 0) (func (drop (i32.load8_s align=2 (i32.const 0)))))
364 "alignment must not be larger than natural"
365)
366(assert_invalid
367 (module (memory 0) (func (drop (i32.load8_u align=2 (i32.const 0)))))
368 "alignment must not be larger than natural"
369)
370(assert_invalid
371 (module (memory 0) (func (drop (i32.load16_s align=4 (i32.const 0)))))
372 "alignment must not be larger than natural"
373)
374(assert_invalid
375 (module (memory 0) (func (drop (i32.load16_u align=4 (i32.const 0)))))
376 "alignment must not be larger than natural"
377)
378(assert_invalid
379 (module (memory 0) (func (drop (i32.load align=8 (i32.const 0)))))
380 "alignment must not be larger than natural"
381)
382(assert_invalid
383 (module (memory 0) (func (drop (i64.load8_s align=2 (i32.const 0)))))
384 "alignment must not be larger than natural"
385)
386(assert_invalid
387 (module (memory 0) (func (drop (i64.load8_u align=2 (i32.const 0)))))
388 "alignment must not be larger than natural"
389)
390(assert_invalid
391 (module (memory 0) (func (drop (i64.load16_s align=4 (i32.const 0)))))
392 "alignment must not be larger than natural"
393)
394(assert_invalid
395 (module (memory 0) (func (drop (i64.load16_u align=4 (i32.const 0)))))
396 "alignment must not be larger than natural"
397)
398(assert_invalid
399 (module (memory 0) (func (drop (i64.load32_s align=8 (i32.const 0)))))
400 "alignment must not be larger than natural"
401)
402(assert_invalid
403 (module (memory 0) (func (drop (i64.load32_u align=8 (i32.const 0)))))
404 "alignment must not be larger than natural"
405)
406(assert_invalid
407 (module (memory 0) (func (drop (i64.load align=16 (i32.const 0)))))
408 "alignment must not be larger than natural"
409)
410(assert_invalid
411 (module (memory 0) (func (drop (f32.load align=8 (i32.const 0)))))
412 "alignment must not be larger than natural"
413)
414(assert_invalid
415 (module (memory 0) (func (drop (f64.load align=16 (i32.const 0)))))
416 "alignment must not be larger than natural"
417)
418
419(assert_invalid
420 (module (memory 0) (func (i32.store8 align=2 (i32.const 0) (i32.const 0))))
421 "alignment must not be larger than natural"
422)
423(assert_invalid
424 (module (memory 0) (func (i32.store16 align=4 (i32.const 0) (i32.const 0))))
425 "alignment must not be larger than natural"
426)
427(assert_invalid
428 (module (memory 0) (func (i32.store align=8 (i32.const 0) (i32.const 0))))
429 "alignment must not be larger than natural"
430)
431(assert_invalid
432 (module (memory 0) (func (i64.store8 align=2 (i32.const 0) (i64.const 0))))
433 "alignment must not be larger than natural"
434)
435(assert_invalid
436 (module (memory 0) (func (i64.store16 align=4 (i32.const 0) (i64.const 0))))
437 "alignment must not be larger than natural"
438)
439(assert_invalid
440 (module (memory 0) (func (i64.store32 align=8 (i32.const 0) (i64.const 0))))
441 "alignment must not be larger than natural"
442)
443(assert_invalid
444 (module (memory 0) (func (i64.store align=16 (i32.const 0) (i64.const 0))))
445 "alignment must not be larger than natural"
446)
447(assert_invalid
448 (module (memory 0) (func (f32.store align=8 (i32.const 0) (f32.const 0))))
449 "alignment must not be larger than natural"
450)
451(assert_invalid
452 (module (memory 0) (func (f64.store align=16 (i32.const 0) (f64.const 0))))
453 "alignment must not be larger than natural"
454)
455
456;; Test aligned and unaligned read/write
457
458(module
459 (memory 1)
460
461 ;; $default: natural alignment, $1: align=1, $2: align=2, $4: align=4, $8: align=8
462
463 (func (export "f32_align_switch") (param i32) (result f32)
464 (local f32 f32)
465 (local.set 1 (f32.const 10.0))
466 (block $4
467 (block $2
468 (block $1
469 (block $default
470 (block $0
471 (br_table $0 $default $1 $2 $4 (local.get 0))
472 ) ;; 0
473 (f32.store (i32.const 0) (local.get 1))
474 (local.set 2 (f32.load (i32.const 0)))
475 (br $4)
476 ) ;; default
477 (f32.store align=1 (i32.const 0) (local.get 1))
478 (local.set 2 (f32.load align=1 (i32.const 0)))
479 (br $4)
480 ) ;; 1
481 (f32.store align=2 (i32.const 0) (local.get 1))
482 (local.set 2 (f32.load align=2 (i32.const 0)))
483 (br $4)
484 ) ;; 2
485 (f32.store align=4 (i32.const 0) (local.get 1))
486 (local.set 2 (f32.load align=4 (i32.const 0)))
487 ) ;; 4
488 (local.get 2)
489 )
490
491 (func (export "f64_align_switch") (param i32) (result f64)
492 (local f64 f64)
493 (local.set 1 (f64.const 10.0))
494 (block $8
495 (block $4
496 (block $2
497 (block $1
498 (block $default
499 (block $0
500 (br_table $0 $default $1 $2 $4 $8 (local.get 0))
501 ) ;; 0
502 (f64.store (i32.const 0) (local.get 1))
503 (local.set 2 (f64.load (i32.const 0)))
504 (br $8)
505 ) ;; default
506 (f64.store align=1 (i32.const 0) (local.get 1))
507 (local.set 2 (f64.load align=1 (i32.const 0)))
508 (br $8)
509 ) ;; 1
510 (f64.store align=2 (i32.const 0) (local.get 1))
511 (local.set 2 (f64.load align=2 (i32.const 0)))
512 (br $8)
513 ) ;; 2
514 (f64.store align=4 (i32.const 0) (local.get 1))
515 (local.set 2 (f64.load align=4 (i32.const 0)))
516 (br $8)
517 ) ;; 4
518 (f64.store align=8 (i32.const 0) (local.get 1))
519 (local.set 2 (f64.load align=8 (i32.const 0)))
520 ) ;; 8
521 (local.get 2)
522 )
523
524 ;; $8s: i32/i64.load8_s, $8u: i32/i64.load8_u, $16s: i32/i64.load16_s, $16u: i32/i64.load16_u, $32: i32.load
525 ;; $32s: i64.load32_s, $32u: i64.load32_u, $64: i64.load
526
527 (func (export "i32_align_switch") (param i32 i32) (result i32)
528 (local i32 i32)
529 (local.set 2 (i32.const 10))
530 (block $32
531 (block $16u
532 (block $16s
533 (block $8u
534 (block $8s
535 (block $0
536 (br_table $0 $8s $8u $16s $16u $32 (local.get 0))
537 ) ;; 0
538 (if (i32.eq (local.get 1) (i32.const 0))
539 (then
540 (i32.store8 (i32.const 0) (local.get 2))
541 (local.set 3 (i32.load8_s (i32.const 0)))
542 )
543 )
544 (if (i32.eq (local.get 1) (i32.const 1))
545 (then
546 (i32.store8 align=1 (i32.const 0) (local.get 2))
547 (local.set 3 (i32.load8_s align=1 (i32.const 0)))
548 )
549 )
550 (br $32)
551 ) ;; 8s
552 (if (i32.eq (local.get 1) (i32.const 0))
553 (then
554 (i32.store8 (i32.const 0) (local.get 2))
555 (local.set 3 (i32.load8_u (i32.const 0)))
556 )
557 )
558 (if (i32.eq (local.get 1) (i32.const 1))
559 (then
560 (i32.store8 align=1 (i32.const 0) (local.get 2))
561 (local.set 3 (i32.load8_u align=1 (i32.const 0)))
562 )
563 )
564 (br $32)
565 ) ;; 8u
566 (if (i32.eq (local.get 1) (i32.const 0))
567 (then
568 (i32.store16 (i32.const 0) (local.get 2))
569 (local.set 3 (i32.load16_s (i32.const 0)))
570 )
571 )
572 (if (i32.eq (local.get 1) (i32.const 1))
573 (then
574 (i32.store16 align=1 (i32.const 0) (local.get 2))
575 (local.set 3 (i32.load16_s align=1 (i32.const 0)))
576 )
577 )
578 (if (i32.eq (local.get 1) (i32.const 2))
579 (then
580 (i32.store16 align=2 (i32.const 0) (local.get 2))
581 (local.set 3 (i32.load16_s align=2 (i32.const 0)))
582 )
583 )
584 (br $32)
585 ) ;; 16s
586 (if (i32.eq (local.get 1) (i32.const 0))
587 (then
588 (i32.store16 (i32.const 0) (local.get 2))
589 (local.set 3 (i32.load16_u (i32.const 0)))
590 )
591 )
592 (if (i32.eq (local.get 1) (i32.const 1))
593 (then
594 (i32.store16 align=1 (i32.const 0) (local.get 2))
595 (local.set 3 (i32.load16_u align=1 (i32.const 0)))
596 )
597 )
598 (if (i32.eq (local.get 1) (i32.const 2))
599 (then
600 (i32.store16 align=2 (i32.const 0) (local.get 2))
601 (local.set 3 (i32.load16_u align=2 (i32.const 0)))
602 )
603 )
604 (br $32)
605 ) ;; 16u
606 (if (i32.eq (local.get 1) (i32.const 0))
607 (then
608 (i32.store (i32.const 0) (local.get 2))
609 (local.set 3 (i32.load (i32.const 0)))
610 )
611 )
612 (if (i32.eq (local.get 1) (i32.const 1))
613 (then
614 (i32.store align=1 (i32.const 0) (local.get 2))
615 (local.set 3 (i32.load align=1 (i32.const 0)))
616 )
617 )
618 (if (i32.eq (local.get 1) (i32.const 2))
619 (then
620 (i32.store align=2 (i32.const 0) (local.get 2))
621 (local.set 3 (i32.load align=2 (i32.const 0)))
622 )
623 )
624 (if (i32.eq (local.get 1) (i32.const 4))
625 (then
626 (i32.store align=4 (i32.const 0) (local.get 2))
627 (local.set 3 (i32.load align=4 (i32.const 0)))
628 )
629 )
630 ) ;; 32
631 (local.get 3)
632 )
633
634 (func (export "i64_align_switch") (param i32 i32) (result i64)
635 (local i64 i64)
636 (local.set 2 (i64.const 10))
637 (block $64
638 (block $32u
639 (block $32s
640 (block $16u
641 (block $16s
642 (block $8u
643 (block $8s
644 (block $0
645 (br_table $0 $8s $8u $16s $16u $32s $32u $64 (local.get 0))
646 ) ;; 0
647 (if (i32.eq (local.get 1) (i32.const 0))
648 (then
649 (i64.store8 (i32.const 0) (local.get 2))
650 (local.set 3 (i64.load8_s (i32.const 0)))
651 )
652 )
653 (if (i32.eq (local.get 1) (i32.const 1))
654 (then
655 (i64.store8 align=1 (i32.const 0) (local.get 2))
656 (local.set 3 (i64.load8_s align=1 (i32.const 0)))
657 )
658 )
659 (br $64)
660 ) ;; 8s
661 (if (i32.eq (local.get 1) (i32.const 0))
662 (then
663 (i64.store8 (i32.const 0) (local.get 2))
664 (local.set 3 (i64.load8_u (i32.const 0)))
665 )
666 )
667 (if (i32.eq (local.get 1) (i32.const 1))
668 (then
669 (i64.store8 align=1 (i32.const 0) (local.get 2))
670 (local.set 3 (i64.load8_u align=1 (i32.const 0)))
671 )
672 )
673 (br $64)
674 ) ;; 8u
675 (if (i32.eq (local.get 1) (i32.const 0))
676 (then
677 (i64.store16 (i32.const 0) (local.get 2))
678 (local.set 3 (i64.load16_s (i32.const 0)))
679 )
680 )
681 (if (i32.eq (local.get 1) (i32.const 1))
682 (then
683 (i64.store16 align=1 (i32.const 0) (local.get 2))
684 (local.set 3 (i64.load16_s align=1 (i32.const 0)))
685 )
686 )
687 (if (i32.eq (local.get 1) (i32.const 2))
688 (then
689 (i64.store16 align=2 (i32.const 0) (local.get 2))
690 (local.set 3 (i64.load16_s align=2 (i32.const 0)))
691 )
692 )
693 (br $64)
694 ) ;; 16s
695 (if (i32.eq (local.get 1) (i32.const 0))
696 (then
697 (i64.store16 (i32.const 0) (local.get 2))
698 (local.set 3 (i64.load16_u (i32.const 0)))
699 )
700 )
701 (if (i32.eq (local.get 1) (i32.const 1))
702 (then
703 (i64.store16 align=1 (i32.const 0) (local.get 2))
704 (local.set 3 (i64.load16_u align=1 (i32.const 0)))
705 )
706 )
707 (if (i32.eq (local.get 1) (i32.const 2))
708 (then
709 (i64.store16 align=2 (i32.const 0) (local.get 2))
710 (local.set 3 (i64.load16_u align=2 (i32.const 0)))
711 )
712 )
713 (br $64)
714 ) ;; 16u
715 (if (i32.eq (local.get 1) (i32.const 0))
716 (then
717 (i64.store32 (i32.const 0) (local.get 2))
718 (local.set 3 (i64.load32_s (i32.const 0)))
719 )
720 )
721 (if (i32.eq (local.get 1) (i32.const 1))
722 (then
723 (i64.store32 align=1 (i32.const 0) (local.get 2))
724 (local.set 3 (i64.load32_s align=1 (i32.const 0)))
725 )
726 )
727 (if (i32.eq (local.get 1) (i32.const 2))
728 (then
729 (i64.store32 align=2 (i32.const 0) (local.get 2))
730 (local.set 3 (i64.load32_s align=2 (i32.const 0)))
731 )
732 )
733 (if (i32.eq (local.get 1) (i32.const 4))
734 (then
735 (i64.store32 align=4 (i32.const 0) (local.get 2))
736 (local.set 3 (i64.load32_s align=4 (i32.const 0)))
737 )
738 )
739 (br $64)
740 ) ;; 32s
741 (if (i32.eq (local.get 1) (i32.const 0))
742 (then
743 (i64.store32 (i32.const 0) (local.get 2))
744 (local.set 3 (i64.load32_u (i32.const 0)))
745 )
746 )
747 (if (i32.eq (local.get 1) (i32.const 1))
748 (then
749 (i64.store32 align=1 (i32.const 0) (local.get 2))
750 (local.set 3 (i64.load32_u align=1 (i32.const 0)))
751 )
752 )
753 (if (i32.eq (local.get 1) (i32.const 2))
754 (then
755 (i64.store32 align=2 (i32.const 0) (local.get 2))
756 (local.set 3 (i64.load32_u align=2 (i32.const 0)))
757 )
758 )
759 (if (i32.eq (local.get 1) (i32.const 4))
760 (then
761 (i64.store32 align=4 (i32.const 0) (local.get 2))
762 (local.set 3 (i64.load32_u align=4 (i32.const 0)))
763 )
764 )
765 (br $64)
766 ) ;; 32u
767 (if (i32.eq (local.get 1) (i32.const 0))
768 (then
769 (i64.store (i32.const 0) (local.get 2))
770 (local.set 3 (i64.load (i32.const 0)))
771 )
772 )
773 (if (i32.eq (local.get 1) (i32.const 1))
774 (then
775 (i64.store align=1 (i32.const 0) (local.get 2))
776 (local.set 3 (i64.load align=1 (i32.const 0)))
777 )
778 )
779 (if (i32.eq (local.get 1) (i32.const 2))
780 (then
781 (i64.store align=2 (i32.const 0) (local.get 2))
782 (local.set 3 (i64.load align=2 (i32.const 0)))
783 )
784 )
785 (if (i32.eq (local.get 1) (i32.const 4))
786 (then
787 (i64.store align=4 (i32.const 0) (local.get 2))
788 (local.set 3 (i64.load align=4 (i32.const 0)))
789 )
790 )
791 (if (i32.eq (local.get 1) (i32.const 8))
792 (then
793 (i64.store align=8 (i32.const 0) (local.get 2))
794 (local.set 3 (i64.load align=8 (i32.const 0)))
795 )
796 )
797 ) ;; 64
798 (local.get 3)
799 )
800)
801
802(assert_return (invoke "f32_align_switch" (i32.const 0)) (f32.const 10.0))
803(assert_return (invoke "f32_align_switch" (i32.const 1)) (f32.const 10.0))
804(assert_return (invoke "f32_align_switch" (i32.const 2)) (f32.const 10.0))
805(assert_return (invoke "f32_align_switch" (i32.const 3)) (f32.const 10.0))
806
807(assert_return (invoke "f64_align_switch" (i32.const 0)) (f64.const 10.0))
808(assert_return (invoke "f64_align_switch" (i32.const 1)) (f64.const 10.0))
809(assert_return (invoke "f64_align_switch" (i32.const 2)) (f64.const 10.0))
810(assert_return (invoke "f64_align_switch" (i32.const 3)) (f64.const 10.0))
811(assert_return (invoke "f64_align_switch" (i32.const 4)) (f64.const 10.0))
812
813(assert_return (invoke "i32_align_switch" (i32.const 0) (i32.const 0)) (i32.const 10))
814(assert_return (invoke "i32_align_switch" (i32.const 0) (i32.const 1)) (i32.const 10))
815(assert_return (invoke "i32_align_switch" (i32.const 1) (i32.const 0)) (i32.const 10))
816(assert_return (invoke "i32_align_switch" (i32.const 1) (i32.const 1)) (i32.const 10))
817(assert_return (invoke "i32_align_switch" (i32.const 2) (i32.const 0)) (i32.const 10))
818(assert_return (invoke "i32_align_switch" (i32.const 2) (i32.const 1)) (i32.const 10))
819(assert_return (invoke "i32_align_switch" (i32.const 2) (i32.const 2)) (i32.const 10))
820(assert_return (invoke "i32_align_switch" (i32.const 3) (i32.const 0)) (i32.const 10))
821(assert_return (invoke "i32_align_switch" (i32.const 3) (i32.const 1)) (i32.const 10))
822(assert_return (invoke "i32_align_switch" (i32.const 3) (i32.const 2)) (i32.const 10))
823(assert_return (invoke "i32_align_switch" (i32.const 4) (i32.const 0)) (i32.const 10))
824(assert_return (invoke "i32_align_switch" (i32.const 4) (i32.const 1)) (i32.const 10))
825(assert_return (invoke "i32_align_switch" (i32.const 4) (i32.const 2)) (i32.const 10))
826(assert_return (invoke "i32_align_switch" (i32.const 4) (i32.const 4)) (i32.const 10))
827
828(assert_return (invoke "i64_align_switch" (i32.const 0) (i32.const 0)) (i64.const 10))
829(assert_return (invoke "i64_align_switch" (i32.const 0) (i32.const 1)) (i64.const 10))
830(assert_return (invoke "i64_align_switch" (i32.const 1) (i32.const 0)) (i64.const 10))
831(assert_return (invoke "i64_align_switch" (i32.const 1) (i32.const 1)) (i64.const 10))
832(assert_return (invoke "i64_align_switch" (i32.const 2) (i32.const 0)) (i64.const 10))
833(assert_return (invoke "i64_align_switch" (i32.const 2) (i32.const 1)) (i64.const 10))
834(assert_return (invoke "i64_align_switch" (i32.const 2) (i32.const 2)) (i64.const 10))
835(assert_return (invoke "i64_align_switch" (i32.const 3) (i32.const 0)) (i64.const 10))
836(assert_return (invoke "i64_align_switch" (i32.const 3) (i32.const 1)) (i64.const 10))
837(assert_return (invoke "i64_align_switch" (i32.const 3) (i32.const 2)) (i64.const 10))
838(assert_return (invoke "i64_align_switch" (i32.const 4) (i32.const 0)) (i64.const 10))
839(assert_return (invoke "i64_align_switch" (i32.const 4) (i32.const 1)) (i64.const 10))
840(assert_return (invoke "i64_align_switch" (i32.const 4) (i32.const 2)) (i64.const 10))
841(assert_return (invoke "i64_align_switch" (i32.const 4) (i32.const 4)) (i64.const 10))
842(assert_return (invoke "i64_align_switch" (i32.const 5) (i32.const 0)) (i64.const 10))
843(assert_return (invoke "i64_align_switch" (i32.const 5) (i32.const 1)) (i64.const 10))
844(assert_return (invoke "i64_align_switch" (i32.const 5) (i32.const 2)) (i64.const 10))
845(assert_return (invoke "i64_align_switch" (i32.const 5) (i32.const 4)) (i64.const 10))
846(assert_return (invoke "i64_align_switch" (i32.const 6) (i32.const 0)) (i64.const 10))
847(assert_return (invoke "i64_align_switch" (i32.const 6) (i32.const 1)) (i64.const 10))
848(assert_return (invoke "i64_align_switch" (i32.const 6) (i32.const 2)) (i64.const 10))
849(assert_return (invoke "i64_align_switch" (i32.const 6) (i32.const 4)) (i64.const 10))
850(assert_return (invoke "i64_align_switch" (i32.const 6) (i32.const 8)) (i64.const 10))
851
852;; Test that an i64 store with 4-byte alignment that's 4 bytes out of bounds traps without storing anything
853
854(module
855 (memory 1)
856 (func (export "store") (param i32 i64)
857 (i64.store align=4 (local.get 0) (local.get 1))
858 )
859 (func (export "load") (param i32) (result i32)
860 (i32.load (local.get 0))
861 )
862)
863
864(assert_trap (invoke "store" (i32.const 65532) (i64.const -1)) "out of bounds memory access")
865;; No memory was changed
866(assert_return (invoke "load" (i32.const 65532)) (i32.const 0))
View as plain text