[libcxx-commits] [libcxx] afc5cca - [libc++] Get rid of _LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 21 06:02:15 PDT 2023


Author: Louis Dionne
Date: 2023-06-21T09:01:24-04:00
New Revision: afc5cca0d4016f09f0d7e2683d5a920c7ecf9397

URL: https://github.com/llvm/llvm-project/commit/afc5cca0d4016f09f0d7e2683d5a920c7ecf9397
DIFF: https://github.com/llvm/llvm-project/commit/afc5cca0d4016f09f0d7e2683d5a920c7ecf9397.diff

LOG: [libc++] Get rid of _LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS

Whether we include operator new and delete into libc++ has always
been a build time setting, and piggy-backing on a macro like
_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS is inconsistent with how
we handle similar cases for e.g. LIBCXX_ENABLE_RANDOM_DEVICE. Instead,
simply avoid including new.cpp in the sources of the library when we
do not wish to include these operators in the build.

This also makes us much closer to being able to share the definitions
between libc++ and libc++abi, since we could technically build those
definitions into a standalone static library and decide whether we link
it into libc++abi.dylib or libc++.dylib.

Differential Revision: https://reviews.llvm.org/D153272

Added: 
    

Modified: 
    libcxx/CMakeLists.txt
    libcxx/src/CMakeLists.txt
    libcxx/src/new.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 3c2fc7f224e95..808b35da66583 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -555,10 +555,6 @@ function(cxx_add_basic_build_flags target)
   # errors.
   target_compile_definitions(${target} PRIVATE -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
 
-  if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
-    target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
-  endif()
-
   if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
     if (LIBCXX_HAS_PTHREAD_LIB)
       target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB)

diff  --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 5280436108e7f..9562d99d5223e 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -34,7 +34,6 @@ set(LIBCXX_SOURCES
   memory_resource.cpp
   mutex.cpp
   mutex_destructor.cpp
-  new.cpp
   new_handler.cpp
   new_helpers.cpp
   optional.cpp
@@ -133,6 +132,12 @@ if (LIBCXX_ENABLE_FILESYSTEM)
   endif()
 endif()
 
+if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
+  list(APPEND LIBCXX_SOURCES
+    new.cpp
+    )
+endif()
+
 # Add all the headers to the project for IDEs.
 if (LIBCXX_CONFIGURE_IDE)
   file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*)

diff  --git a/libcxx/src/new.cpp b/libcxx/src/new.cpp
index a9920ba09849b..c435c5ffc809c 100644
--- a/libcxx/src/new.cpp
+++ b/libcxx/src/new.cpp
@@ -10,9 +10,7 @@
 #include <cstdlib>
 #include <new>
 
-#if !defined(__GLIBCXX__) &&                                                   \
-    !defined(_LIBCPP_ABI_VCRUNTIME) &&      \
-    !defined(_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
+#if !defined(__GLIBCXX__) && !defined(_LIBCPP_ABI_VCRUNTIME)
 
 // The code below is copied as-is into libc++abi's libcxxabi/src/stdlib_new_delete.cpp
 // file. The version in this file is the canonical one.
@@ -257,4 +255,4 @@ operator delete[] (void* ptr, size_t, std::align_val_t alignment) noexcept
 #endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
 // ------------------ END COPY ------------------
 
-#endif // !__GLIBCXX__ && !_LIBCPP_ABI_VCRUNTIME && !_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS
+#endif // !__GLIBCXX__ && !_LIBCPP_ABI_VCRUNTIME


        


More information about the libcxx-commits mailing list