Repository navigation
Honor [UnscopedRef] on properties in canValueClassInstancePointerEscape - #137849
Merged
Merged
Conversation
C# emits `[UnscopedRef]` for a property on the property itself, not on its `get_` accessor. `canValueClassInstancePointerEscape` (VM and crossgen2/ILC) only looked at the method's own attributes, so for a devirtualized call to an `[UnscopedRef]` ref-returning property getter on a boxed struct, the JIT replaced the box with a stack copy and the returned ref pointed into a dead frame. Both implementations now also check the owning property when the method is a property accessor. The ECMA-335 augment (III.1.7.7) is updated to allow the annotation on the property for accessors. Fixes dotnet#137839 Co-authored-by: Copilot <[email protected]> Copilot-Session: a7d5e4f0-950c-4eb5-85e7-c5ba6a7533c0
|
Azure Pipelines: Successfully started running 4 pipeline(s). 11 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: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The regression’s AggressiveOptimization flag causes crossgen2 to skip the method, leaving the ReadyToRun fix untested without an invoked NoInlining-only variant.
1 open issue
What changed in this PR
This PR fixes escape analysis for boxed value types whose properties carry [UnscopedRef], preventing returned references from pointing into expired stack storage.
Changes:
- Check property-level attributes in the VM and shared crossgen2/NativeAOT escape analysis.
- Add a regression test for a ref-returning property on a boxed struct.
- Clarify property-accessor annotations in the ECMA-335 augment.
| File | Description |
|---|---|
src/tests/JIT/Regression_ro_2/Runtime_137839.cs |
Adds the boxed-struct property regression test. |
src/coreclr/vm/jitinterface.cpp |
Checks the owning property's [UnscopedRef] annotation. |
src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs |
Adds equivalent property checks for ahead-of-time compilation. |
docs/design/specs/Ecma-335-Augments.md |
Allows property-level annotations for accessors. |
Review effort: Balanced
Member
Author
|
PTAL @jkotas @jakobbotsch since it's related to #130863 |
jakobbotsch
approved these changes
Nov 18, 2026
jkotas
approved these changes
Nov 18, 2026
Member
Author
|
/ba-g filed #137875 |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

C# emits
[UnscopedRef]for a property on the property itself, not on itsget_accessor.canValueClassInstancePointerEscape(VM and crossgen2/ILC) only looked at the method's own attributes, so for a devirtualized call to an[UnscopedRef]ref-returning property getter on a boxed struct, the JIT replaced the box with a stack copy and the returned ref pointed into a dead frame.Both implementations now also check the owning property when the method is a property accessor. The ECMA-335 augment (III.1.7.7) is updated to allow the annotation on the property for accessors.
Fixes #137839