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().
This commit is contained in:
R-Goc 2025-02-17 16:20:15 +01:00 committed by Andrew Kaster
commit 5226a566e9
Notes: github-actions[bot] 2025-04-02 16:23:10 +00:00

View file

@ -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<u8*>(static_cast<FlatPtr>(bit_cast<u32>(member)));
return bit_cast<V*>(bit_cast<u8*>(&node) - distance);
#else
return bit_cast<V*>(bit_cast<u8*>(&node) - bit_cast<u8*>(member));
#endif
}
};