Skip to content

The Jit does not add explicit null checks for zero-offset field addresses #77640

@SingleAccretion

Description

@SingleAccretion

Reproduction:

Console.WriteLine((nint)Problem(null));

[MethodImpl(MethodImplOptions.NoInlining)]
static int* Problem(StructWithIndex* s)
{
    return &s->Index;
}

struct StructWithIndex
{
    public int Index;
    public int Value;
}

Compile and run.

Expected result: a NullReferenceException is thrown.

Actual result: 0 is printed.

Cause: odd code in fgMorphField that special-cases fields with zero offsets.

Metadata

Metadata

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbugin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions