Skip to content

[release/10.0] Fix missing call to write barrier in static constructors of ref structs#125613

Open
janvorli wants to merge 1 commit intodotnet:release/10.0from
janvorli:port-fix-refclass-contructor-codegen
Open

[release/10.0] Fix missing call to write barrier in static constructors of ref structs#125613
janvorli wants to merge 1 commit intodotnet:release/10.0from
janvorli:port-fix-refclass-contructor-codegen

Conversation

@janvorli
Copy link
Member

This change fixes it and adds a regression test that causes fatal error when run with DOTNET_HeapVerify=1.

Backport of #125418 to release/10.0

Customer Impact

  • Customer reported
  • Found internally

A customer has reported intermittent crashes in their application after migrating to .NET 10. Analysis has revealed GC heap corruption where a reference field of an object was pointing to a stale address of another object.
The JIT was incorrectly handling initialization of static fields of ref structs. It was not adding call to JIT_ByRefWriteBarrier when setting these fields even though these statics live in GC heap.

Regression

Testing

CI tests, local manual directed test provided by the customer

Risk

Low, the change just adds write barrier call for static fields of ref structs that were missing.

…rs of ref structs

The JIT was incorrectly handling initialization of static fields of ref
structs. It was not adding call to JIT_ByRefWriteBarrier when setting
these fields even though these statics live in GC heap.

This issue was introduced in .NET 10 in dotnet#111733

This change fixes it and adds a regression test that causes fatal error
when run with DOTNET_HeapVerify=1.
@janvorli janvorli added this to the 10.0.x milestone Mar 16, 2026
@janvorli janvorli requested a review from EgorBo March 16, 2026 13:46
@janvorli janvorli self-assigned this Mar 16, 2026
@janvorli janvorli added Servicing-consider Issue for next servicing release review area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labels Mar 16, 2026
Copilot AI review requested due to automatic review settings March 16, 2026 13:46
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a CoreCLR JIT importer annotation bug where stores to static fields declared on byref-like (ref struct) types could be incorrectly treated as targeting a non-heap location, which can suppress required write barriers and lead to GC heap corruption.

Changes:

  • Update importer logic to only mark “field owner is byref-like ⇒ target not on heap” for non-static fields.
  • Clarify the comment to reflect the corrected condition (byref-like owner and non-static).

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI Servicing-consider Issue for next servicing release review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants