Merged
Conversation
The JIT attempts to deduce a class handle for the return type of TYP_REF calls, and almost always succeeds. However System.Array.Clone is special cased to return the type of its argument, and this argument may be a byref indir without a known managed type, so this deduction may fail. This causes the JIT to pass a null handle into the VM. Cope with this by setting the type instead of updating the type, if we discover it later via inlining. Closes dotnet#120522.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an access violation (AV) in the JIT compiler caused by a null class handle being passed to the VM. The issue occurs when the JIT tries to deduce the return type of System.Array.Clone() calls where the argument is a byref indir without a known managed type.
- Adds defensive logging when class handle deduction fails in the spill return expression helper
- Updates the inlining logic to properly handle cases where class handles are initially unknown by setting the type instead of updating it
- Includes a regression test that reproduces the original crash scenario
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/tests/JIT/Regression/JitBlue/Runtime_120522/Runtime_120522.csproj | Test project file for the regression test |
| src/tests/JIT/Regression/JitBlue/Runtime_120522/Runtime_120522.cs | Regression test that reproduces the AV scenario with Array.Clone() |
| src/coreclr/jit/importercalls.cpp | Adds defensive logging when class handle deduction fails |
| src/coreclr/jit/fginline.cpp | Fixes the core issue by checking for NO_CLASS_HANDLE and using lvaSetClass instead of lvaUpdateClass |
Member
Author
|
@EgorBo PTAL No diffs expected. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Member
Author
|
@dotnet/jit-contrib ping, this is a fairly straightforward fix. No diffs. |
JulieLeeMSFT
approved these changes
Oct 10, 2025
EgorBo
approved these changes
Oct 13, 2025
Member
Author
|
/backport to release/10.0 |
Contributor
|
Started backporting to |
4 tasks
steveisok
pushed a commit
that referenced
this pull request
Nov 12, 2025
Backport of #120575 to release/10.0 /cc @AndyAyersMS ## Customer Impact - [x] Customer reported - [ ] Found internally Reported by customer in #120522 ## Regression - [ ] Yes - [x] No Similar problem exists in .NET 8 and .NET 9. I intend to backport this fix there if we fix this in .NET 10. ## Testing Verified on the test case from the issue. ## Risk Low. The JIT special cases return type deductions for `Array.Clone`, and this issue only triggers if the argument to `Array.Clone` is a byref. The fix is a bit more general but is mainly defensive, handling cases where return type deductions fail. Co-authored-by: Andy Ayers <andya@microsoft.com>
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.
The JIT attempts to deduce a class handle for the return type of TYP_REF calls, and almost always succeeds. However System.Array.Clone is special cased to return the type of its argument, and this argument may be a byref indir without a known managed type, so this deduction may fail.
This causes the JIT to pass a null handle into the VM.
Cope with this by setting the type instead of updating the type, if we discover it later via inlining.
Closes #120522.