Repository navigation
[Interpreter] Record the next instruction's ip before calling a managed helper - #135464
Merged
Merged
Conversation
…ed helper The native-helper exits of INTOP_CALL_HELPER_* and INTOP_UNBOX_ANY[_GENERIC] left pFrame->ip at the start of the instruction while the helper ran. An exception thrown by a managed helper reaches the interpreter frame through managed dispatch, which treats the frame's ip as a return address and moves it back by STACKWALK_CONTROLPC_ADJUST_OFFSET. When the helper call started a try region, as the static-base helper does for a static field access on a type with a .cctor, the adjusted ip fell before the region and its handlers did not run. Record the next instruction's ip before the native helper call, as INTOP_CALL and the IL-target exits of the same opcodes already do. Fixes dotnet#135455
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke |
BrzVlad
reviewed
Oct 9, 2026
Replace SAVE_IP_BEFORE_HELPER_CALL with explicit `pFrame->ip = ip + N`, and remove the store of the instruction start at the top of the helper opcodes that call nothing but GetPossiblyIndirectHelper before the helper. Keep it in the opcodes that call DoGenericLookup first: that lookup can throw and trigger a GC, and its exceptions mark the frame faulting, so the ip has to be the start of the instruction for them.
BrzVlad
reviewed
Oct 9, 2026
Take TestCctorExceptionAtTryStart out of the interpreter bring-up suite and add it as src/tests/Regressions/coreclr/GitHub_135455, with the same cases.
janvorli
reviewed
Oct 9, 2026
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli |
Instead of storing ip + N before the helper call and adding N again after it, advance ip first and store that, as INTOP_CALL does.
BrzVlad
approved these changes
Oct 13, 2026
Member
|
/ba-g diagnostics failure unrelated |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 #135455.
The native-helper exits of
INTOP_CALL_HELPER_*andINTOP_UNBOX_ANY[_GENERIC]leftpFrame->ipat the start of the instruction while the helper ran. The helpers that can throw there are managed code, so an exception from one reaches the interpreter frame through managed dispatch: the frame is not marked faulting, andSfiInitWorker/SfiNextWorkertreat its ip as a return address and subtractSTACKWALK_CONTROLPC_ADJUST_OFFSET. When the helper call is the first instruction of a try region, as the static-base helper is for a static field access on a type with a.cctor, the adjusted ip falls before the region and its handlers do not run.INTOP_CALL, and the IL-target exits of the same opcodes (ip += N; goto CALL_INTERP_METHOD), already record the next instruction's ip. The native helper exits now do the same: they advanceipand store it before the helper call.The
pFrame->ip = ipat the top of each case is gone where onlyGetPossiblyIndirectHelperruns before the helper. It stays in the five opcodes that callDoGenericLookupfirst (INTOP_CALL_HELPER_P_G,P_GS,P_GA,V_AGSandINTOP_UNBOX_ANY_GENERIC): that lookup can throw and can trigger a GC, and its exceptions are C++ exceptions, which the unwind-and-continue handler inInterpExecMethodcatches and marks the frame faulting, so the instruction start is right for them.Test:
src/tests/Regressions/coreclr/GitHub_135455puts the static access first in both a try/finally and an enclosing try/catch. It covers the first access, the access that rethrows the recorded failure, and a shared-generic instantiation, which takes theINTOP_CALL_HELPER_P_Gpath. The project setsOptimizeso that the access stays the first instruction of the region in every build configuration.Validation (Checked runtime, at this PR's base), with the test run under the JIT and under
DOTNET_InterpMode1, 2 and 3:TypeInitializationExceptionescapes)TypeInitializationExceptionescapes)TypeInitializationExceptionescapes)Storing the instruction start again in
INTOP_CALL_HELPER_P_Pmakes the test fail under the interpreter on all three platforms. Under the JIT the test passes with and without the fix.The test ran through the merged
Regressionsrunner, as it does in CI. The existingRegressions/coreclr/GitHub_135234test (from #135290) hits the same bug: on osx-arm64 it fails underDOTNET_InterpMode1 and 3 at this PR's base and passes with the fix.With the fix,
JIT/interpreterpasses on linux-x64 and osx-arm64. On windows-x64 it passes up toTestPInvoke, which I could not run there because the native test assets did not build on that machine; the test assemblies used there were the ones built on macOS.Other places that store the start of an instruction and then call out, and why they are not changed here:
INTOP_NEWARR[_GENERIC]: the allocation failure is raised from the helper's ownDynamicHelperFrame, so the frame is not faulting there either. Anewarrcannot be the first instruction of a try region, though: its length is always loaded by a separate instruction inside the region, and nothing folds that load away today. It would become reachable with copy propagation.Note
This PR was prepared with AI assistance (Anthropic Claude, reviewed by OpenAI Codex). The builds and runs it cites were done at the PR's base commit.