-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[z/OS][libc++] Remove align_val_t
dependency in small_buffer.h
#114396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-libcxx Author: Zibi Sarbinowski (zibi2) ChangesWe need to guard 2 functions to avoid errors when
Full diff: https://github.com/llvm/llvm-project/pull/114396.diff 1 Files Affected:
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) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
align_val_t
is available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently this approach just disables dynamic allocation when aligned allocation is not available in such a case. I guess we should manually align the buffer ptrs instead.
Thank you for the comments, Louis please check if I addressed your suggestions correctly. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
… allocation and sized deallocation
@@ -75,7 +75,7 @@ class __small_buffer { | |||
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)}); | |||
std::__libcpp_deallocate((void*)__buffer_, _BufferSize * sizeof(byte), alignof(_Stored)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect, since you're deallocating the buffer itself (which is a member variable), not the pointer contained in the buffer. The previous reinterpret_cast
must be kept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for caching it.
@@ -75,7 +75,7 @@ class __small_buffer { | |||
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)}); | |||
std::__libcpp_deallocate(*reinterpret_cast<void**>(__buffer_), _BufferSize * sizeof(byte), alignof(_Stored)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change the size calculation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing out this. The good part is that this issue was also caught by stage3 sanitizer failure.
Let's merge once CI is green. |
align_val_t
is availablealign_val_t
dependency in small_buffer.h
…m#114396) Rewriting `__alloc()` and `__dealloc()` template functions to avoid errors when `small_buffer.h` is included in the modules LIT tests. For example: ``` test-suite-install/include/c++/v1/__utility/small_buffer.h:69:81: error: use of undeclared identifier 'align_val_t' # | 69 | byte* __allocation = static_cast<byte*>(::operator new[](sizeof(_Stored), align_val_t{alignof(_Stored)})); # | | ^ ```
We need to guard 2 functions to avoid errors when
small_buffer.h
is included in the modules LIT tests. For example: