[libcxx-commits] [PATCH] D93473: [libc++/abi] Re-remove unnecessary null pointer checks from operator delete

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 17 10:32:50 PST 2020


ldionne created this revision.
ldionne added a reviewer: MaskRay.
Herald added a subscriber: jkorous.
ldionne requested review of this revision.
Herald added projects: libc++, libc++abi.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Herald added a reviewer: libc++abi.

In 7cd67904f776, we removed the unnecessary nullptr checks from the libc++abi
definition of operator delete, but we forgot to update the definition in
libc++ (damn code duplication!). Then, in d4a1e03c5fb5 <https://reviews.llvm.org/rGd4a1e03c5fb588a8e3f41110de437b38d4e57bbf>, I synced the
definitions across libc++ and libc++abi, but I did it the wrong way around.
I re-added the if() checks to libc++abi instead of removing them from libc++.

In ef74f0fdc339 <https://reviews.llvm.org/rGef74f0fdc33909d0e29a8206debd73d7673791c6>, we re-removed the if() check from operator delete, but
only in libc++abi. This patch corrects this mess and removes it
consistently in libc++ and libc++abi.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93473

Files:
  libcxx/src/new.cpp
  libcxxabi/src/stdlib_new_delete.cpp


Index: libcxxabi/src/stdlib_new_delete.cpp
===================================================================
--- libcxxabi/src/stdlib_new_delete.cpp
+++ libcxxabi/src/stdlib_new_delete.cpp
@@ -214,9 +214,7 @@
 void
 operator delete(void* ptr, std::align_val_t) _NOEXCEPT
 {
-    if (ptr) {
-        std::__libcpp_aligned_free(ptr);
-    }
+    std::__libcpp_aligned_free(ptr);
 }
 
 _LIBCXXABI_WEAK
Index: libcxx/src/new.cpp
===================================================================
--- libcxx/src/new.cpp
+++ libcxx/src/new.cpp
@@ -130,8 +130,7 @@
 void
 operator delete(void* ptr) _NOEXCEPT
 {
-    if (ptr)
-        ::free(ptr);
+    ::free(ptr);
 }
 
 _LIBCPP_WEAK
@@ -252,9 +251,7 @@
 void
 operator delete(void* ptr, std::align_val_t) _NOEXCEPT
 {
-    if (ptr) {
-        std::__libcpp_aligned_free(ptr);
-    }
+    std::__libcpp_aligned_free(ptr);
 }
 
 _LIBCPP_WEAK


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93473.312555.patch
Type: text/x-patch
Size: 888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201217/2e116e8d/attachment.bin>


More information about the libcxx-commits mailing list