Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
659c512
commit eb6fbad
Showing
3 changed files
with
74 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters