From 9a72df7dab460fbd8b3a45a63b10cff3214899fe Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Tue, 11 Aug 2026 16:42:54 -0700 Subject: [PATCH] Crossgen2: don't mutate getCallInfo token Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4a1c1a0f-9329-402a-ac6d-b19087898fa6 --- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 565034235355b5..4ec656fa67a58f 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -2473,6 +2473,9 @@ private void VerifyMethodSignatureIsStable(MethodSignature methodSig) private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESOLVED_TOKEN* pConstrainedResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle, CORINFO_CALLINFO_FLAGS flags, CORINFO_CALL_INFO* pResult) { + // Constraint resolution may update tokenType for internal bookkeeping, but getCallInfo + // treats the resolved token as input and must not expose that mutation to the caller. + CORINFO_RESOLVED_TOKEN resolvedToken = pResolvedToken; MethodDesc methodToCall; MethodDesc targetMethod; TypeDesc constrainedType; @@ -2482,7 +2485,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO EcmaModule callerModule; bool useInstantiatingStub; ceeInfoGetCallInfo( - ref pResolvedToken, + ref resolvedToken, pConstrainedResolvedToken, callerHandle, flags, @@ -2550,7 +2553,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO pResult->codePointerOrStubLookup.constLookup = CreateConstLookupToSymbol( _compilation.SymbolNodeFactory.DispatchCell( - ComputeMethodWithToken(targetMethod, ref pResolvedToken, constrainedType: null, unboxing: false), + ComputeMethodWithToken(targetMethod, ref resolvedToken, constrainedType: null, unboxing: false), MethodBeingCompiled)); // If the abi of the method isn't stable, this will cause a usage of the RequiresRuntimeJitSymbol, which will trigger a RequiresRuntimeJitException @@ -2611,7 +2614,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO // READYTORUN: FUTURE: Direct calls if possible pResult->codePointerOrStubLookup.constLookup = CreateConstLookupToSymbol( _compilation.NodeFactory.MethodEntrypoint( - ComputeMethodWithToken(nonUnboxingMethod, ref pResolvedToken, constrainedType, unboxing: isUnboxingStub), + ComputeMethodWithToken(nonUnboxingMethod, ref resolvedToken, constrainedType, unboxing: isUnboxingStub), isInstantiatingStub: useInstantiatingStub, isPrecodeImportRequired: (flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_LDFTN) != 0, isJumpableImportRequired: false)); @@ -2635,7 +2638,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO { pResult->codePointerOrStubLookup.constLookup = CreateConstLookupToSymbol( _compilation.NodeFactory.DynamicHelperCell( - ComputeMethodWithToken(targetMethod, ref pResolvedToken, constrainedType: null, unboxing: false), + ComputeMethodWithToken(targetMethod, ref resolvedToken, constrainedType: null, unboxing: false), useInstantiatingStub)); // Wasm routes all virtual calls through LDVIRTFTN (stub dispatch is unsupported), @@ -2665,7 +2668,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO { pResult->instParamLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.CreateReadyToRunHelper( ReadyToRunHelperId.MethodDictionary, - ComputeMethodWithToken(targetMethod, ref pResolvedToken, constrainedType: constrainedType, unboxing: false))); + ComputeMethodWithToken(targetMethod, ref resolvedToken, constrainedType: constrainedType, unboxing: false))); } else {