Skip to content

Commit 56b87a7

Browse files
lewingCopilot
andcommitted
Skip closed static retbuf adapters for calls with a Wasm generic context
With the dedicated 'g' token, RaiseSignature no longer returns the generic context as a parameter, so lowering the raised signature without hidden flags dropped it and tripped the FuncType assert. Delegate Invoke never takes a generic context, so treat 'g' like 'a' and don't create the adapter. Co-authored-by: Copilot App <[email protected]>
1 parent f6fea81 commit 56b87a7

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmClosedStaticRetBufThunkNode.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected override void EmitCode(NodeFactory factory, ref WasmEmitter instructio
6969
Debug.Assert(!instructionEncoder.Is64Bit);
7070
Debug.Assert(_signature.SignatureString[0] == 'S');
7171
Debug.Assert(!_signature.SignatureString.Contains('a'));
72+
Debug.Assert(!_signature.SignatureString.Contains('g'));
7273

7374
ReadOnlySpan<WasmValueType> parameters = _signature.FuncType.Params.Types;
7475
Debug.Assert(parameters.Length >= 4);

‎src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,12 +3832,13 @@ private void recordCallSite(uint instrOffset, CORINFO_SIG_INFO* callSig, CORINFO
38323832
AddAdditionalDependency(_compilation.NodeFactory.WasmR2RToInterpreterThunk(wasmSig), "R2R-to-interpreter thunk for call site");
38333833
MethodDesc method = methodHandle is null ? null : HandleToObject(methodHandle);
38343834
// A closed static delegate target needs an adapter only when Invoke returns
3835-
// through a hidden buffer ('S') and has no async-continuation hidden argument.
3835+
// through a hidden buffer ('S') and has no async-continuation or generic context hidden argument.
38363836
if (method is not null &&
38373837
method.OwningType.IsDelegate &&
38383838
method.Name == "Invoke"u8 &&
38393839
wasmSig.SignatureString[0] == 'S' &&
3840-
!wasmSig.SignatureString.Contains('a'))
3840+
!wasmSig.SignatureString.Contains('a') &&
3841+
!wasmSig.SignatureString.Contains('g'))
38413842
{
38423843
AddWasmClosedStaticRetBufThunkDependencies(wasmSig);
38433844
}
@@ -3874,10 +3875,11 @@ private void recordWasmManagedCallSig(CORINFO_SIG_INFO* callSig)
38743875
ReadOnlySpan<WasmValueType> parameters = wasmSig.FuncType.Params.Types;
38753876
// The adapter accepts the managed instance shape
38763877
// (sp, this, retbuf, ..., pep). Require an indirect aggregate return,
3877-
// no async-continuation argument, and pointer-typed this/retbuf positions.
3878+
// no async-continuation or generic context argument, and pointer-typed this/retbuf positions.
38783879
if (!sig.IsStatic &&
38793880
wasmSig.SignatureString[0] == 'S' &&
38803881
!wasmSig.SignatureString.Contains('a') &&
3882+
!wasmSig.SignatureString.Contains('g') &&
38813883
parameters.Length >= 4 &&
38823884
parameters[1] == WasmValueType.I32 &&
38833885
parameters[2] == WasmValueType.I32)

0 commit comments

Comments
 (0)