Skip to content

Conversation

@jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Jan 22, 2026

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 negatives.

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.

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
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
Member Author

/azp run runtime-coreclr jitstress

@azure-pipelines
Copy link

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
Member Author

cc @dotnet/jit-contrib PTAL @EgorBo

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 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.

@jakobbotsch
Copy link
Member Author

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

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

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

2 participants