[Wasm] Add missing return buffer argument in wasm import thunks#128104
Draft
kg wants to merge 3 commits into
Draft
[Wasm] Add missing return buffer argument in wasm import thunks#128104kg wants to merge 3 commits into
kg wants to merge 3 commits into
Conversation
kg
commented
May 12, 2026
| // Pass return buffer argument if needed | ||
| if (hasRetBuffArg) | ||
| { | ||
| expressions.Add(Local.Get(1)); |
Member
Author
There was a problem hiding this comment.
Is this always going to be local 1 or will there be cases where it's 0? Statics?
Member
There was a problem hiding this comment.
Order is:
$spif managedthisif instance method- retBuff if returning struct by-ref
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the WebAssembly import thunk emitter in the ReadyToRun AOT toolchain to account for signatures that require a hidden return-buffer (struct return) argument, preventing invalid wasm codegen at indirect call sites.
Changes:
- Detect struct-return signatures that require a hidden return buffer argument.
- Attempt to push the return buffer argument before the final
call_indirectdispatch in the import thunk.
| // Pass return buffer argument if needed | ||
| if (hasRetBuffArg) | ||
| { | ||
| expressions.Add(Local.Get(hasThis ? 1 : 0)); |
Comment on lines
129
to
132
| int[] offsets = new int[methodSignature.Length]; | ||
| bool[] isIndirectStructArg = new bool[methodSignature.Length]; | ||
| bool hasRetBuffArg = _wasmSignature.SignatureString[0] == 'S'; | ||
|
|
This was referenced May 13, 2026
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.
Fixes errors like
cc @davidwrighton @AndyAyersMS