[libc-commits] [libc] [libc] Added missing operator delete generated by gcc/clang (PR #67457)

Mikhail R. Gadelha via libc-commits libc-commits at lists.llvm.org
Fri Jul 5 05:36:03 PDT 2024


https://github.com/mikhailramalho updated https://github.com/llvm/llvm-project/pull/67457

>From 6dd3fd76c71766cc11db08b16fa473cd66be1651 Mon Sep 17 00:00:00 2001
From: "Mikhail R. Gadelha" <mikhail at igalia.com>
Date: Tue, 26 Sep 2023 13:57:20 -0300
Subject: [PATCH] [libc] Added missing operator deletes generated by gcc/clang

This patch adds two operator delete functions 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 ca854ad94393e..050020cd8308e 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -123,7 +123,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); }
 
@@ -136,3 +136,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();
+}



More information about the libc-commits mailing list