Skip to content

Commit 03f3fe2

Browse files
committed
[libcxx] Use aligned_alloc for testing instead of posix_memalign
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.
1 parent 6de04e6 commit 03f3fe2

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

libcxx/test/libcxx/language.support/support.dynamic/new_faligned_allocation.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int main(int, char**) {
7676
test_allocations(64, 64);
7777
// Size being a multiple of alignment also needs to be supported.
7878
test_allocations(64, 32);
79-
// When aligned allocation is implemented using posix_memalign,
79+
// When aligned allocation is implemented using aligned_alloc,
8080
// that function requires a minimum alignment of sizeof(void*).
8181
// Check that we can also create overaligned allocations with
8282
// an alignment argument less than sizeof(void*).

libcxx/test/support/count_new.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ inline void* allocate_aligned_impl(std::size_t size, std::align_val_t align) {
460460
void* ret = nullptr;
461461
# ifdef USE_ALIGNED_ALLOC
462462
ret = _aligned_malloc(size, alignment);
463+
# elif TEST_STD_VER >= 17
464+
size_t rounded_size = (size + alignment - 1) & ~(alignment - 1);
465+
ret = aligned_alloc(alignment, size > rounded_size ? size : rounded_size);
463466
# else
464467
assert(posix_memalign(&ret, std::max(alignment, sizeof(void*)), size) != EINVAL);
465468
# endif

0 commit comments

Comments
 (0)