runtime: SEHException on misaligned access

Run the following code on an arm64 machine (e.g. Apple-M1):

using System.Runtime.CompilerServices;

long[] a = new long[100];
ref long misalignedLong = ref Unsafe.As<byte, long>(
    ref Unsafe.Add(ref Unsafe.As<long, byte>(ref a[0]), 1));
Test(ref misalignedLong);

[MethodImpl(MethodImplOptions.NoInlining)]
long Test(ref long misalignedLong) => Volatile.Read(ref misalignedLong);

Expected:

No exception or DataMisalignedException is thrown

Actual:

SEHException is thrown

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments