Skip to content

JIT: (bug) optJumpThreadCore omits target PHI args for threaded edges, causing RangeCheck to unsoundly eliminate bounds checks #135810

Description

@EgorBo

Jump threading in optJumpThreadCore redirects predecessor edges to a target block without adding corresponding GT_PHI_ARG entries to PHIs in the target block, causing RangeCheck to unsoundly eliminate array bounds checks.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static int Test(bool cond0, bool cond1, int y)
    {
        int[] arr = new int[1];
        if (cond0)
        {
            y = 0;
            goto Target;
        }

        int v = 0;
        if (!cond1)
        {
            v = y;
        }

        if (v == 0)
        {
            goto Target;
        }

        return v;

    Target:
        return arr[y];
    }

    static void Main()
    {
        try
        {
            int res = Test(false, true, 100);
            Console.WriteLine($"No exception! Returned: {res}");
        }
        catch (IndexOutOfRangeException)
        {
            Console.WriteLine("IndexOutOfRangeException");
        }
    }
}

Expected

IndexOutOfRangeException

Actual

No exception! Returned: 0

Notes

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 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