Skip to content

Commit a979cae

Browse files
Translator: Fix miscompilation in relinking optimization
All instructions that just pop values but do not push anything should invalidate the relinking state.
1 parent ca470ec commit a979cae

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed
Binary file not shown.

Sources/WasmKit/Translator.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
959959
guard try checkBeforePop(typeHint: type) else {
960960
return nil
961961
}
962+
iseqBuilder.resetLastEmission()
962963
return try valueStack.pop(type)
963964
}
964965

@@ -976,6 +977,7 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
976977
guard try checkBeforePop(typeHint: nil) else {
977978
return (.unknown, nil)
978979
}
980+
iseqBuilder.resetLastEmission()
979981
return try valueStack.pop()
980982
}
981983

Tests/WasmKitTests/ExtraSuite/br_if.wast

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@
1212

1313
(assert_return (invoke "brif_not_taken" (i32.const 3)) (i32.const 6))
1414

15+
(module
16+
(func (export "check")
17+
(local i64 i32 f32)
18+
i64.const 4
19+
;; use non-const nor local instruction to force
20+
;; leaving local.set at runtime
21+
i64.clz
22+
23+
i32.const 0
24+
i32.eqz
25+
;; popping the i32.eqz should invalidate the relinking state
26+
br_if 0
27+
local.set 0
28+
unreachable)
29+
)
30+
31+
32+
(invoke "check")

0 commit comments

Comments
 (0)