radik878 opened PR #12609 from radik878:fix/sign-extend-bug to bytecodealliance:main:
What was wrong: The sign extension operators (
i32.extend8_s,i32.extend16_s,i64.extend8_s,i64.extend16_s,i64.extend32_s) were incorrectly discarding theireduceresult. The code was pushing theireduceresult to the value stack and then immediately popping a different value (the next value on the stack) for thesextendoperation.
Changes: Store theireduceresult in a local variable and use it directly insextendinstead of popping from the stack.
radik878 requested fitzgen for a review on PR #12609.
radik878 requested wasmtime-compiler-reviewers for a review on PR #12609.
cfallin commented on PR #12609:
@radik878 I don't think your description is correct.
The existing code pops, reduces, pushes; then pops, sign-extends, and pushes. The intermediate push-then-pop has the effect of carrying through the result of the reduce to the sign-extend. Nothing is discarded, and the "next value on the stack" is not used.
I didn't write this code so I don't know the intent for sure but I can imagine this is meant to express the operator as a composition of the two operations. It's a little odd, but it's not incorrect.
Your description ("fix") implies that you observed an incorrect execution. Did you, and if so can you show the test case here? And can you explain your reasoning a bit more?
Last updated: Feb 24 2026 at 04:36 UTC