diff --git a/include/godot_cpp/core/memory.hpp b/include/godot_cpp/core/memory.hpp index 917ccdede..2671572dd 100644 --- a/include/godot_cpp/core/memory.hpp +++ b/include/godot_cpp/core/memory.hpp @@ -64,7 +64,16 @@ class Memory { Memory(); public: - // Alignment: ↓ max_align_t ↓ uint64_t ↓ max_align_t +#if defined(__MINGW32__) && !defined(__MINGW64__) + // Note: Using hardcoded value, since the value can end up different in different compile units on 32-bit windows + // due to a compiler bug (see GH-113145) + static constexpr size_t MAX_ALIGN = 16; + static_assert(MAX_ALIGN % alignof(max_align_t) == 0); +#else + static constexpr size_t MAX_ALIGN = alignof(max_align_t); +#endif + + // Alignment: ↓ max_align_t ↓ uint64_t ↓ MAX_ALIGN // ┌─────────────────┬──┬────────────────┬──┬───────────... // │ uint64_t │░░│ uint64_t │░░│ T[] // │ alloc size │░░│ element count │░░│ data @@ -74,7 +83,7 @@ class Memory { static constexpr size_t SIZE_OFFSET = 0; static constexpr size_t ELEMENT_OFFSET = ((SIZE_OFFSET + sizeof(uint64_t)) % alignof(uint64_t) == 0) ? (SIZE_OFFSET + sizeof(uint64_t)) : ((SIZE_OFFSET + sizeof(uint64_t)) + alignof(uint64_t) - ((SIZE_OFFSET + sizeof(uint64_t)) % alignof(uint64_t))); - static constexpr size_t DATA_OFFSET = ((ELEMENT_OFFSET + sizeof(uint64_t)) % alignof(max_align_t) == 0) ? (ELEMENT_OFFSET + sizeof(uint64_t)) : ((ELEMENT_OFFSET + sizeof(uint64_t)) + alignof(max_align_t) - ((ELEMENT_OFFSET + sizeof(uint64_t)) % alignof(max_align_t))); + static constexpr size_t DATA_OFFSET = ((ELEMENT_OFFSET + sizeof(uint64_t)) % MAX_ALIGN == 0) ? (ELEMENT_OFFSET + sizeof(uint64_t)) : ((ELEMENT_OFFSET + sizeof(uint64_t)) + MAX_ALIGN - ((ELEMENT_OFFSET + sizeof(uint64_t)) % MAX_ALIGN)); static void *alloc_static(size_t p_bytes, bool p_pad_align = false); static void *realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align = false); diff --git a/include/godot_cpp/templates/cowdata.hpp b/include/godot_cpp/templates/cowdata.hpp index 39ba5c8e7..52b84023b 100644 --- a/include/godot_cpp/templates/cowdata.hpp +++ b/include/godot_cpp/templates/cowdata.hpp @@ -97,7 +97,7 @@ class CowData { return ++x; } - // Alignment: ↓ max_align_t ↓ USize ↓ max_align_t + // Alignment: ↓ max_align_t ↓ USize ↓ MAX_ALIGN // ┌────────────────────┬──┬─────────────┬──┬───────────... // │ SafeNumeric │░░│ USize │░░│ T[] // │ ref. count │░░│ data size │░░│ data @@ -106,7 +106,7 @@ class CowData { static constexpr size_t REF_COUNT_OFFSET = 0; static constexpr size_t SIZE_OFFSET = ((REF_COUNT_OFFSET + sizeof(SafeNumeric)) % alignof(USize) == 0) ? (REF_COUNT_OFFSET + sizeof(SafeNumeric)) : ((REF_COUNT_OFFSET + sizeof(SafeNumeric)) + alignof(USize) - ((REF_COUNT_OFFSET + sizeof(SafeNumeric)) % alignof(USize))); - static constexpr size_t DATA_OFFSET = ((SIZE_OFFSET + sizeof(USize)) % alignof(max_align_t) == 0) ? (SIZE_OFFSET + sizeof(USize)) : ((SIZE_OFFSET + sizeof(USize)) + alignof(max_align_t) - ((SIZE_OFFSET + sizeof(USize)) % alignof(max_align_t))); + static constexpr size_t DATA_OFFSET = ((SIZE_OFFSET + sizeof(USize)) % Memory::MAX_ALIGN == 0) ? (SIZE_OFFSET + sizeof(USize)) : ((SIZE_OFFSET + sizeof(USize)) + Memory::MAX_ALIGN - ((SIZE_OFFSET + sizeof(USize)) % Memory::MAX_ALIGN)); mutable T *_ptr = nullptr;