[libcxx-commits] [PATCH] D138196: [libc++] Use aligned_alloc instead of posix_memalign for C++17

Alexander Richardson via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 21 02:58:06 PST 2022


arichardson updated this revision to Diff 476838.
arichardson added a comment.

Try to disable aligned_alloc for macOS 10.9


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138196/new/

https://reviews.llvm.org/D138196

Files:
  libcxx/include/__config
  libcxx/include/new


Index: libcxx/include/new
===================================================================
--- libcxx/include/new
+++ libcxx/include/new
@@ -341,6 +341,8 @@
 void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) {
 #if defined(_LIBCPP_MSVCRT_LIKE)
   return ::_aligned_malloc(__size, __alignment);
+#elif _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_C11_ALIGNED_ALLOC)
+  return ::aligned_alloc(__alignment, __size);
 #else
   void* __result = nullptr;
   (void)::posix_memalign(&__result, __alignment, __size);
Index: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -720,6 +720,15 @@
 #    define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
 #  endif
 
+// It is not yet possible to use aligned_alloc() on all Apple platforms as 10.9
+// does not ship with an implementation of aligned_alloc().
+#  if defined(__APPLE__)
+#    if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&                                                     \
+         __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101000)
+#      define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
+#    endif
+#  endif
+
 #  if defined(__APPLE__) || defined(__FreeBSD__)
 #    define _LIBCPP_HAS_DEFAULTRUNELOCALE
 #  endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138196.476838.patch
Type: text/x-patch
Size: 1304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221121/d444c666/attachment-0001.bin>


More information about the libcxx-commits mailing list