Skip to content

The Jit reorders null checks on field addresses with calls that have return buffers #77650

@SingleAccretion

Description

@SingleAccretion

Reproduction:

Problem();

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Problem()
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    static Guid GetStruct(ClassWithFields cls)
    {
        throw new Exception("GetStruct");
    }

    ClassWithFields cls = null;
    cls.GuidFld = GetStruct(cls);
}

class ClassWithFields
{
    public Guid GuidFld;
}

Compile and run.

Expected result: Exception("GetStruct") is thrown.

Actual result: NullReferenceException is thrown.

Cause: the FIELD = CALL => CALL(ADDR(FIELD)) transformation effectively moves the null check from the point of the store to before the call happens.

Metadata

Metadata

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions