diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs index b5f200735f9894..27b2d792466a6f 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs @@ -128,6 +128,7 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr int[] offsets = new int[methodSignature.Length]; bool[] isIndirectStructArg = new bool[methodSignature.Length]; + bool hasRetBuffArg = _wasmSignature.SignatureString[0] == 'S'; int argIndex = 0; int argOffset; @@ -195,6 +196,11 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr wasmLocalIndex++; } + if (hasRetBuffArg) + { + wasmLocalIndex++; + } + for (int i = 0; i < methodSignature.Length; i++) { TypeDesc paramType = methodSignature[i]; @@ -302,6 +308,13 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr wasmLocalIndex++; } + // Pass return buffer argument if needed + if (hasRetBuffArg) + { + expressions.Add(Local.Get(wasmLocalIndex)); + wasmLocalIndex++; + } + for (int i = 0; i < methodSignature.Length; i++) { TypeDesc paramType = methodSignature[i];