From 73799b46072c2241ae32c87f478a7e2a30c0e1a3 Mon Sep 17 00:00:00 2001 From: "Mikhail R. Gadelha" Date: Wed, 17 Jul 2024 17:20:15 +0200 Subject: [PATCH] [libc] Added missing operator delete generated by gcc/clang (#67457) This patch adds two operators delete that are being generated by clang 15 on rv32 (operator delete(void *mem, std::align_val_t)) and by gcc 13 on intel 64 (operator delete(void *mem, unsigned long)). --- libc/test/UnitTest/HermeticTestUtils.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp index 85e5cf02ff613a..47f813b0b7a4e1 100644 --- a/libc/test/UnitTest/HermeticTestUtils.cpp +++ b/libc/test/UnitTest/HermeticTestUtils.cpp @@ -124,7 +124,7 @@ unsigned long __getauxval(unsigned long id) { } // extern "C" -void *operator new(unsigned long size, void *ptr) { return ptr; } +void *operator new(size_t size, void *ptr) { return ptr; } void *operator new(size_t size) { return malloc(size); } @@ -137,3 +137,16 @@ void operator delete(void *) { } void operator delete(void *ptr, size_t size) { __builtin_trap(); } + +// Defining members in the std namespace is not preferred. But, we do it here +// so that we can use it to define the operator new which takes std::align_val_t +// argument. +namespace std { +enum class align_val_t : size_t {}; +} // namespace std + +void operator delete(void *mem, std::align_val_t) noexcept { __builtin_trap(); } + +void operator delete(void *mem, unsigned int, std::align_val_t) noexcept { + __builtin_trap(); +}