[interp] Fix wasm-interp stack cleanup for tail calls - #2835
Open
KKiiim wants to merge 1 commit into
Open
Conversation
KKiiim
force-pushed
the
fix-interp-return-call
branch
2 times, most recently
from
August 25, 2026 09:29
a1d3749 to
fee30e3
Compare
sbc100
reviewed
Aug 25, 2026
|
|
||
| FuncType& func_type = func_types_[func_index]; | ||
| Index param_count; | ||
| if (!validator_.GetFuncParamCount(func_index, ¶m_count)) { |
Member
There was a problem hiding this comment.
Why pull this information from the validator if we have our own func_types_ array?
IIUC that validator is not normally the source of this kind of information is it?
| Index param_count; | ||
| if (!validator_.GetFuncParamCount(func_index, ¶m_count)) { | ||
| return validator_.OnReturnCall(GetLocation(), | ||
| Var(func_index, GetLocation())); |
Member
There was a problem hiding this comment.
Can you add a comment as to why we have this early return when param count is zero? Can't the generic code below handle zero params?
Contributor
Author
|
Yes. Thanks for your advice. Current change: Compute and emit the correct This bug can be reproduced using the function |
KKiiim
force-pushed
the
fix-interp-return-call
branch
2 times, most recently
from
August 26, 2026 05:52
1b8220a to
6fe4e91
Compare
KKiiim
force-pushed
the
fix-interp-return-call
branch
from
August 26, 2026 06:23
6fe4e91 to
e430599
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix incorrect value-stack cleanup when lowering
return_callandreturn_call_indirectinwasm-interp.The interpreter emits
drop_keepbefore a tail call to discard values below the callee arguments. The cleanup counts must be calculated from the validator's current type stack. Previously, the return-call validator was invoked before that calculation, consuming the tail-call operands and making the computed drop count incorrect.As a result, dead operand-stack values could survive an imported tail call and later be observed as a caller result.
Fix
Get the callee parameter count from the validator, then compute
drop_keepand catch cleanup before validation consumes the operands. Invalid indexes remain handled by the validator.Tests
Add minimal direct and indirect imported tail-call regressions where a dead value below the tail-call arguments must not escape into the caller.
Verified with the focused interpreter tail-call tests and the original fuzz reproducer, which now returns
i32:0.