Files
2026-11-21 01:03:32 -08:00

18 lines
986 B
WebAssembly Text Format

;; globals + linear memory: stores, sign/zero-extending loads, then an OOB trap
(module
(memory 1)
(global $g (mut i32) (i32.const 40))
(data (i32.const 0) "\ff\01")
(func (export "main") (result i32)
(global.set $g (i32.add (global.get $g) (i32.const 1)))
(i32.store (i32.const 100) (i32.const 0x01020304))
(if (i32.ne (i32.load8_u (i32.const 100)) (i32.const 4)) (then (return (i32.const 1))))
(if (i32.ne (i32.load8_s (i32.const 0)) (i32.const -1)) (then (return (i32.const 2))))
(if (i32.ne (i32.load16_u (i32.const 0)) (i32.const 0x01ff)) (then (return (i32.const 3))))
(i32.store8 (i32.const 200) (i32.const 1))
(global.set $g (i32.add (global.get $g) (i32.load8_u (i32.const 200))))
(if (i32.ne (memory.size) (i32.const 1)) (then (return (i32.const 4))))
(if (i32.ne (global.get $g) (i32.const 42)) (then (return (i32.const 5))))
(drop (i32.load (i32.const 65533))) ;; 4-byte load straddling the end: traps
(global.get $g)))