FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[release/9.0-staging] JIT: Fix invalid removal of explicit zeroing in methods without .localsinit by jakobbotsch · Pull Request #115568 · dotnet/runtime · GitHub

Repository navigation

[release/9.0-staging] JIT: Fix invalid removal of explicit zeroing in methods without .localsinit - #115568

Merged
jakobbotsch merged 3 commits into
dotnet:release/9.0-stagingfrom
jakobbotsch:fix-113658-backport
May 22, 2025
Merged

jakobbotsch merged 3 commits into
dotnet:release/9.0-stagingfrom
jakobbotsch:fix-113658-backport

Conversation

jakobbotsch commented May 14, 2025 •
edited
Loading

Copy link
Copy Markdown
Member

Backport of #115556 to release/9.0-staging

Customer Impact

  • Customer reported
  • Found internally

The JIT may mistakenly remove explicit field zeroing for some struct fields in methods without .localsinit (e.g. by having the SkipLocalsInit attribute applied in C#). This can happen when the IL first zero-initializes the full struct local using e.g. initobj, and then later zeroes a particular field of the struct local using stfld. Under certain circumstances, the JIT mistakenly eliminates both explicit zeroings of the field, leaving no zero initialization present, resulting in the field containing stack garbage.

Reported by customer in #113658.

Regression

  • Yes
  • No

This was exposed by support for cross-block assertion prop enabled in #94689.

Testing

Unit test added, and tested manually on user's test case.

Risk

Low

Copilot AI review requested due to automatic review settings May 14, 2025 16:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull Request Overview

This PR backports a fix to the JIT to address an issue where explicit zeroing of struct fields gets mistakenly removed in methods without .localsinit (when the SkipLocalsInit attribute is applied).

  • Ensures explicit field zeroing is preserved by killing dependent assertions for dead fields.
  • Adds a dedicated test case to validate the fix.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/tests/JIT/Regression/JitBlue/Runtime_113658/Runtime_113658.csproj New test project configuration for JIT regression.
src/tests/JIT/Regression/JitBlue/Runtime_113658/Runtime_113658.cs New test validating correct zeroing behavior.
src/coreclr/jit/morphblock.cpp Introduces calls to kill dependent assertions in field-by-field initialization and copy paths to prevent incorrect removal of zeroing.
Comments suppressed due to low confidence (2)

src/coreclr/jit/morphblock.cpp:409

  • Double-check that killing dependent assertions here correctly targets only fields that are truly dead, ensuring that no valid assertions are unintentionally removed.
m_comp->fgKillDependentAssertionsSingle(m_dstLclNum DEBUGARG(m_store));

src/coreclr/jit/morphblock.cpp:1238

  • Verify that the use of fgKillDependentAssertionsSingle in the field-by-field copy logic is consistent with its use in the initialization routine and does not remove assertions that should be preserved.
m_comp->fgKillDependentAssertionsSingle(m_dstLclNum DEBUGARG(m_store));

jakobbotsch added the Servicing-consider Issue for next servicing release review label May 14, 2025

jeffschwMSFT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

lgtm. please get a code review. we will take for consideration in 9.0.x

jeffschwMSFT added this to the 9.0.x milestone May 14, 2025
jakobbotsch requested review from AndyAyersMS and EgorBo May 14, 2025 16:29
jeffschwMSFT added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 15, 2025

Copy link
Copy Markdown
Contributor

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

rbhanda modified the milestones: 9.0.x, 9.0.7 May 20, 2025
rbhanda added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels May 20, 2025
jakobbotsch merged commit 331ddf9 into dotnet:release/9.0-staging May 22, 2025
jakobbotsch deleted the fix-113658-backport branch May 22, 2025 18:38
github-actions Bot locked and limited conversation to collaborators Jun 22, 2025
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.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL