Skip to content

JIT: Fix assertion in fgGetFirstILBlock for async methods with internal conditional blocks - #121616

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
jakobbotsch:firstbb-assert
Nov 14, 2025
Merged

jakobbotsch merged 1 commit into
dotnet:mainfrom
jakobbotsch:firstbb-assert

Conversation

@jakobbotsch

Copy link
Copy Markdown
Member

The fgGetFirstILBlock() function was being called unconditionally during morph to allow edge creation for tail-call-to-loop optimization. However, this function assumes all BBF_INTERNAL blocks before the first IL block are BBJ_ALWAYS, which is not true for async methods with exception save/restore context where internal blocks can be conditional (because of introducing and inlining a call to save contexts).

Fix by only calling fgGetFirstILBlock() when the method actually has recursive tail calls that need to be converted to loops, checked via doesMethodHaveRecursiveTailcall().

…al conditional blocks

The fgGetFirstILBlock() function was being called unconditionally during
morph to allow edge creation for tail-call-to-loop optimization.
However, this function assumes all BBF_INTERNAL blocks before the first
IL block are BBJ_ALWAYS, which is not true for async methods with
exception save/restore context where internal blocks can be conditional
(because of introducing and inlining a call to save contexts).

Fix by only calling fgGetFirstILBlock() when the method actually has
recursive tail calls that need to be converted to loops, checked via
doesMethodHaveRecursiveTailcall().
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 14, 2025
@jakobbotsch jakobbotsch added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI runtime-async and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 14, 2025
@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.

@jakobbotsch

Copy link
Copy Markdown
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

Some minor diffs. I haven't looked closely, but I imagine that happens when we now allow using assertions into the first IL block because there is no recursive tailcall.

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 fixes an assertion failure in fgGetFirstILBlock() that occurred for async methods with internal conditional blocks. The function was being called unconditionally during the morph phase but assumed all BBF_INTERNAL blocks before the first IL block are BBJ_ALWAYS, which is not true for async methods with exception save/restore contexts.

Key Changes:

  • Conditionally call fgGetFirstILBlock() only when the method has recursive tail calls (via doesMethodHaveRecursiveTailcall())
  • Add null check before removing the BBF_CAN_ADD_PRED flag from firstILBB

@jakobbotsch
jakobbotsch merged commit 4d8ec94 into dotnet:main Nov 14, 2025
@jakobbotsch
jakobbotsch deleted the firstbb-assert branch November 14, 2025 22:49
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 15, 2025
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 runtime-async

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants