From 1af57fa9936d1f5d4a9329e62576cdf426b0f8be Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 1 May 2026 16:24:01 +0000 Subject: [PATCH 1/2] Initial plan From c116fb36375eada8d758e45b2a2ff70fd3fb9d9b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 1 May 2026 16:49:48 +0000 Subject: [PATCH 2/2] Fix SIGBUS crash on ARMv7 by using Unsafe.ReadUnaligned in Hashing Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/8ce2f2de-22f7-4ba6-ba20-cf4f26de986f Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> --- .../Collections/Frozen/String/Hashing.cs | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/Hashing.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/Hashing.cs index 212e2cca3bf624..5966f4e60423d4 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/Hashing.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/Hashing.cs @@ -4,6 +4,7 @@ using System.Buffers; using System.Diagnostics; using System.Numerics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; @@ -47,27 +48,26 @@ public static unsafe int GetHashCodeOrdinal(ReadOnlySpan s) return (int)(Hash1Start + (hash2 * Factor)); case 4: - hash1 = (BitOperations.RotateLeft(Hash1Start, 5) + Hash1Start) ^ ((uint*)src)[0]; - hash2 = (BitOperations.RotateLeft(Hash1Start, 5) + Hash1Start) ^ ((uint*)src)[1]; + hash1 = (BitOperations.RotateLeft(Hash1Start, 5) + Hash1Start) ^ Unsafe.ReadUnaligned(src); + hash2 = (BitOperations.RotateLeft(Hash1Start, 5) + Hash1Start) ^ Unsafe.ReadUnaligned(src + 2); return (int)(hash1 + (hash2 * Factor)); default: hash1 = Hash1Start; hash2 = hash1; - uint* ptrUInt32 = (uint*)src; + char* ptr = src; while (length >= 4) { - hash1 = (BitOperations.RotateLeft(hash1, 5) + hash1) ^ ptrUInt32[0]; - hash2 = (BitOperations.RotateLeft(hash2, 5) + hash2) ^ ptrUInt32[1]; - ptrUInt32 += 2; + hash1 = (BitOperations.RotateLeft(hash1, 5) + hash1) ^ Unsafe.ReadUnaligned(ptr); + hash2 = (BitOperations.RotateLeft(hash2, 5) + hash2) ^ Unsafe.ReadUnaligned(ptr + 2); + ptr += 4; length -= 4; } - char* ptrChar = (char*)ptrUInt32; while (length-- > 0) { - hash2 = (BitOperations.RotateLeft(hash2, 5) + hash2) ^ *ptrChar++; + hash2 = (BitOperations.RotateLeft(hash2, 5) + hash2) ^ *ptr++; } return (int)(hash1 + (hash2 * Factor)); @@ -111,28 +111,27 @@ public static unsafe int GetHashCodeOrdinalIgnoreCaseAscii(ReadOnlySpan s) return (int)(Hash1Start + (hash2 * Factor)); case 4: - hash1 = (BitOperations.RotateLeft(Hash1Start, 5) + Hash1Start) ^ (((uint*)src)[0] | LowercaseUInt32); - hash2 = (BitOperations.RotateLeft(Hash1Start, 5) + Hash1Start) ^ (((uint*)src)[1] | LowercaseUInt32); + hash1 = (BitOperations.RotateLeft(Hash1Start, 5) + Hash1Start) ^ (Unsafe.ReadUnaligned(src) | LowercaseUInt32); + hash2 = (BitOperations.RotateLeft(Hash1Start, 5) + Hash1Start) ^ (Unsafe.ReadUnaligned(src + 2) | LowercaseUInt32); return (int)(hash1 + (hash2 * Factor)); default: hash1 = Hash1Start; hash2 = hash1; - uint* ptrUInt32 = (uint*)src; + char* ptr = src; while (length >= 4) { - hash1 = (BitOperations.RotateLeft(hash1, 5) + hash1) ^ (ptrUInt32[0] | LowercaseUInt32); - hash2 = (BitOperations.RotateLeft(hash2, 5) + hash2) ^ (ptrUInt32[1] | LowercaseUInt32); - ptrUInt32 += 2; + hash1 = (BitOperations.RotateLeft(hash1, 5) + hash1) ^ (Unsafe.ReadUnaligned(ptr) | LowercaseUInt32); + hash2 = (BitOperations.RotateLeft(hash2, 5) + hash2) ^ (Unsafe.ReadUnaligned(ptr + 2) | LowercaseUInt32); + ptr += 4; length -= 4; } - char* ptrChar = (char*)ptrUInt32; while (length-- > 0) { - hash2 = (BitOperations.RotateLeft(hash2, 5) + hash2) ^ (*ptrChar | LowercaseUInt32); - ptrChar++; + hash2 = (BitOperations.RotateLeft(hash2, 5) + hash2) ^ (*ptr | LowercaseUInt32); + ptr++; } return (int)(hash1 + (hash2 * Factor));