Fix bmalloc's PackedAlignedPtr for X86_64 canonical addresses See https://bugs.webkit.org/show_bug.cgi?id=214142 Suitable for upstream. diff --git a/Source/bmalloc/bmalloc/Packed.h b/Source/bmalloc/bmalloc/Packed.h index a51809445086..a0d1e06a9508 100644 --- webkit/Source/bmalloc/bmalloc/Packed.h.~1~ 2024-11-24 18:41:16.000000000 +0000 +++ webkit/Source/bmalloc/bmalloc/Packed.h 2024-11-24 19:03:37.356568453 +0000 @@ -37,6 +37,8 @@ namespace bmalloc { +template constexpr unsigned countOfBits = sizeof(T) * CHAR_BIT; + template class Packed { public: @@ -145,6 +147,12 @@ #endif if (isAlignmentShiftProfitable) value <<= alignmentShiftSize; + +#if BCPU(X86_64) && !(BOS(DARWIN) || BOS(LINUX) || BOS(WINDOWS)) + constexpr unsigned shiftBits = countOfBits - BOS_EFFECTIVE_ADDRESS_WIDTH; + value = (std::bit_cast(value) << shiftBits) >> shiftBits; +#endif + return std::bit_cast(value); } @@ -158,6 +166,7 @@ #else memcpy(m_storage.data(), std::bit_cast(&value) + (sizeof(void*) - storageSize), storageSize); #endif + BASSERT(get() == passedValue); } void clear()