Skip to content

JIT: (bug) crash (null deref in impFixPredLists) for finally { while (true) {} } when profile weights are used #135819

Closed

Description

@EgorBo

impFixPredLists dereferences Next() of every predecessor of a finally handler's first block without checking for BBJ_CALLFINALLY. For a finally with an infinite loop laid out as the last block, the only predecessor is its own back edge (Next() == nullptr), so the JIT crashes (AV) when compiling the method with profile weights (default tiering + dynamic PGO), even if the finally is never reached.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

public static class Program
{
    public static int Main()
    {
        Console.WriteLine(Test(false));
        return 100;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    public static int Test(bool b)
    {
        if (!b)
            return 1;

        try
        {
            throw new Exception();
        }
        finally
        {
            while (true)
            {
            }
        }
    }
}

Expected

Prints 1.

Actual

Fatal error.
0xC0000005
   at Program.Main()

Default env (Checked JIT, main c6d6546). No crash with DOTNET_TieredCompilation=0 or DOTNET_TieredPGO=0; crashes with DOTNET_TC_QuickJitForLoops=0 and DOTNET_ReadyToRun=0. The method is first rejected for Tier0/OSR ("OSR can't handle loop in handler") and recompiled optimized with a synthesized profile.

Regression?

Default env, Release JIT, same repro per TFM:

  • .NET 8.0.32 / 9.0.21: prints 1
  • .NET 10.0.13: crash (Internal CLR error. (0x80131506))
  • .NET 11.0.0-rc.1.26425.128: crash (0xC0000005)

Appears to be a regression from the .NET 10 cycle.

Notes

  • Compiler::impFixPredLists (importer.cpp): the first loop skips preds that aren't BBJ_CALLFINALLY, but the profile-weights fix-up loop doesn't:
    BasicBlock* const callFinallyRet = callFinally->Next(); callFinallyRet->setBBProfileWeight(...) (null deref).
  • Here the try ends in throw (no BBJ_CALLFINALLY) and the finally's first block has only itself as pred; it's the last block.
  • Fix: skip non-BBJ_CALLFINALLY preds in that loop. See also the related profile-inconsistency issue for finally entry back edges.

Activity

  1. added this to the 12.0.0 milestone on Oct 14, 2026
  2. added
    area-CodeGen-coreclr
    on Oct 14, 2026
  3. dotnet-policy-service commented on Oct 14, 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. self-assigned this
    on Oct 15, 2026
  5. added a commit that references this issue on Oct 20, 2026
    9e9a54c
  6. locked and limited conversation to collaborators on Nov 20, 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