Closed stephentoub closed 1 month ago
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch See info in area-owners.md if you want to be subscribed.
This is due to a difference in IL generated by Roslyn.
static void Set(object[] array)
{
ref var o = ref array[0];
}
Uses ldelem
instead of ldelema
:
IL to import:
IL_0000 03 ldarg.1
IL_0001 16 ldc.i4.0
IL_0002 9a ldelem.ref
IL_0003 26 pop
IL_0004 2a ret
And Roslyn uses ldelema
for the same C# snippet compiled in Debug
I hadn't noticed that IL difference. I assume that means we'd consider this a Roslyn bug and it should always be using ldelema?
Depending on what the C# specification says, yes. It's not a runtime bug in any case.
This code throws an ArrayTypeMismatchException:
SharpLab
But this code does not:
SharpLab
By eliding the CORINFO_HELP_LDELEMA_REF call that does the variance checking, does that mean the JIT's optimizations are changing program behavior in a way we try not to?