Skip to content

Commit f472c74

Browse files
Translator: Preserve locals on the stack when entering a block
1 parent 428f0a7 commit f472c74

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed
Binary file not shown.

Sources/WasmKit/Translator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,7 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
11271127
mutating func visitBlock(blockType: WasmParser.BlockType) throws -> Output {
11281128
let blockType = try module.resolveBlockType(blockType)
11291129
let endLabel = iseqBuilder.allocLabel()
1130+
self.preserveLocalsOnStack(depth: self.valueStack.height)
11301131
let stackHeight = try popPushValues(blockType.parameters)
11311132
controlStack.pushFrame(ControlStack.ControlFrame(blockType: blockType, stackHeight: stackHeight, continuation: endLabel, kind: .block))
11321133
}

Tests/WasmKitTests/ExtraSuite/local_cow.wast

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,21 @@
4949
)
5050

5151
(assert_return (invoke "invalidate-relink" (i32.const 1) (i32.const 2)) (i32.const 2))
52+
53+
(module
54+
(global (mut i32) (i32.const 4))
55+
(func (export "check") (result i32)
56+
(local i32)
57+
global.get 0
58+
drop
59+
local.get 0
60+
block
61+
i32.const 1
62+
br_if 0
63+
i32.const 0
64+
local.set 0
65+
end
66+
)
67+
)
68+
69+
(assert_return (invoke "check") (i32.const 0))

0 commit comments

Comments
 (0)