From 5226a566e9d935ffff081e29a9d184f2acae27b8 Mon Sep 17 00:00:00 2001 From: R-Goc Date: Mon, 17 Feb 2025 16:20:15 +0100 Subject: [PATCH] AK: Modify IntrusiveRedBlackTree for Windows IntrusiveRedBlackTree relies on a member pointer for accessing the value of a node. On windows member pointers can be of variable length, depending on the inheritance structure of the class. This commit casts the 4 byte member pointer, or rather offset to a full pointer type, so that the bit_cast to u8* works, as previously the source was smaller than the destination, which fails inside __builtin_bit_cast(). --- AK/IntrusiveRedBlackTree.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/AK/IntrusiveRedBlackTree.h b/AK/IntrusiveRedBlackTree.h index fb2db6b92e1..a5585de662c 100644 --- a/AK/IntrusiveRedBlackTree.h +++ b/AK/IntrusiveRedBlackTree.h @@ -174,7 +174,14 @@ private: static V* node_to_value(TreeNode& node) { +#ifdef AK_OS_WINDOWS + // NOTE: https://learn.microsoft.com/en-us/cpp/build/reference/vmb-vmg-representation-method?view=msvc-170 + static_assert(sizeof(member) == 4); + auto distance = bit_cast(static_cast(bit_cast(member))); + return bit_cast(bit_cast(&node) - distance); +#else return bit_cast(bit_cast(&node) - bit_cast(member)); +#endif } };