Skip to content

Commit

Permalink
fix store bug, added testcases for the fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobgetz committed Dec 19, 2023
1 parent 234f582 commit 38332da
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"args": [
"node",
"-t",
"exported-called-params-grow-mem",
"mem-exp-host-mod-pingpong",
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/replay-generator.cts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ export default class Generator {
this.state.lastFuncReturn = true
r.slice(-1)[0].reps += 1
this.state.importCallStack.pop()
this.state.importCallStackFunction.pop()
this.state.lastFunc = this.state.importCallStackFunction.pop()
break
}
}
this.state.lastFuncReturn = true
r.push({ results: event.results, reps: 1 })
this.state.importCallStack.pop()
this.state.importCallStackFunction.pop()
this.state.lastFunc = this.state.importCallStackFunction.pop()
break
case "Load":
this.pushEvent({
Expand Down
33 changes: 33 additions & 0 deletions tests/node/mem-exp-host-mod-store-lastfunc-return/index.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(module
(import "env" "changeMemAfterReentry" (func $changeMemAfterReentry (result i32)))
(import "env" "foo" (func $foo))
(import "env" "bar" (func $bar (result i32)))
(func $main (export "main")
call $changeMemAfterReentry
drop
i32.const 1
i32.load
drop
call $changeMemAfterReentry
drop
i32.const 1
i32.load
drop
call $changeMemAfterReentry
drop
i32.const 1
i32.load
drop
)
(func (export "reentry")
call $foo
i32.const 1
i32.load
drop
)
(func (export "reentry2")
call $bar
drop
)
(memory (export "memory") 1)
)
22 changes: 22 additions & 0 deletions tests/node/mem-exp-host-mod-store-lastfunc-return/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default async function test(wasmBinary) {
let instance
let imports = {
env: {
changeMemAfterReentry: () => {
instance.exports.reentry()
new Uint8Array(instance.exports.memory.buffer)[1] = 1
return 69
},
foo: () => {
instance.exports.reentry2()
},
bar: () => {
new Uint8Array(instance.exports.memory.buffer)[1] = 2
return 420
}
}
}
let wasm = await WebAssembly.instantiate(wasmBinary, imports)
instance = wasm.instance
instance.exports.main()
}
21 changes: 21 additions & 0 deletions tests/node/mem-exp-host-mod-store-lastfunc/index.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(module
(import "env" "changeMemAfterReentry" (func $changeMemAfterReentry))
(import "env" "foo" (func $foo))
(import "env" "bar" (func $bar))
(func $main (export "main")
call $changeMemAfterReentry
i32.const 1
i32.load
drop
)
(func (export "reentry")
call $foo
i32.const 1
i32.load
drop
)
(func (export "reentry2")
call $bar
)
(memory (export "memory") 1)
)
20 changes: 20 additions & 0 deletions tests/node/mem-exp-host-mod-store-lastfunc/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default async function test(wasmBinary) {
let instance
let imports = {
env: {
changeMemAfterReentry: () => {
instance.exports.reentry()
new Uint8Array(instance.exports.memory.buffer)[1] = 1
},
foo: () => {
instance.exports.reentry2()
},
bar: () => {
new Uint8Array(instance.exports.memory.buffer)[1] = 2
}
}
}
let wasm = await WebAssembly.instantiate(wasmBinary, imports)
instance = wasm.instance
instance.exports.main()
}

0 comments on commit 38332da

Please sign in to comment.