Skip to content

Commit ea32e27

Browse files
authored
[Wasm] Add missing return buffer argument in wasm import thunks (#128104)
For wasm import thunks with a return buffer argument, we weren't accounting for it and the result was an unbalanced stack.
1 parent da574bb commit ea32e27

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

  • src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun

src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr
128128

129129
int[] offsets = new int[methodSignature.Length];
130130
bool[] isIndirectStructArg = new bool[methodSignature.Length];
131+
bool hasRetBuffArg = _wasmSignature.SignatureString[0] == 'S';
131132

132133
int argIndex = 0;
133134
int argOffset;
@@ -195,6 +196,11 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr
195196
wasmLocalIndex++;
196197
}
197198

199+
if (hasRetBuffArg)
200+
{
201+
wasmLocalIndex++;
202+
}
203+
198204
for (int i = 0; i < methodSignature.Length; i++)
199205
{
200206
TypeDesc paramType = methodSignature[i];
@@ -302,6 +308,13 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr
302308
wasmLocalIndex++;
303309
}
304310

311+
// Pass return buffer argument if needed
312+
if (hasRetBuffArg)
313+
{
314+
expressions.Add(Local.Get(wasmLocalIndex));
315+
wasmLocalIndex++;
316+
}
317+
305318
for (int i = 0; i < methodSignature.Length; i++)
306319
{
307320
TypeDesc paramType = methodSignature[i];

0 commit comments

Comments
 (0)