[libcxx-commits] [libcxx] [libc++] Fix std::pmr::new_delete_resource() returning underaligned pointers (PR #219166)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 27 03:48:28 PDT 2026
================
@@ -34,11 +34,11 @@ static bool is_aligned_to(void* ptr, size_t align) {
class _LIBCPP_HIDDEN __new_delete_memory_resource_imp : public memory_resource {
void* do_allocate(size_t bytes, size_t align) override {
#if _LIBCPP_HAS_ALIGNED_ALLOCATION
- return std::__libcpp_allocate<std::byte>(__element_count(bytes), align);
+ return ::new (std::align_val_t(align)) std::byte[bytes];
#else
- if (bytes == 0)
- bytes = 1;
- std::byte* result = std::__libcpp_allocate<std::byte>(__element_count(bytes), align);
+ if (bytes < align)
----------------
philnik777 wrote:
There is indeed: https://eel.is/c++draft/mem.res#private-1. FWIW I'd probably add the check to `allocate`, since that's inlined and the function that will basically always be called. I'll create a patch.
https://github.com/llvm/llvm-project/pull/219166
More information about the libcxx-commits
mailing list