Godot Engine – Multi-platform 2D and 3D game engine
Do not inline `new` operators.
Pāvels Nadtočajevs75e0f205f2e7
diff --git a/core/os/memory.cpp b/core/os/memory.cppindex b910424b182..5418e9b36fc 100644--- a/core/os/memory.cpp+++ b/core/os/memory.cpp@@ -44,6 +44,14 @@ static SafeNumeric<uint64_t> _current_mem_usage;static SafeNumeric<uint64_t> _max_mem_usage;#endif+void *operator new(size_t p_size, DefaultAllocator p_allocator) {+ return Memory::alloc_static(p_size);+}++void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)) {+ return p_allocfunc(p_size);+}+void *Memory::alloc_aligned_static(size_t p_bytes, size_t p_alignment) {DEV_ASSERT(Math::is_power_of_2(p_alignment));diff --git a/core/os/memory.h b/core/os/memory.hindex 01762c9ad52..09cfeee788b 100644--- a/core/os/memory.h+++ b/core/os/memory.h@@ -104,15 +104,13 @@ public:_FORCE_INLINE_ static void free(void *p_ptr) { Memory::free_static(p_ptr, false); }};-// Overload of new operator to use the Memory::alloc_static function.-// The DefaultAllocator parameter is just a tag to select this overload.-inline void *operator new(size_t p_size, DefaultAllocator p_allocator) {- return Memory::alloc_static(p_size);-}-// Overload of new operator to use a custom allocation function.-inline void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)) {- return p_allocfunc(p_size);-}+// Overload of `new` operator to use the `Memory::alloc_static()` function.+// The `DefaultAllocator` parameter is just a tag to select this overload.+// NOTE: do not inline `new` operators due to GCC+LTO compiler bug (see GH-119752).+void *operator new(size_t p_size, DefaultAllocator p_allocator);++// Overload of `new` operator to use a custom allocation function.+void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size));#if defined(_MSC_VER) && !defined(__clang__)// When compiling with VC++ 2017, the above declarations of placement new generate many irrelevant warnings (C4291).