Repository navigation
Description
The following example, found by Fuzzlyn, causes a JIT assertion failure on arm64 (SVE):
// Generated by Fuzzlyn v3.3 on 2026-07-05 16:50:02
// Run on Arm64 Linux
// Seed: 9930514512682849353-vectort,vector64,vector128,armadvsimd,armadvsimdarm64,armaes,armarmbase,armarmbasearm64,armcrc32,armcrc32arm64,armdp,armrdm,armrdmarm64,armsha1,armsha256,armsve,armsve2
// Reduced from 52.5 KiB to 0.9 KiB in 00:03:06
// Hits JIT assert for Release:
// Assertion failed '(block->bbRefs == 0) && (block->bbPreds == nullptr)' in 'Program:M0()' during 'Remove empty try-catch-fault 3' (IL size 146; hash 0xaf50ff37; FullOpts)
//
// File: /__w/1/s/src/coreclr/jit/fgbasic.cpp Line: 5110
//
using System.Numerics;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
public class Program
{
public static Vector128<long> s_2;
public static long s_4;
public static void Main()
{
M0();
}
public static void M0()
{
ref Vector128<long> var0 = ref s_2;
var vr2 = Vector128.CreateScalar(-1201041991713307749L).AsVector();
var vr3 = Vector.Create<long>(s_4);
var vr4 = Vector.Create<long>(0);
try
{
var0 = Vector128.Create<long>(0);
}
catch (System.Exception)when (Sve.TestFirstTrue(vr2, Sve.ExtractVector(vr3, vr4, 47)))
{
var vr0 = Vector128.CreateScalar(0).AsVector();
var vr1 = Vector.Create<sbyte>(0);
var vr5 = (Vector<sbyte>)Vector128.CreateScalar(0).AsVector();
Sve.DotProductBySelectedScalar(vr0, vr1, vr5, 14);
}
}
}The assertion:
Assertion failed '(block->bbRefs == 0) && (block->bbPreds == nullptr)' in 'Program:M0()' during 'Remove empty try-catch-fault 3' (IL size 146; hash 0xaf50ff37; FullOpts)
File: /__w/1/s/src/coreclr/jit/fgbasic.cpp Line: 5110
Analysis of jitdump (AI-generated)
[!NOTE]
The following analysis was generated by AI (GitHub Copilot) and may contain inaccuracies.
Analysis (AI-generated)
Assertion: (block->bbRefs == 0) && (block->bbPreds == nullptr)
Location: src/coreclr/jit/fgbasic.cpp:5110 (Compiler::fgRemoveBlock, unreachable path)
Phase: Remove empty try-catch-fault (fgRemoveEmptyTryCatchOrTryFault), target arm64/SVE.
Flow graph entering the phase
BBnum preds kind EH region
BB01 -> BB02 (always)
BB02 BB01 -> BB08 T0 try { }
BB03 cond BB05/04 H0 filter { (hascall)
BB04 BB03 -> BB06 H0
BB05 BB03 -> BB09 H0
BB09 BB05,BB07 (throw) H0 (hascall) <-- ref 2
BB06 BB04 -> BB07 H0 } (fltret)
BB07 BB06 -> BB09 H0 filtHnd { }
BB08 BB02 (return)
EH table: Try BB02..BB02, Filter BB03..BB06, Handler BB07..BB07.
Note the physical block order is BB03, BB04, BB05, BB09, BB06, BB07: the
BBJ_THROW block BB09 (the argument-out-of-range throw helper generated for
Sve.ExtractVector(vr3, vr4, 47)'s immediate) sits between the filter blocks
and the fltret block BB06. BB09 has two predecessors: BB05 (a filter
block) and BB07 (the filter's handler block).
What the phase does
The try region is empty, so fgRemoveEmptyTryCatchOrTryFault removes the whole
try/filter/handler. It removes the filter blocks in two passes:
// firstFltBlock = ebdFilter (BB03); afterLastFltBlock = BBFilterLast()->Next() (BB06->Next() = BB07)
for (filterBlock = firstFltBlock; filterBlock != afterLastFltBlock; filterBlock = filterBlock->Next())
{
fgRemoveBlockAsPred(filterBlock);
filterBlock->SetKind(BBJ_THROW);
}
for (filterBlock = firstFltBlock; filterBlock != afterLastFltBlock; filterBlock = filterBlock->Next())
{
filterBlock->RemoveFlags(BBF_DONT_REMOVE);
fgRemoveBlock(filterBlock, /* unreachable */ true);
}Both loops walk the physical block list with ->Next() from ebdFilter
(BB03) up to BBFilterLast()->Next() (BB07). Because BB09 is physically
located between BB05 and BB06, it is swept into the filter-removal range even
though it is a handler throw block, not a filter block.
The JitDump confirms the removal order: BB03, BB04, BB05, then BB09.
Why the assert fires
- First pass unlinks the outgoing preds of BB03/BB04/BB05/BB09/BB06 and sets
them toBBJ_THROW. This removes theBB05 -> BB09edge, but the
BB07 -> BB09edge is not removed, becauseBB07is a handler block that
is only processed later, in step (3) of the phase. - Second pass calls
fgRemoveBlock(BB09, /* unreachable */ true). At the end of
that routinefgRemoveBlockasserts
(block->bbRefs == 0) && (block->bbPreds == nullptr). ButBB09still has the
live predecessor edge fromBB07, sobbRefs == 1/bbPreds != nullptrand
the assert fails.
Root cause
fgRemoveEmptyTryCatchOrTryFault assumes the filter's blocks form a contiguous
physical range [ebdFilter .. BBFilterLast()] containing only filter blocks.
Here an extra BBJ_THROW helper block (BB09), which logically belongs to the
handler side and is still referenced by the handler block BB07, is interleaved
inside that physical range. Iterating the filter removal by ->Next() pulls
BB09 into the filter pass and removes it as "unreachable" before its
handler-side predecessor (BB07) has been unlinked, tripping the
fgRemoveBlock sanity check.
The fix likely needs the phase to either (a) iterate filter/handler blocks by EH
membership rather than raw physical Next() order, or (b) unlink all
cross-region predecessor edges (or remove blocks in an order/passes) so that any
interleaved throw-helper block no longer has live predecessors when it is
removed.
Attached details.zip file that includes the repro.mc and jitdump.txt files for this example.
cc @dotnet/jit-contrib
Activity
dotnet-policy-service commentedon Jul 6, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
AndyAyersMS commentedon Jul 6, 2026
If the AI artifacts are right, the bug is that there is a throw helper reachable from two different funclets, so the issue is in the ACD key management rather than in the optimization itself.
AndyAyersMS commentedon Jul 6, 2026
Looks like it is an invalid tail merge that creates this, not throw helper mismanagement.
BoyBaykiller commentedon Jul 6, 2026
I'll have a look then. In fact I already have a suspicion.
Block tail merges across handler and filter (#130260)
Block tail merges across handler and filter (#130260)