[libcxx-commits] [libcxx] [libcxx] Use `aligned_alloc` for testing instead of `posix_memalign` (PR #101748)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 14 09:03:28 PDT 2024


================
@@ -460,6 +460,9 @@ inline void* alocate_aligned_impl(std::size_t size, std::align_val_t align) {
   void* ret                   = nullptr;
 #    ifdef USE_ALIGNED_ALLOC
   ret = _aligned_malloc(size, alignment);
+#    elif TEST_STD_VER >= 17
+  size_t rounded_size = (size + alignment - 1) & ~(alignment - 1);
+  ret                 = aligned_alloc(alignment, size > rounded_size ? size : rounded_size);
----------------
ldionne wrote:

We want this check:

```c++
#  if defined(__APPLE__)
#    if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&                                                     \
         __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)
#      define TEST_HAS_NO_C11_ALIGNED_ALLOC
#    endif
#  elif defined(__ANDROID__) && __ANDROID_API__ < 28
#    define TEST_HAS_NO_C11_ALIGNED_ALLOC
#  endif

// and then
#elif TEST_STD_VER >= 17 && !defined(TEST_HAS_NO_C11_ALIGNED_ALLOC)
size_t rounded_size = (size + alignment - 1) & ~(alignment - 1);
ret                 = aligned_alloc(alignment, size > rounded_size ? size : rounded_size);
#else
// etc...
```

https://github.com/llvm/llvm-project/pull/101748


More information about the libcxx-commits mailing list