Skip to content

JIT: Treat stores to EH-live locals as visible when hoisting - #135850

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:jit-fix-134938
Oct 16, 2026
Merged

EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:jit-fix-134938

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

HoistVisitor considered a local store globally visible only if the local was address-exposed, so m_canHoistSideEffects stayed true after state = i + 1 and a later throwing a / b was hoisted into the preheader. But state is live into the catch handler, which then observed the old value.

Fix: also treat stores to locals that are live in/out of a handler (or untracked) as visible when the block may throw into a handler. No asm diffs in libraries.pmi.

Fixes #134938

A few diffs

`HoistVisitor` considered a local store globally visible only if the local was
address-exposed, so `m_canHoistSideEffects` stayed true after `state = i + 1`
and a later throwing `a / b` was hoisted into the preheader. But `state` is live
into the catch handler, which then observed the old value.

Fix: also treat stores to locals that are live in/out of a handler (or
untracked) as visible when the block may throw into a handler. No asm diffs in
libraries.pmi.

Fixes dotnet#134938

Co-authored-by: Copilot <[email protected]>
Copilot-Session: ef747772-3030-470e-b839-f9a4fc116717
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 15, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

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.

🔵 Needs a closer look

Exception-sensitive JIT code motion needs maintainer confirmation and checked-runtime regression validation, which was not performed in this review.

0 open findings

What changed in this PR

Fixes loop hoisting that could move a throwing expression ahead of a local store observable by an exception handler, causing the handler to see stale state.

Changes:

  • Treats handler-live or untracked local stores as visible when the block has potential exception-handler successors.
  • Adds a regression test verifying that the catch handler observes the updated local value.
File Description
src/​tests/​JIT/​Regression_ro_2/​Runtime_134938.cs Tests local-state visibility after division throws.
src/​coreclr/​jit/​optimizer.cpp Extends store-visibility checks used by loop hoisting.

🧠 Review effort: Balanced

@EgorBo

EgorBo commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib, trivial change, a few diffs

@EgorBo
EgorBo merged commit d1cf7ba into dotnet:main Oct 16, 2026
134 of 138 checks passed
@EgorBo
EgorBo deleted the jit-fix-134938 branch October 16, 2026 23:53
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 19, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: (bug) loop hoisting moves a throwing expression above a store to an EH-live local

3 participants