From 417fad9c4374c985ec41d02e28be512dad8fcd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= Date: Mon, 19 Aug 2024 09:57:31 +0200 Subject: [PATCH] [libxx] add tag_pointer --- libcxx/include/__bit/pointer_tag.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libcxx/include/__bit/pointer_tag.h b/libcxx/include/__bit/pointer_tag.h index 95bd186f473de3..b0b1aca1d8e40f 100644 --- a/libcxx/include/__bit/pointer_tag.h +++ b/libcxx/include/__bit/pointer_tag.h @@ -35,13 +35,18 @@ template > auto _result = tagged_pointer<_T, _Mask>{static_cast<_T*>(__builtin_pointer_tag(_ptr, _value, _Mask))}; #else // non-constexpr variant - auto _result = tagged_pointer<_T, _Mask>{reinterpret_cast((reinterpret_cast(_ptr) & ~_Mask) | (_value & _mask))}; + auto _result = tagged_pointer<_T, _Mask>{reinterpret_cast((reinterpret_cast(_ptr) & ~_Mask) | (_value & _Mask))}; #endif _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(_result.value() == _value, "value can't be recovered with provided mask"); _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(_result.pointer() == _ptr, "pointer can't be recovered with provided mask"); return _result; } +template +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto tag_pointer(_T * _ptr, uintptr_t _value) noexcept -> tagged_pointer<_T, _Mask> { + return tag_pointer<_T, _Mask>(_ptr, _value); +} + template > [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto unsafe_tagged_pointer_cast(_T * _ptr) noexcept -> tagged_pointer<_T, _Mask> { return tagged_pointer<_T, _Mask>{_ptr};