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

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 2 13:24:03 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Joseph Huber (jhuber6)

<details>
<summary>Changes</summary>

Summary:
The `aligned_alloc` function is the C11 replacement for
`posix_memalign`. We should favor the C standard over the POSIX standard
so more C library implementations can run the tests.


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


2 Files Affected:

- (modified) libcxx/test/libcxx/language.support/support.dynamic/new_faligned_allocation.pass.cpp (+1-1) 
- (modified) libcxx/test/support/count_new.h (+1-1) 


``````````diff
diff --git a/libcxx/test/libcxx/language.support/support.dynamic/new_faligned_allocation.pass.cpp b/libcxx/test/libcxx/language.support/support.dynamic/new_faligned_allocation.pass.cpp
index 69c46f00fb65d..87f4783e12973 100644
--- a/libcxx/test/libcxx/language.support/support.dynamic/new_faligned_allocation.pass.cpp
+++ b/libcxx/test/libcxx/language.support/support.dynamic/new_faligned_allocation.pass.cpp
@@ -76,7 +76,7 @@ int main(int, char**) {
   test_allocations(64, 64);
   // Size being a multiple of alignment also needs to be supported.
   test_allocations(64, 32);
-  // When aligned allocation is implemented using posix_memalign,
+  // When aligned allocation is implemented using aligned_alloc,
   // that function requires a minimum alignment of sizeof(void*).
   // Check that we can also create overaligned allocations with
   // an alignment argument less than sizeof(void*).
diff --git a/libcxx/test/support/count_new.h b/libcxx/test/support/count_new.h
index 0a95e05b72421..dc9fe2bcc610e 100644
--- a/libcxx/test/support/count_new.h
+++ b/libcxx/test/support/count_new.h
@@ -461,7 +461,7 @@ inline void* alocate_aligned_impl(std::size_t size, std::align_val_t align) {
 #    ifdef USE_ALIGNED_ALLOC
   ret = _aligned_malloc(size, alignment);
 #    else
-  assert(posix_memalign(&ret, std::max(alignment, sizeof(void*)), size) != EINVAL);
+  ret = aligned_alloc(alignment, size);
 #    endif
   return ret;
 }

``````````

</details>


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


More information about the libcxx-commits mailing list