[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
Tue Sep 26 10:04:13 PDT 2023


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

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)).

>From 2d0e2f737bc78ad88320830da0885fc3110a3ce1 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 | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index 73d54b9eeb5ecc9..d4628091f30fac2 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -109,3 +109,22 @@ void operator delete(void *) {
   // we just trap here to catch any such accidental usages.
   __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 {
+  // The libc runtime should not use the global delete operator. Hence,
+  // we just trap here to catch any such accidental usages.
+  __builtin_trap();
+}
+
+void operator delete(void *mem, unsigned long) noexcept {
+  // The libc runtime should not use the global delete operator. Hence,
+  // we just trap here to catch any such accidental usages.
+  __builtin_trap();
+}



More information about the libc-commits mailing list