Skip to content

The Jit doesn't handle certain uses of field addresses correctly #77636

Closed

Description

@SingleAccretion

Reproduction:

Console.WriteLine(Problem(null));

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

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

Compile and run.

Expected result: NullReferenceException is thrown.

Actual result: AccessViolationException is thrown.

Cause: the morphing context used for checking whether an explicit null check is required has fairly non-obvious propagation rules. In particular, it does not get "reset" for arbitrary users, but passed as-is.

Activity

  1. added
    area-CodeGen-coreclr
    on Oct 29, 2022
  2. added this to the 8.0.0 milestone on Oct 29, 2022
  3. ghost added
    in-pr
    on Nov 11, 2022
  4. ghost removed
    in-pr
    on Nov 29, 2022
  5. ghost locked as resolved and limited conversation to collaborators on Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-CodeGen-coreclrbug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions