Roslyn should not optimize unused byref dereferences due to possible side effect of NRE. E.g. https://github.com/dotnet/runtime/pull/98547/files PR used such dereferences intentionally to throw NRE before we enter unmanaged code.
Version Used:
Reproduces in .NET 8.0 and in Main on Sharplab.
Steps to Reproduce:
static void Test(ref byte b)
{
_ = b; // dereference, hence, NRE as a side effect
}
Expected Behavior:
.method assembly hidebysig static Test (uint8& b)
{
.maxstack 8
ldind.u1
pop
ret
}
Actual Behavior:
.method assembly hidebysig static Test (uint8& b)
{
.maxstack 8
ret
}
Roslyn should not optimize unused byref dereferences due to possible side effect of NRE. E.g. https://github.com/dotnet/runtime/pull/98547/files PR used such dereferences intentionally to throw NRE before we enter unmanaged code.
Version Used:
Reproduces in .NET 8.0 and in Main on Sharplab.
Steps to Reproduce:
Expected Behavior:
.method assembly hidebysig static Test (uint8& b) { .maxstack 8 ldind.u1 pop ret }Actual Behavior:
.method assembly hidebysig static Test (uint8& b) { .maxstack 8 ret }