Skip to content

JIT: Remove tailcall "has GC safe point" assert#123489

Merged
jakobbotsch merged 6 commits into
dotnet:mainfrom
jakobbotsch:fix-122481
Jan 28, 2026
Merged

JIT: Remove tailcall "has GC safe point" assert#123489
jakobbotsch merged 6 commits into
dotnet:mainfrom
jakobbotsch:fix-122481

Conversation

@jakobbotsch

@jakobbotsch jakobbotsch commented Jan 22, 2026

Copy link
Copy Markdown
Member

BBF_GC_SAFE_POINT is not kept up to date so we cannot reliably assert this. The assert was already disabled for fast tailcalls for that reason, so remove it from there and from JIT helper based tailcalls as well.

Fix #122481

Since tailcalls can form tight loops that do not allow for return
address hijacking we take care to introduce GC safe points in those
scenarios. We had an assert for this, but the assert can result in false
positives.

In the test case we have two tailcalls via JIT helpers, both in blocks
with GC safe points in them. Later tail merging merges them into a new
block without a GC safe point, and that makes the assert in lowering
hit, despite the fact that both preds are GC safe points.

Fix the assert by introducing a graph walk. Fast tailcalls can use the
same assert now, fixing a TODO-Cleanup at the same time.
@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 Jan 22, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@jakobbotsch

Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr jitstress

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@jakobbotsch jakobbotsch marked this pull request as ready for review January 23, 2026 08:52
Copilot AI review requested due to automatic review settings January 23, 2026 08:52
@jakobbotsch

Copy link
Copy Markdown
Member Author

cc @dotnet/jit-contrib PTAL @EgorBo

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.

Pull request overview

This PR updates the JIT’s debug-only tailcall “GC safe point” assertion logic to avoid false negatives caused by tail-merge creating a new block without a GC safe point, despite all predecessors being GC safe points.

Changes:

  • Replace the old tailcall-via-helper “current block OR entry block is a GC safe point” assert with a reachability-based check.
  • Apply the same reachability-based assert to fast tailcalls, removing the prior TODO-based workaround.
  • Introduce a DEBUG-only CFG walk helper (IsBlockReachableWithoutGCSafePoint) used by these asserts.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/lower.h Declares a new helper used by debug asserts to validate GC-safe-point reachability.
src/coreclr/jit/lower.cpp Updates tailcall asserts and adds a DEBUG-only CFG walk to avoid false negatives after tail merging.

Comment thread src/coreclr/jit/lower.cpp Outdated
Comment thread src/coreclr/jit/lower.cpp Outdated
@jakobbotsch

Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr jitstress, runtime-coreclr libraries-jitstress

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@jakobbotsch

Copy link
Copy Markdown
Member Author

In the end I removed the asserts, BBF_GC_SAFE_POINT is not kept up to date through the compilation so we can't reliably check whether there is a GC safe point using it.

@jakobbotsch jakobbotsch changed the title JIT: Improve precision of tailcall "has GC safe point" assert JIT: Remove tailcall "has GC safe point" assert Jan 26, 2026
@jakobbotsch

Copy link
Copy Markdown
Member Author

/ba-g Infra timeouts

Comment thread src/coreclr/jit/lower.h Outdated
@jakobbotsch jakobbotsch reopened this Jan 28, 2026
@jakobbotsch

Copy link
Copy Markdown
Member Author

/ba-g Known arm64 infra issues

@jakobbotsch jakobbotsch merged commit 1c7914a into dotnet:main Jan 28, 2026
123 of 131 checks passed
@jakobbotsch jakobbotsch deleted the fix-122481 branch January 28, 2026 22:34
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 28, 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

3 participants