[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
Tue Nov 22 01:41:46 PST 2022


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

rebase to prod CI


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.477114.patch
Type: text/x-patch
Size: 1304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221122/18c1e249/attachment-0001.bin>


More information about the libcxx-commits mailing list