Repository navigation
JIT: Fix assertion in fgGetFirstILBlock for async methods with internal conditional blocks - #121616
Merged
Merged
Conversation
…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().
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
This was referenced Nov 14, 2025
Open
jakobbotsch
marked this pull request as ready for review
November 14, 2025 16:33
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. |
Contributor
There was a problem hiding this comment.
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 (viadoesMethodHaveRecursiveTailcall()) - Add null check before removing the BBF_CAN_ADD_PRED flag from
firstILBB
AndyAyersMS
approved these changes
Nov 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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().