|
| 1 | +(module |
| 2 | + (memory 256 256) |
| 3 | + (data (i32.const 10) "waka waka waka waka waka") |
| 4 | + ;; stack imports are special |
| 5 | + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) |
| 6 | + (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) |
| 7 | + ;; other imports must not be touched! |
| 8 | + (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) |
| 9 | + (export "test1" $test1) |
| 10 | + (export "test2" $test2) |
| 11 | + (export "test3" $test3) |
| 12 | + ;; ok to modify a global, if we keep it the same value |
| 13 | + (global $mine (mut i32) (i32.const 1)) |
| 14 | + ;; stack imports are ok to use. their uses are the same as other |
| 15 | + ;; globals - must keep the same value (which means, unwind the stack) |
| 16 | + ;; here the global names are "minified" |
| 17 | + (global $global0 (mut i32) (get_global $STACKTOP$asm2wasm$import)) |
| 18 | + (global $global1 (mut i32) (get_global $STACK_MAX$asm2wasm$import)) |
| 19 | + ;; a global initialized by an import, so bad, but ok if not used |
| 20 | + (global $do-not-use (mut i32) (get_global $tempDoublePtr)) |
| 21 | + (func $test1 |
| 22 | + (local $temp i32) |
| 23 | + (set_global $mine (i32.const 1)) |
| 24 | + (set_local $temp (get_global $global0)) |
| 25 | + (set_global $global0 (i32.const 1337)) ;; bad |
| 26 | + (set_global $global0 (get_local $temp)) ;; save us |
| 27 | + (set_global $global1 (i32.const 913370)) ;; bad |
| 28 | + (set_global $global1 (get_local $temp)) ;; save us |
| 29 | + ;; use the stack memory |
| 30 | + (i32.store (get_local $temp) (i32.const 1337)) |
| 31 | + (if |
| 32 | + (i32.ne |
| 33 | + (i32.load (get_local $temp)) |
| 34 | + (i32.const 1337) |
| 35 | + ) |
| 36 | + (unreachable) ;; they should be equal, never get here |
| 37 | + ) |
| 38 | + ;; finally, do a valid store |
| 39 | + (i32.store8 (i32.const 12) (i32.const 115)) |
| 40 | + ) |
| 41 | + (func $test2 |
| 42 | + (set_global $tempDoublePtr (i32.const 1)) ;; bad! |
| 43 | + (i32.store8 (i32.const 13) (i32.const 115)) |
| 44 | + ) |
| 45 | + (func $test3 |
| 46 | + (i32.store8 (i32.const 14) (i32.const 115)) |
| 47 | + ) |
| 48 | +) |
0 commit comments