using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public static unsafe class Program
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ref byte GetNonNullPinnableReference(Span<byte> buffer)
{
return ref buffer.Length != 0 ? ref MemoryMarshal.GetReference(buffer) : ref Unsafe.AsRef<byte>((void*)1);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static int Consume(byte* p, int length) => p is null ? -1 : length;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int Pin(Span<byte> destination)
{
fixed (byte* p = &GetNonNullPinnableReference(destination))
{
int status = Consume(p, destination.Length);
if (status != 0)
{
throw new InvalidOperationException();
}
return status;
}
}
public static int Main()
{
int result = Pin(default);
Console.WriteLine($"Pin(default) = {result}");
return result == 0 ? 100 : 1;
}
}
src\coreclr\jit\emitarm64.cpp:3025
Assertion failed 'isValidGeneralDatasize(size)' in 'Program:Main():int' during 'Generate code' (IL size 65; hash 0xd9b8a0c8; FullOpts)
Reproduces only with crossgen2/ilc.
I hit this in a less-contrived example in #131538.
Reproduces only with crossgen2/ilc.
I hit this in a less-contrived example in #131538.