Skip to content

JIT: Restore EH-region check in if-conversion flow validation#127450

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-jit-assertion-failure
Draft

JIT: Restore EH-region check in if-conversion flow validation#127450
Copilot wants to merge 3 commits intomainfrom
copilot/fix-jit-assertion-failure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 27, 2026

A Fuzzlyn-generated repro hits assert(!block->HasFlag(BBF_DONT_REMOVE)) during the JIT's If conversion phase when the Then block is the start of a try region. Bisected to dea4756 (#125347), which simplified IfConvertCheckFlow and inadvertently dropped the BasicBlock::sameEHRegion check previously performed by IfConvertCheckInnerBlockFlow. Without it, if-conversion proceeds on a Then/Else block that begins an EH region, then trips the assert when later removing it.

Changes

  • src/coreclr/jit/ifconversion.cpp — In OptIfConversionDsc::IfConvertCheckFlow, bail when falseBb (Then) or trueBb (Else, when present) is not in the same EH region as m_startBlock.
  • src/tests/JIT/Regression/JitBlue/Runtime_127446/Runtime_127446.cs — Regression test using the original repro. The test source is added to the shared merged src/tests/JIT/Regression/Regression_o_3.csproj (alongside other JitBlue regression tests); no per-test csproj or environment variables are needed.
if (falseBb->GetUniquePred(m_compiler) == nullptr)
{
    return false;
}

// Then/Else are removed by if-conversion, so they must share m_startBlock's EH
// region; otherwise they may be a try/handler entry (BBF_DONT_REMOVE).
if (!BasicBlock::sameEHRegion(falseBb, m_startBlock))
{
    return false;
}

m_doElseConversion = trueBb->GetUniquePred(m_compiler) != nullptr;
m_finalBlock       = m_doElseConversion ? trueBb->GetUniqueSucc() : trueBb;

if (m_doElseConversion && !BasicBlock::sameEHRegion(trueBb, m_startBlock))
{
    return false;
}

Verified the assert reproduces on the unfixed JIT and is gone with the fix; the new test passes through the merged test runner (global::Runtime_127446.Runtime_127446.TestEntryPoint() → Passed).

Copilot AI requested review from Copilot and removed request for Copilot April 27, 2026 12:17
@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 Apr 27, 2026
Copilot AI requested review from Copilot and removed request for Copilot April 27, 2026 12:50
@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 changed the title [WIP] Fix JIT assertion failure during If conversion JIT: Restore EH-region check in if-conversion flow validation Apr 27, 2026
Copilot AI requested a review from EgorBo April 27, 2026 12:55
@BoyBaykiller
Copy link
Copy Markdown
Contributor

BoyBaykiller commented Apr 27, 2026

Maybe I should just directly check for BBF_DONT_REMOVE. This handles BasicBlock::sameEHRegion and anything else...

@EgorBo
Copy link
Copy Markdown
Member

EgorBo commented Apr 27, 2026

@copilot please delete Runtime_127446.csproj, juse use the shared csproj, we don't need explicit env vars for this.

Copilot AI requested review from Copilot and removed request for Copilot April 27, 2026 23:30
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 27, 2026

@copilot please delete Runtime_127446.csproj, juse use the shared csproj, we don't need explicit env vars for this.

Done in 1a10c80 — removed Runtime_127446.csproj and added the test to the shared merged JIT/Regression/Regression_o_3.csproj. Verified it runs and passes through the merged runner (global::Runtime_127446.Runtime_127446.TestEntryPoint() → Passed).

Note

This reply was AI-generated by GitHub Copilot.

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: Assertion failed '!block->HasFlag(BBF_DONT_REMOVE)' during 'If conversion'

3 participants