Skip to content

Commit 72cb0ce

Browse files
Fix miscompilation of relinking over local.get
1 parent e5b8264 commit 72cb0ce

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed
121 Bytes
Binary file not shown.

Sources/WasmKit/Translator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,7 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
14541454
}
14551455
}
14561456
mutating func visitLocalGet(localIndex: UInt32) throws -> Output {
1457+
iseqBuilder.resetLastEmission()
14571458
try valueStack.pushLocal(localIndex, locals: &locals)
14581459
}
14591460
mutating func visitLocalSetOrTee(localIndex: UInt32, isTee: Bool) throws {

Tests/WasmKitTests/ExtraSuite/local_cow.wast

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,17 @@
3434
)
3535

3636
(assert_return (invoke "check") (i32.const 0))
37+
38+
(module
39+
(func (export "invalidate-relink") (param i32 i32) (result i32)
40+
(i32.add (i32.const 1) (i32.const 42))
41+
;; This local.get should invalidate the relinking
42+
;; connection of i32.add even though it doesn't
43+
;; emit its own instruction.
44+
(local.get 1)
45+
(local.set 0)
46+
(local.get 0)
47+
)
48+
)
49+
50+
(assert_return (invoke "invalidate-relink" (i32.const 1) (i32.const 2)) (i32.const 2))

0 commit comments

Comments
 (0)