Skip to content

Commit 6c8284c

Browse files
Fix a miscompilation in const slotting and result relinking
1 parent 4f150c1 commit 6c8284c

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed
116 Bytes
Binary file not shown.

Sources/WasmKit/Translator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,7 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
16361636
private mutating func visitConst(_ type: ValueType, _ value: Value) {
16371637
if let constSlotIndex = constantSlots.allocate(value) {
16381638
valueStack.pushConst(constSlotIndex, type: type)
1639+
iseqBuilder.resetLastEmission()
16391640
return
16401641
}
16411642
let value = UntypedValue(value)
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(module
2-
(func (export "check") (param i32) (result i32)
2+
(func (export "check-limit") (param i32) (result i32)
33
;; Enough to reach the limit of constant slots
44
(drop (i32.const 1))
55
(drop (i32.const 2))
@@ -9,7 +9,18 @@
99
(drop (i32.const 6))
1010
(i32.add (local.get 0) (i32.add (i32.const 1) (i32.const 1)))
1111
)
12+
(func (export "invalidate-relink") (result i32)
13+
(local i32)
14+
(i32.add (i32.const 1) (i32.const 1))
15+
;; This constant should invalidate the relinking
16+
;; connection of i32.add even though it doesn't
17+
;; emit its own instruction.
18+
(i32.const 0)
19+
(local.set 0)
20+
(local.get 0)
21+
)
1222
)
1323

14-
(assert_return (invoke "check" (i32.const 3)) (i32.const 5))
24+
(assert_return (invoke "check-limit" (i32.const 3)) (i32.const 5))
25+
(assert_return (invoke "invalidate-relink") (i32.const 0))
1526

0 commit comments

Comments
 (0)