[libcxx-commits] [libcxx] [libc++] Fix std::pmr::new_delete_resource() returning underaligned pointers (PR #219166)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 27 03:42:24 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)
----------------
ldionne wrote:

If `align == 0`, the behavior is different before/after the patch. Is that intended? Is there a precondition that `align > 0` (which we should check)?

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


More information about the libcxx-commits mailing list