[libcxx-commits] [libcxx] [z/OS][libc++] Guard to be used only when `align_val_t` is available (PR #114396)
Zibi Sarbinowski via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 31 12:38:23 PDT 2024
https://github.com/zibi2 updated https://github.com/llvm/llvm-project/pull/114396
>From a83b5caf569b1aabfe347f5d84f6a2c9f518333e Mon Sep 17 00:00:00 2001
From: Zbigniew Sarbinowski <zibi at ca.ibm.com>
Date: Thu, 31 Oct 2024 12:08:18 +0000
Subject: [PATCH 1/2] Guard to be used only when they are available
---
libcxx/include/__utility/small_buffer.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libcxx/include/__utility/small_buffer.h b/libcxx/include/__utility/small_buffer.h
index 70e068f89f62ed..6071bda4513657 100644
--- a/libcxx/include/__utility/small_buffer.h
+++ b/libcxx/include/__utility/small_buffer.h
@@ -61,6 +61,7 @@ class __small_buffer {
return *std::launder(reinterpret_cast<_Stored**>(__buffer_));
}
+# ifdef _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
template <class _Stored>
_LIBCPP_HIDE_FROM_ABI _Stored* __alloc() {
if constexpr (__fits_in_buffer<_Stored>) {
@@ -72,11 +73,14 @@ class __small_buffer {
}
}
+# endif // _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
+# ifdef _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
template <class _Stored>
_LIBCPP_HIDE_FROM_ABI void __dealloc() noexcept {
if constexpr (!__fits_in_buffer<_Stored>)
::operator delete[](*reinterpret_cast<void**>(__buffer_), sizeof(_Stored), align_val_t{alignof(_Stored)});
}
+# endif // _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
template <class _Stored, class... _Args>
_LIBCPP_HIDE_FROM_ABI void __construct(_Args&&... __args) {
>From ff95378feeb7ef5790aa7d3f14f409d61d11300d Mon Sep 17 00:00:00 2001
From: Zbigniew Sarbinowski <zibi at ca.ibm.com>
Date: Thu, 31 Oct 2024 19:49:21 +0000
Subject: [PATCH 2/2] Add __libcpp_allocate and __libcpp_deallocate in the
absense of align allocation and sized deallocation
---
libcxx/include/__utility/small_buffer.h | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/libcxx/include/__utility/small_buffer.h b/libcxx/include/__utility/small_buffer.h
index 6071bda4513657..a99df30e80c794 100644
--- a/libcxx/include/__utility/small_buffer.h
+++ b/libcxx/include/__utility/small_buffer.h
@@ -61,26 +61,30 @@ class __small_buffer {
return *std::launder(reinterpret_cast<_Stored**>(__buffer_));
}
-# ifdef _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
template <class _Stored>
_LIBCPP_HIDE_FROM_ABI _Stored* __alloc() {
if constexpr (__fits_in_buffer<_Stored>) {
return std::launder(reinterpret_cast<_Stored*>(__buffer_));
} else {
+# ifdef _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
byte* __allocation = static_cast<byte*>(::operator new[](sizeof(_Stored), align_val_t{alignof(_Stored)}));
std::construct_at(reinterpret_cast<byte**>(__buffer_), __allocation);
return std::launder(reinterpret_cast<_Stored*>(__allocation));
+# else
+ return static_cast<_Stored*>(std::__libcpp_allocate(_BufferSize* sizeof(byte), _LIBCPP_ALIGNOF(byte)));
+# endif // _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
}
}
-# endif // _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
-# ifdef _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
template <class _Stored>
_LIBCPP_HIDE_FROM_ABI void __dealloc() noexcept {
if constexpr (!__fits_in_buffer<_Stored>)
+# ifdef _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
::operator delete[](*reinterpret_cast<void**>(__buffer_), sizeof(_Stored), align_val_t{alignof(_Stored)});
- }
+# else
+ std::__libcpp_deallocate((void*)__buffer_, _BufferSize * sizeof(byte), _LIBCPP_ALIGNOF(_Stored));
# endif // _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
+ }
template <class _Stored, class... _Args>
_LIBCPP_HIDE_FROM_ABI void __construct(_Args&&... __args) {
More information about the libcxx-commits
mailing list