Skip to content

JIT: Reordering of data and null check for stores #125124

@jakobbotsch

Description

@jakobbotsch
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public class Program
{
    static void Main()
    {
        Get().Field = Bar();
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static int Bar()
    {
        Console.WriteLine("Bar called");
        return 123;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static Program Get() => null;

    private LargeStruct _large;
    public int Field;

    [InlineArray(0x10000)]
    private struct LargeStruct
    {
        public byte B;
    }
}

This program does not print "Bar called" even though it should. The cause is that when we import STFLD we create IR that evaluates "obj -> nullcheck(obj) -> data -> store", when in reality the evaluation should be "obj -> data -> nullcheck(obj) -> store".

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions