Skip to content

JIT: (bug) fgUpdateFlowGraph dereferences a null predecessor list for a handler entry after tail duplication #134006

Closed

Description

@EgorBo

fgUpdateFlowGraph assumes bbRefs == 1 implies a non-empty predecessor list after tail duplication and conditional folding. Handler entries can have one artificial EH reference and no real predecessors, causing a JIT-time null dereference.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

public class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    public static void Test(int b)
    {
        int L = b;
        try
        {
            throw new Exception("boom");
        }
        finally
        {
        T1:
            if (L == 1)
            {
                goto Done;
            }
            L = 1;
            goto T1;
        Done:
            Console.WriteLine("finally done");
        }
    }

    public static void Main()
    {
        Console.WriteLine("start");
        try { Test(0); } catch (Exception e) { Console.WriteLine(e.Message); }
        Console.WriteLine("done");
    }
}

Expected

start
finally done
boom
done

Actual

start
UB

The process dies while JIT-compiling Test. JitDump reaches the tail-duplication fold and then faults:

BB03 [0002]  2     0 BB04  ... ( cond ) H0 finally {
Considering uncond to cond BB04 -> BB03
Conditional folded at BB04
BB04 becomes a BBJ_ALWAYS to BB05
Fatal error.
0xC0000005

Notes

Compiler::fgUpdateFlowGraph() (fgopt.cpp) checks bDest->bbRefs == 1 and then dereferences bDest->bbPreds; for handler/filter entries the remaining ref can be artificial and bbPreds can be null.
Also reproduces on released .NET 10.0.12 x64, surfacing as Internal CLR error. (0x80131506).
Guard on the predecessor list or account for artificial handler/filter entry refs before reading bbPreds.

Activity

  1. added this to the 12.0.0 milestone on Sep 15, 2026
  2. added
    area-CodeGen-coreclr
    on Sep 15, 2026
  3. dotnet-policy-service commented on Sep 15, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  4. changed the title [-]JIT (bug): fgUpdateFlowGraph dereferences a null predecessor list for a handler entry after tail duplication[/-] [+]JIT: (bug) fgUpdateFlowGraph dereferences a null predecessor list for a handler entry after tail duplication[/+] on Sep 16, 2026
  5. added a commit that references this issue on Sep 16, 2026
    9bd1e08
  6. EgorBo commented on Sep 18, 2026

    @EgorBo
    MemberAuthor

    Affected SDK versions:

    • 10.0.401
    • 11.0.100-rc.2.26467.112
  7. added a commit that references this issue on Sep 21, 2026
    07930f4
  8. locked and limited conversation to collaborators on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions