Skip to content

JIT: Incorrect exception modelling for INDEX_ADDR #85645

@jakobbotsch

Description

@jakobbotsch

OperExceptions returns only ExceptionSetFlags::IndexOutOfRange for INDEX_ADDR nodes, but these can also throw NullReferenceException. It means that in tier-0 the following program throws IndexOutOfRangeException when it should actually throw NullReferenceException:

using System.Runtime.CompilerServices;

public class Program
{
    public static void Main()
    {
        Bar(null, new int[0]);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    public static void Bar(int[] a, int[] b)
    {
        Consume(a[0], b[0] + 3);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void Consume(int a, int b)
    {
    }
}

When optimizing we expand INDEX_ADDR nodes and then call args morphing realizes that it cannot reorder these arguments.

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions