Skip to content

JIT: use a call GC poll for blocks that end an EH region - #134100

Open
EgorBo wants to merge 1 commit into
dotnet:mainfrom
EgorBo:fix-134005-gcpoll-ehret
Open

EgorBo wants to merge 1 commit into
dotnet:mainfrom
EgorBo:fix-134005-gcpoll-ehret

Conversation

@EgorBo

@EgorBo EgorBo commented Sep 16, 2026

Copy link
Copy Markdown
Member

Thread.FastPollGC() (inlined from Buffer.BulkMoveWithWriteBarrier) can land in the block that terminates an EH region. fgInsertGCPolls asserted that such a block was one of the kinds the inline poll expansion knows how to split, so e.g. a Span<object>.CopyTo at the end of a finally or catch tripped 'block->KindIs(BBJ_RETURN, BBJ_ALWAYS, BBJ_COND, BBJ_SWITCH, BBJ_THROW, BBJ_CALLFINALLY)' (and would have hit a NO_WAY in release).

An inline poll splits the block and fgCreateGCPoll only knows how to move the outgoing flow of the kinds above onto the new bottom block, so select a call poll for blocks with hasEHBoundaryOut(), just like we already do for switches. The call poll path already handles those blocks correctly.

Fixes #134005

No diffs

`Thread.FastPollGC()` (inlined from `Buffer.BulkMoveWithWriteBarrier`) can
land in the block that terminates an EH region. `fgInsertGCPolls` asserted
that such a block was one of the kinds the inline poll expansion knows how to
split, so e.g. a `Span<object>.CopyTo` at the end of a `finally` or `catch`
tripped 'block->KindIs(BBJ_RETURN, BBJ_ALWAYS, BBJ_COND, BBJ_SWITCH, BBJ_THROW,
BBJ_CALLFINALLY)' (and would have hit a `NO_WAY` in release).

An inline poll splits the block and `fgCreateGCPoll` only knows how to move
the outgoing flow of the kinds above onto the new bottom block, so select a
call poll for blocks with `hasEHBoundaryOut()`, just like we already do for
switches. The call poll path already handles those blocks correctly.

Fixes dotnet#134005

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 16, 2026 19:54
@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 Sep 16, 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

The JIT control-flow change at EH boundaries warrants final human review.

Pull request overview

Fixes JIT GC poll insertion for blocks ending EH regions by routing them through call polls, with regression coverage for finally and catch cases.

Changes:

  • Selects call GC polls for EH-boundary blocks.
  • Adds Runtime_134005 regression coverage.
File summaries
File Summary
src/tests/JIT/Regression_ro_2/Runtime_134005.cs Tests the reported finally and catch scenarios.
src/coreclr/jit/flowgraph.cpp Routes EH-boundary blocks to call GC polls.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

@EgorBo
EgorBo requested a review from AndyAyersMS September 16, 2026 21:51
@EgorBo

EgorBo commented Sep 16, 2026

Copy link
Copy Markdown
Member Author

PTAL @AndyAyersMS @dotnet/jit-contrib simple fix, no diffs.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: (bug) GC poll insertion asserts when a poll lands in an EH-return block

2 participants