[all-commits] [llvm/llvm-project] eb6fba: [libc++] Use aligned_alloc instead of posix_memali...
Alexander Richardson via All-commits
all-commits at lists.llvm.org
Thu Dec 22 07:02:10 PST 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: eb6fbad711a2cd39ccfb4b111db0a77933e06573
https://github.com/llvm/llvm-project/commit/eb6fbad711a2cd39ccfb4b111db0a77933e06573
Author: Alex Richardson <alexrichardson at google.com>
Date: 2022-12-22 (Thu, 22 Dec 2022)
Changed paths:
M libcxx/include/__config
M libcxx/include/new
M libcxx/test/libcxx/language.support/support.dynamic/new_faligned_allocation.pass.cpp
Log Message:
-----------
[libc++] Use aligned_alloc instead of posix_memalign for C++17
C++17 defines the C11 `aligned_alloc`, so we can use that instead of
posix_memalign. This change allows building against picolibc without
defining _DEFAULT_SOURCE/_GNU_SOURCE.
The C11 `aligned_alloc` function should be available on all supported
non-Windows platforms except for macOS where we need version 10.15.
There is one caveat: aligned_alloc() requires that __size is a multiple of
__alignment, but [new.delete.general] only states "if the value of an
alignment argument passed to any of these functions is not a valid
alignment value, the behavior is undefined".
To handle calls such as ::operator new(1, std::align_val_t(128)), we
round up __size to __alignment (and check for wrap-around).
This is required at least for macOS where aligned_alloc(128, 1) returns
an error instead of allocating memory (glibc ignores the specification).
Differential Revision: https://reviews.llvm.org/D138196
More information about the All-commits
mailing list