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.