Hana =?utf-8?q?Dusíková?= <hani...@hanicka.net>, Hana =?utf-8?q?Dusíková?= <hani...@hanicka.net> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/111...@github.com>
================ @@ -0,0 +1,517 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___TAGGED_PTR_H +#define _LIBCPP___TAGGED_PTR_H + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 26 + +#include <__config> +#include <__type_traits/is_trivially_copyable.h> +#include <__assert> +#include "__bit/has_single_bit.h" +#include <__type_traits/rank.h> +#include "pointer_traits.h" +#include <compare> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <typename T, typename Y> concept convertible_to_from = std::convertible_to<Y, T> && std::convertible_to<T, Y>; + +template <typename T> concept pointer_tagging_schema = requires(T::dirty_pointer payload, T::clean_pointer clean, T::tag_type tag) { + requires convertible_to_from<typename T::tag_type, uintptr_t>; + requires std::is_pointer_v<typename T::clean_pointer>; + + { T::encode_pointer_with_tag(clean, tag) } noexcept -> std::same_as<typename T::dirty_pointer>; + { T::recover_pointer(payload) } noexcept -> std::same_as<typename T::clean_pointer>; + { T::recover_value(payload) } noexcept -> std::same_as<typename T::tag_type>; +}; + +template <typename T> concept pointer_tagging_schema_with_aliasing = pointer_tagging_schema<T> && requires(T::dirty_pointer payload) { + { T::recover_aliasing_pointer(payload) } noexcept -> std::same_as<typename T::clean_pointer>; +}; + +// no-op schema so I can better explain how schemas work +struct no_tag { + template <typename T, typename Tag> struct schema { + using clean_pointer = T *; + using dirty_pointer = void *; + using tag_type = Tag; + + [[clang::always_inline]] static constexpr dirty_pointer encode_pointer_with_tag(clean_pointer _ptr, tag_type) noexcept { + return (dirty_pointer)_ptr; + } + [[clang::always_inline]] static constexpr clean_pointer recover_pointer(dirty_pointer _ptr) noexcept { + return (clean_pointer)_ptr; + } + [[clang::always_inline]] static constexpr clean_pointer recover_aliasing_pointer(dirty_pointer _ptr) noexcept { + return (clean_pointer)_ptr; + } + [[clang::always_inline]] static constexpr tag_type recover_value(dirty_pointer) noexcept { ---------------- ldionne wrote: ```suggestion [[clang::always_inline]] static constexpr tag_type recover_tag(dirty_pointer) noexcept { ``` https://github.com/llvm/llvm-project/pull/111861 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits