Skip to content

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

Closed

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".

Activity

  1. added
    untriaged
    on Mar 3, 2026
  2. added
    area-CodeGen-coreclr
    on Mar 3, 2026
  3. added this to the 11.0.0 milestone on Mar 3, 2026
  4. MihuBot commented on Mar 3, 2026

    @MihuBot

    I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):

  5. removed
    untriaged
    on Mar 9, 2026
  6. locked and limited conversation to collaborators on Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions