diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-09-11 18:37:24 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-12-08 17:35:11 +0000 |
commit | 8a4dda33d67586ca2624f2a38417baa03a533a7f (patch) | |
tree | ea87f69d4341b5a653c3747ebbdbedd7b41da233 /contrib/llvm-project/libcxx/include | |
parent | 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e (diff) | |
parent | 8092e001bcd76c0b9fec2311f3a515aa60d2ed07 (diff) | |
download | src-8a4dda33d67586ca2624f2a38417baa03a533a7f.tar.gz src-8a4dda33d67586ca2624f2a38417baa03a533a7f.zip |
Merge llvm-project release/17.x llvmorg-17.0.0-rc4-10-g0176e8729ea4
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and
openmp to llvmorg-17.0.0-rc4-10-g0176e8729ea4.
PR: 273753
MFC after: 1 month
Diffstat (limited to 'contrib/llvm-project/libcxx/include')
13 files changed, 842 insertions, 106 deletions
diff --git a/contrib/llvm-project/libcxx/include/__algorithm/pstl_sort.h b/contrib/llvm-project/libcxx/include/__algorithm/pstl_sort.h index 81514953f24b..75c77ed40527 100644 --- a/contrib/llvm-project/libcxx/include/__algorithm/pstl_sort.h +++ b/contrib/llvm-project/libcxx/include/__algorithm/pstl_sort.h @@ -17,6 +17,7 @@ #include <__type_traits/is_execution_policy.h> #include <__type_traits/remove_cvref.h> #include <__utility/forward.h> +#include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/contrib/llvm-project/libcxx/include/__config b/contrib/llvm-project/libcxx/include/__config index 9759d3b9e8e0..43f8a20031ff 100644 --- a/contrib/llvm-project/libcxx/include/__config +++ b/contrib/llvm-project/libcxx/include/__config @@ -208,19 +208,16 @@ // HARDENING { -// TODO(hardening): remove this in LLVM 18. -// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) -// equivalent to setting the hardened mode. -# ifdef _LIBCPP_ENABLE_ASSERTIONS -# warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_ENABLE_HARDENED_MODE instead." -# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 -# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" -# endif -# if _LIBCPP_ENABLE_ASSERTIONS -# define _LIBCPP_ENABLE_HARDENED_MODE 1 -# endif +# ifndef _LIBCPP_ENABLE_ASSERTIONS +# define _LIBCPP_ENABLE_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS_DEFAULT +# endif +# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 +# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" # endif +// NOTE: These modes are experimental and are not stable yet in LLVM 17. Please refrain from using them and use the +// documented libc++ "safe" mode instead. +// // Enables the hardened mode which consists of all checks intended to be used in production. Hardened mode prioritizes // security-critical checks that can be done with relatively little overhead in constant time. Mutually exclusive with // `_LIBCPP_ENABLE_DEBUG_MODE`. @@ -275,6 +272,11 @@ # error "Only one of _LIBCPP_ENABLE_HARDENED_MODE and _LIBCPP_ENABLE_DEBUG_MODE can be enabled." # endif +# if _LIBCPP_ENABLE_ASSERTIONS && (_LIBCPP_ENABLE_HARDENED_MODE || _LIBCPP_ENABLE_DEBUG_MODE) +# error \ + "_LIBCPP_ENABLE_ASSERTIONS is mutually exclusive with _LIBCPP_ENABLE_HARDENED_MODE and _LIBCPP_ENABLE_DEBUG_MODE." +# endif + // Hardened mode checks. // clang-format off @@ -303,6 +305,18 @@ # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) +// Safe mode checks. + +# elif _LIBCPP_ENABLE_ASSERTIONS + +// All checks enabled. +# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) +# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) +# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) +# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) +# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) +# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) + // Disable all checks if hardening is not enabled. # else diff --git a/contrib/llvm-project/libcxx/include/__format/format_functions.h b/contrib/llvm-project/libcxx/include/__format/format_functions.h index 27ec0a295f4f..bb62c1ce10c1 100644 --- a/contrib/llvm-project/libcxx/include/__format/format_functions.h +++ b/contrib/llvm-project/libcxx/include/__format/format_functions.h @@ -245,6 +245,9 @@ __handle_replacement_field(_Iterator __begin, _Iterator __end, using _CharT = iter_value_t<_Iterator>; __format::__parse_number_result __r = __format::__parse_arg_id(__begin, __end, __parse_ctx); + if (__r.__last == __end) + std::__throw_format_error("The argument index should end with a ':' or a '}'"); + bool __parse = *__r.__last == _CharT(':'); switch (*__r.__last) { case _CharT(':'): diff --git a/contrib/llvm-project/libcxx/include/__locale_dir/locale_base_api/locale_guard.h b/contrib/llvm-project/libcxx/include/__locale_dir/locale_base_api/locale_guard.h index 0e2e91af7d19..5946ed698e0f 100644 --- a/contrib/llvm-project/libcxx/include/__locale_dir/locale_base_api/locale_guard.h +++ b/contrib/llvm-project/libcxx/include/__locale_dir/locale_base_api/locale_guard.h @@ -10,6 +10,7 @@ #define _LIBCPP___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H #include <__config> +#include <__locale> // for locale_t #include <clocale> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/contrib/llvm-project/libcxx/include/__mdspan/extents.h b/contrib/llvm-project/libcxx/include/__mdspan/extents.h index 42355678d60c..a510220d4096 100644 --- a/contrib/llvm-project/libcxx/include/__mdspan/extents.h +++ b/contrib/llvm-project/libcxx/include/__mdspan/extents.h @@ -171,11 +171,14 @@ public: _TStatic __static_val = _StaticValues::__get(__i); if (__static_val == _DynTag) { __dyn_vals_[_DynamicIdxMap::__get(__i)] = __values[__i]; - } - // Precondition check - else - _LIBCPP_ASSERT_UNCATEGORIZED(__values[__i] == static_cast<_TDynamic>(__static_val), - "extents construction: mismatch of provided arguments with static extents."); + } else + // Not catching this could lead to out of bounds errors later + // e.g. using my_mdspan_t = mdspan<int, extents<int, 10>>; my_mdspan_t = m(new int[5], 5); + // Right-hand-side construction looks ok with allocation and size matching, + // but since (potentially elsewhere defined) my_mdspan_t has static size m now thinks its range is 10 not 5 + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __values[__i] == static_cast<_TDynamic>(__static_val), + "extents construction: mismatch of provided arguments with static extents."); } } @@ -187,11 +190,14 @@ public: _TStatic __static_val = _StaticValues::__get(__i); if (__static_val == _DynTag) { __dyn_vals_[_DynamicIdxMap::__get(__i)] = static_cast<_TDynamic>(__vals[__i]); - } - // Precondition check - else - _LIBCPP_ASSERT_UNCATEGORIZED(static_cast<_TDynamic>(__vals[__i]) == static_cast<_TDynamic>(__static_val), - "extents construction: mismatch of provided arguments with static extents."); + } else + // Not catching this could lead to out of bounds errors later + // e.g. using my_mdspan_t = mdspan<int, extents<int, 10>>; my_mdspan_t = m(new int[N], span<int,1>(&N)); + // Right-hand-side construction looks ok with allocation and size matching, + // but since (potentially elsewhere defined) my_mdspan_t has static size m now thinks its range is 10 not N + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + static_cast<_TDynamic>(__vals[__i]) == static_cast<_TDynamic>(__static_val), + "extents construction: mismatch of provided arguments with static extents."); } } @@ -310,28 +316,37 @@ public: (sizeof...(_OtherIndexTypes) == __rank_ || sizeof...(_OtherIndexTypes) == __rank_dynamic_)) _LIBCPP_HIDE_FROM_ABI constexpr explicit extents(_OtherIndexTypes... __dynvals) noexcept : __vals_(static_cast<index_type>(__dynvals)...) { - _LIBCPP_ASSERT_UNCATEGORIZED(__mdspan_detail::__are_representable_as<index_type>(__dynvals...), - "extents ctor: arguments must be representable as index_type and nonnegative"); + // Not catching this could lead to out of bounds errors later + // e.g. mdspan m(ptr, dextents<char, 1>(200u)); leads to an extent of -56 on m + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__mdspan_detail::__are_representable_as<index_type>(__dynvals...), + "extents ctor: arguments must be representable as index_type and nonnegative"); } template <class _OtherIndexType, size_t _Size> - requires(is_convertible_v<_OtherIndexType, index_type> && is_nothrow_constructible_v<index_type, _OtherIndexType> && + requires(is_convertible_v<const _OtherIndexType&, index_type> && + is_nothrow_constructible_v<index_type, const _OtherIndexType&> && (_Size == __rank_ || _Size == __rank_dynamic_)) explicit(_Size != __rank_dynamic_) _LIBCPP_HIDE_FROM_ABI constexpr extents(const array<_OtherIndexType, _Size>& __exts) noexcept : __vals_(span(__exts)) { - _LIBCPP_ASSERT_UNCATEGORIZED(__mdspan_detail::__are_representable_as<index_type>(span(__exts)), - "extents ctor: arguments must be representable as index_type and nonnegative"); + // Not catching this could lead to out of bounds errors later + // e.g. mdspan m(ptr, dextents<char, 1>(array<unsigned,1>(200))); leads to an extent of -56 on m + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__mdspan_detail::__are_representable_as<index_type>(span(__exts)), + "extents ctor: arguments must be representable as index_type and nonnegative"); } template <class _OtherIndexType, size_t _Size> - requires(is_convertible_v<_OtherIndexType, index_type> && is_nothrow_constructible_v<index_type, _OtherIndexType> && + requires(is_convertible_v<const _OtherIndexType&, index_type> && + is_nothrow_constructible_v<index_type, const _OtherIndexType&> && (_Size == __rank_ || _Size == __rank_dynamic_)) explicit(_Size != __rank_dynamic_) _LIBCPP_HIDE_FROM_ABI constexpr extents(const span<_OtherIndexType, _Size>& __exts) noexcept : __vals_(__exts) { - _LIBCPP_ASSERT_UNCATEGORIZED(__mdspan_detail::__are_representable_as<index_type>(__exts), - "extents ctor: arguments must be representable as index_type and nonnegative"); + // Not catching this could lead to out of bounds errors later + // e.g. array a{200u}; mdspan<int, dextents<char,1>> m(ptr, extents(span<unsigned,1>(a))); leads to an extent of -56 + // on m + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__mdspan_detail::__are_representable_as<index_type>(__exts), + "extents ctor: arguments must be representable as index_type and nonnegative"); } private: @@ -380,10 +395,16 @@ public: for (size_t __r = 0; __r < rank(); __r++) { if constexpr (static_cast<make_unsigned_t<index_type>>(numeric_limits<index_type>::max()) < static_cast<make_unsigned_t<_OtherIndexType>>(numeric_limits<_OtherIndexType>::max())) { - _LIBCPP_ASSERT_UNCATEGORIZED(__mdspan_detail::__is_representable_as<index_type>(__other.extent(__r)), - "extents ctor: arguments must be representable as index_type and nonnegative"); + // Not catching this could lead to out of bounds errors later + // e.g. dextents<char,1>> e(dextents<unsigned,1>(200)) leads to an extent of -56 on e + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __mdspan_detail::__is_representable_as<index_type>(__other.extent(__r)), + "extents ctor: arguments must be representable as index_type and nonnegative"); } - _LIBCPP_ASSERT_UNCATEGORIZED( + // Not catching this could lead to out of bounds errors later + // e.g. mdspan<int, extents<int, 10>> m = mdspan<int, dextents<int, 1>>(new int[5], 5); + // Right-hand-side construction was ok, but m now thinks its range is 10 not 5 + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( (_Values::__static_value(__r) == dynamic_extent) || (static_cast<index_type>(__other.extent(__r)) == static_cast<index_type>(_Values::__static_value(__r))), "extents construction: mismatch of provided arguments with static extents."); diff --git a/contrib/llvm-project/libcxx/include/__mdspan/layout_left.h b/contrib/llvm-project/libcxx/include/__mdspan/layout_left.h index e81e0d10b595..7503dcf77d13 100644 --- a/contrib/llvm-project/libcxx/include/__mdspan/layout_left.h +++ b/contrib/llvm-project/libcxx/include/__mdspan/layout_left.h @@ -75,8 +75,11 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr mapping() noexcept = default; _LIBCPP_HIDE_FROM_ABI constexpr mapping(const mapping&) noexcept = default; _LIBCPP_HIDE_FROM_ABI constexpr mapping(const extents_type& __ext) noexcept : __extents_(__ext) { - _LIBCPP_ASSERT(__required_span_size_is_representable(__ext), - "layout_left::mapping extents ctor: product of extents must be representable as index_type."); + // not catching this could lead to out-of-bounds access later when used inside mdspan + // mapping<dextents<char, 2>> map(dextents<char, 2>(40,40)); map(10, 3) == -126 + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __required_span_size_is_representable(__ext), + "layout_left::mapping extents ctor: product of extents must be representable as index_type."); } template <class _OtherExtents> @@ -84,7 +87,9 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_OtherExtents, extents_type>) mapping(const mapping<_OtherExtents>& __other) noexcept : __extents_(__other.extents()) { - _LIBCPP_ASSERT( + // not catching this could lead to out-of-bounds access later when used inside mdspan + // mapping<dextents<char, 2>> map(mapping<dextents<int, 2>>(dextents<int, 2>(40,40))); map(10, 3) == -126 + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( __mdspan_detail::__is_representable_as<index_type>(__other.required_span_size()), "layout_left::mapping converting ctor: other.required_span_size() must be representable as index_type."); } @@ -94,7 +99,13 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_OtherExtents, extents_type>) mapping(const layout_right::mapping<_OtherExtents>& __other) noexcept : __extents_(__other.extents()) { - _LIBCPP_ASSERT( + // not catching this could lead to out-of-bounds access later when used inside mdspan + // Note: since this is constraint to rank 1, extents itself would catch the invalid conversion first + // and thus this assertion should never be triggered, but keeping it here for consistency + // layout_left::mapping<dextents<char, 1>> map( + // layout_right::mapping<dextents<unsigned, 1>>(dextents<unsigned, 1>(200))); map.extents().extent(0) == + // -56 + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( __mdspan_detail::__is_representable_as<index_type>(__other.required_span_size()), "layout_left::mapping converting ctor: other.required_span_size() must be representable as index_type."); } @@ -122,6 +133,10 @@ public: requires((sizeof...(_Indices) == extents_type::rank()) && (is_convertible_v<_Indices, index_type> && ...) && (is_nothrow_constructible_v<index_type, _Indices> && ...)) _LIBCPP_HIDE_FROM_ABI constexpr index_type operator()(_Indices... __idx) const noexcept { + // Mappings are generally meant to be used for accessing allocations and are meant to guarantee to never + // return a value exceeding required_span_size(), which is used to know how large an allocation one needs + // Thus, this is a canonical point in multi-dimensional data structures to make invalid element access checks + // However, mdspan does check this on its own, so for now we avoid double checking in hardened mode _LIBCPP_ASSERT(__mdspan_detail::__is_multidimensional_index_in(__extents_, __idx...), "layout_left::mapping: out of bounds indexing"); array<index_type, extents_type::rank()> __idx_a{static_cast<index_type>(__idx)...}; @@ -144,9 +159,12 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr index_type stride(rank_type __r) const noexcept requires(extents_type::rank() > 0) { - _LIBCPP_ASSERT(__r < extents_type::rank(), "layout_left::mapping::stride(): invalid rank index"); + // While it would be caught by extents itself too, using a too large __r + // is functionally an out of bounds access on the stored information needed to compute strides + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __r < extents_type::rank(), "layout_left::mapping::stride(): invalid rank index"); index_type __s = 1; - for (rank_type __i = extents_type::rank() - 1; __i > __r; __i--) + for (rank_type __i = 0; __i < __r; __i++) __s *= __extents_.extent(__i); return __s; } @@ -159,7 +177,7 @@ public: } private: - extents_type __extents_{}; // exposition only + _LIBCPP_NO_UNIQUE_ADDRESS extents_type __extents_{}; }; #endif // _LIBCPP_STD_VER >= 23 diff --git a/contrib/llvm-project/libcxx/include/__mdspan/layout_right.h b/contrib/llvm-project/libcxx/include/__mdspan/layout_right.h index a8a91b86c714..3d814554a1be 100644 --- a/contrib/llvm-project/libcxx/include/__mdspan/layout_right.h +++ b/contrib/llvm-project/libcxx/include/__mdspan/layout_right.h @@ -74,8 +74,11 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr mapping() noexcept = default; _LIBCPP_HIDE_FROM_ABI constexpr mapping(const mapping&) noexcept = default; _LIBCPP_HIDE_FROM_ABI constexpr mapping(const extents_type& __ext) noexcept : __extents_(__ext) { - _LIBCPP_ASSERT(__required_span_size_is_representable(__ext), - "layout_right::mapping extents ctor: product of extents must be representable as index_type."); + // not catching this could lead to out-of-bounds access later when used inside mdspan + // mapping<dextents<char, 2>> map(dextents<char, 2>(40,40)); map(3, 10) == -126 + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __required_span_size_is_representable(__ext), + "layout_right::mapping extents ctor: product of extents must be representable as index_type."); } template <class _OtherExtents> @@ -83,7 +86,9 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_OtherExtents, extents_type>) mapping(const mapping<_OtherExtents>& __other) noexcept : __extents_(__other.extents()) { - _LIBCPP_ASSERT( + // not catching this could lead to out-of-bounds access later when used inside mdspan + // mapping<dextents<char, 2>> map(mapping<dextents<int, 2>>(dextents<int, 2>(40,40))); map(3, 10) == -126 + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( __mdspan_detail::__is_representable_as<index_type>(__other.required_span_size()), "layout_right::mapping converting ctor: other.required_span_size() must be representable as index_type."); } @@ -93,7 +98,13 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_OtherExtents, extents_type>) mapping(const layout_left::mapping<_OtherExtents>& __other) noexcept : __extents_(__other.extents()) { - _LIBCPP_ASSERT( + // not catching this could lead to out-of-bounds access later when used inside mdspan + // Note: since this is constraint to rank 1, extents itself would catch the invalid conversion first + // and thus this assertion should never be triggered, but keeping it here for consistency + // layout_right::mapping<dextents<char, 1>> map( + // layout_left::mapping<dextents<unsigned, 1>>(dextents<unsigned, 1>(200))); map.extents().extent(0) == + // -56 + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( __mdspan_detail::__is_representable_as<index_type>(__other.required_span_size()), "layout_right::mapping converting ctor: other.required_span_size() must be representable as index_type."); } @@ -121,6 +132,10 @@ public: requires((sizeof...(_Indices) == extents_type::rank()) && (is_convertible_v<_Indices, index_type> && ...) && (is_nothrow_constructible_v<index_type, _Indices> && ...)) _LIBCPP_HIDE_FROM_ABI constexpr index_type operator()(_Indices... __idx) const noexcept { + // Mappings are generally meant to be used for accessing allocations and are meant to guarantee to never + // return a value exceeding required_span_size(), which is used to know how large an allocation one needs + // Thus, this is a canonical point in multi-dimensional data structures to make invalid element access checks + // However, mdspan does check this on its own, so for now we avoid double checking in hardened mode _LIBCPP_ASSERT(__mdspan_detail::__is_multidimensional_index_in(__extents_, __idx...), "layout_right::mapping: out of bounds indexing"); return [&]<size_t... _Pos>(index_sequence<_Pos...>) { @@ -141,7 +156,10 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr index_type stride(rank_type __r) const noexcept requires(extents_type::rank() > 0) { - _LIBCPP_ASSERT(__r < extents_type::rank(), "layout_right::mapping::stride(): invalid rank index"); + // While it would be caught by extents itself too, using a too large __r + // is functionally an out of bounds access on the stored information needed to compute strides + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __r < extents_type::rank(), "layout_right::mapping::stride(): invalid rank index"); index_type __s = 1; for (rank_type __i = extents_type::rank() - 1; __i > __r; __i--) __s *= __extents_.extent(__i); @@ -156,7 +174,7 @@ public: } private: - extents_type __extents_{}; // exposition only + _LIBCPP_NO_UNIQUE_ADDRESS extents_type __extents_{}; }; #endif // _LIBCPP_STD_VER >= 23 diff --git a/contrib/llvm-project/libcxx/include/__mdspan/mdspan.h b/contrib/llvm-project/libcxx/include/__mdspan/mdspan.h new file mode 100644 index 000000000000..58f3b9cf1b18 --- /dev/null +++ b/contrib/llvm-project/libcxx/include/__mdspan/mdspan.h @@ -0,0 +1,308 @@ +// -*- 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 +// +// Kokkos v. 4.0 +// Copyright (2022) National Technology & Engineering +// Solutions of Sandia, LLC (NTESS). +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCPP___MDSPAN_MDSPAN_H +#define _LIBCPP___MDSPAN_MDSPAN_H + +#include <__assert> +#include <__config> +#include <__fwd/mdspan.h> +#include <__mdspan/default_accessor.h> +#include <__mdspan/extents.h> +#include <__type_traits/extent.h> +#include <__type_traits/is_abstract.h> +#include <__type_traits/is_array.h> +#include <__type_traits/is_constructible.h> +#include <__type_traits/is_convertible.h> +#include <__type_traits/is_default_constructible.h> +#include <__type_traits/is_nothrow_constructible.h> +#include <__type_traits/is_pointer.h> +#include <__type_traits/is_same.h> +#include <__type_traits/rank.h> +#include <__type_traits/remove_all_extents.h> +#include <__type_traits/remove_cv.h> +#include <__type_traits/remove_pointer.h> +#include <__type_traits/remove_reference.h> +#include <__utility/integer_sequence.h> +#include <array> +#include <cinttypes> +#include <cstddef> +#include <limits> +#include <span> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 23 + +// Helper for lightweight test checking that one did pass a layout policy as LayoutPolicy template argument +namespace __mdspan_detail { +template <class _Layout, class _Extents> +concept __has_invalid_mapping = !requires { typename _Layout::template mapping<_Extents>; }; +} // namespace __mdspan_detail + +template <class _ElementType, + class _Extents, + class _LayoutPolicy = layout_right, + class _AccessorPolicy = default_accessor<_ElementType> > +class mdspan { +private: + static_assert(__mdspan_detail::__is_extents_v<_Extents>, + "mdspan: Extents template parameter must be a specialization of extents."); + static_assert(!is_array_v<_ElementType>, "mdspan: ElementType template parameter may not be an array type"); + static_assert(!is_abstract_v<_ElementType>, "mdspan: ElementType template parameter may not be an abstract class"); + static_assert(is_same_v<_ElementType, typename _AccessorPolicy::element_type>, + "mdspan: ElementType template parameter must match AccessorPolicy::element_type"); + static_assert(!__mdspan_detail::__has_invalid_mapping<_LayoutPolicy, _Extents>, + "mdspan: LayoutPolicy template parameter is invalid. A common mistake is to pass a layout mapping " + "instead of a layout policy"); + +public: + using extents_type = _Extents; + using layout_type = _LayoutPolicy; + using accessor_type = _AccessorPolicy; + using mapping_type = typename layout_type::template mapping<extents_type>; + using element_type = _ElementType; + using value_type = remove_cv_t<element_type>; + using index_type = typename extents_type::index_type; + using size_type = typename extents_type::size_type; + using rank_type = typename extents_type::rank_type; + using data_handle_type = typename accessor_type::data_handle_type; + using reference = typename accessor_type::reference; + + _LIBCPP_HIDE_FROM_ABI static constexpr rank_type rank() noexcept { return extents_type::rank(); } + _LIBCPP_HIDE_FROM_ABI static constexpr rank_type rank_dynamic() noexcept { return extents_type::rank_dynamic(); } + _LIBCPP_HIDE_FROM_ABI static constexpr size_t static_extent(rank_type __r) noexcept { + return extents_type::static_extent(__r); + } + _LIBCPP_HIDE_FROM_ABI constexpr index_type extent(rank_type __r) const noexcept { + return __map_.extents().extent(__r); + }; + +public: + //-------------------------------------------------------------------------------- + // [mdspan.mdspan.cons], mdspan constructors, assignment, and destructor + + _LIBCPP_HIDE_FROM_ABI constexpr mdspan() + requires((extents_type::rank_dynamic() > 0) && is_default_constructible_v<data_handle_type> && + is_default_constructible_v<mapping_type> && is_default_constructible_v<accessor_type>) + = default; + _LIBCPP_HIDE_FROM_ABI constexpr mdspan(const mdspan&) = default; + _LIBCPP_HIDE_FROM_ABI constexpr mdspan(mdspan&&) = default; + + template <class... _OtherIndexTypes> + requires((is_convertible_v<_OtherIndexTypes, index_type> && ...) && + (is_nothrow_constructible_v<index_type, _OtherIndexTypes> && ...) && + ((sizeof...(_OtherIndexTypes) == rank()) || (sizeof...(_OtherIndexTypes) == rank_dynamic())) && + is_constructible_v<mapping_type, extents_type> && is_default_constructible_v<accessor_type>) + _LIBCPP_HIDE_FROM_ABI explicit constexpr mdspan(data_handle_type __p, _OtherIndexTypes... __exts) + : __ptr_(std::move(__p)), __map_(extents_type(static_cast<index_type>(std::move(__exts))...)), __acc_{} {} + + template <class _OtherIndexType, size_t _Size> + requires(is_convertible_v<const _OtherIndexType&, index_type> && + is_nothrow_constructible_v<index_type, const _OtherIndexType&> && + ((_Size == rank()) || (_Size == rank_dynamic())) && is_constructible_v<mapping_type, extents_type> && + is_default_constructible_v<accessor_type>) + explicit(_Size != rank_dynamic()) + _LIBCPP_HIDE_FROM_ABI constexpr mdspan(data_handle_type __p, const array<_OtherIndexType, _Size>& __exts) + : __ptr_(std::move(__p)), __map_(extents_type(__exts)), __acc_{} {} + + template <class _OtherIndexType, size_t _Size> + requires(is_convertible_v<const _OtherIndexType&, index_type> && + is_nothrow_constructible_v<index_type, const _OtherIndexType&> && + ((_Size == rank()) || (_Size == rank_dynamic())) && is_constructible_v<mapping_type, extents_type> && + is_default_constructible_v<accessor_type>) + explicit(_Size != rank_dynamic()) + _LIBCPP_HIDE_FROM_ABI constexpr mdspan(data_handle_type __p, span<_OtherIndexType, _Size> __exts) + : __ptr_(std::move(__p)), __map_(extents_type(__exts)), __acc_{} {} + + _LIBCPP_HIDE_FROM_ABI constexpr mdspan(data_handle_type __p, const extents_type& __exts) + requires(is_default_constructible_v<accessor_type> && is_constructible_v<mapping_type, const extents_type&>) + : __ptr_(std::move(__p)), __map_(__exts), __acc_{} {} + + _LIBCPP_HIDE_FROM_ABI constexpr mdspan(data_handle_type __p, const mapping_type& __m) + requires(is_default_constructible_v<accessor_type>) + : __ptr_(std::move(__p)), __map_(__m), __acc_{} {} + + _LIBCPP_HIDE_FROM_ABI constexpr mdspan(data_handle_type __p, const mapping_type& __m, const accessor_type& __a) + : __ptr_(std::move(__p)), __map_(__m), __acc_(__a) {} + + template <class _OtherElementType, class _OtherExtents, class _OtherLayoutPolicy, class _OtherAccessor> + requires(is_constructible_v<mapping_type, const typename _OtherLayoutPolicy::template mapping<_OtherExtents>&> && + is_constructible_v<accessor_type, const _OtherAccessor&>) + explicit(!is_convertible_v<const typename _OtherLayoutPolicy::template mapping<_OtherExtents>&, mapping_type> || + !is_convertible_v<const _OtherAccessor&, accessor_type>) + _LIBCPP_HIDE_FROM_ABI constexpr mdspan( + const mdspan<_OtherElementType, _OtherExtents, _OtherLayoutPolicy, _OtherAccessor>& __other) + : __ptr_(__other.__ptr_), __map_(__other.__map_), __acc_(__other.__acc_) { + static_assert(is_constructible_v<data_handle_type, const typename _OtherAccessor::data_handle_type&>, + "mdspan: incompatible data_handle_type for mdspan construction"); + static_assert( + is_constructible_v<extents_type, _OtherExtents>, "mdspan: incompatible extents for mdspan construction"); + + // The following precondition is part of the standard, but is unlikely to be triggered. + // The extents constructor checks this and the mapping must be storing the extents, since + // its extents() function returns a const reference to extents_type. + // The only way this can be triggered is if the mapping conversion constructor would for example + // always construct its extents() only from the dynamic extents, instead of from the other extents. + if constexpr (rank() > 0) { + for (size_t __r = 0; __r < rank(); __r++) { + // Not catching this could lead to out of bounds errors later + // e.g. mdspan<int, dextents<char,1>, non_checking_layout> m = + // mdspan<int, dextents<unsigned, 1>, non_checking_layout>(ptr, 200); leads to an extent of -56 on m + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + (static_extent(__r) == dynamic_extent) || + (static_cast<index_type>(__other.extent(__r)) == static_cast<index_type>(static_extent(__r))), + "mdspan: conversion mismatch of source dynamic extents with static extents"); + } + } + } + + _LIBCPP_HIDE_FROM_ABI constexpr mdspan& operator=(const mdspan&) = default; + _LIBCPP_HIDE_FROM_ABI constexpr mdspan& operator=(mdspan&&) = default; + + //-------------------------------------------------------------------------------- + // [mdspan.mdspan.members], members + + template <class... _OtherIndexTypes> + requires((is_convertible_v<_OtherIndexTypes, index_type> && ...) && + (is_nothrow_constructible_v<index_type, _OtherIndexTypes> && ...) && + (sizeof...(_OtherIndexTypes) == rank())) + _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](_OtherIndexTypes... __indices) const { + // Note the standard layouts would also check this, but user provided ones may not, so we + // check the precondition here + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__mdspan_detail::__is_multidimensional_index_in(extents(), __indices...), + "mdspan: operator[] out of bounds access"); + return __acc_.access(__ptr_, __map_(static_cast<index_type>(std::move(__indices))...)); + } + + template <class _OtherIndexType> + requires(is_convertible_v<const _OtherIndexType&, index_type> && + is_nothrow_constructible_v<index_type, const _OtherIndexType&>) + _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](const array< _OtherIndexType, rank()>& __indices) const { + return __acc_.access(__ptr_, [&]<size_t... _Idxs>(index_sequence<_Idxs...>) { + return __map_(__indices[_Idxs]...); + }(make_index_sequence<rank()>())); + } + + template <class _OtherIndexType> + requires(is_convertible_v<const _OtherIndexType&, index_type> && + is_nothrow_constructible_v<index_type, const _OtherIndexType&>) + _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](span<_OtherIndexType, rank()> __indices) const { + return __acc_.access(__ptr_, [&]<size_t... _Idxs>(index_sequence<_Idxs...>) { + return __map_(__indices[_Idxs]...); + }(make_index_sequence<rank()>())); + } + + _LIBCPP_HIDE_FROM_ABI constexpr size_type size() const noexcept { + // Could leave this as only checked in debug mode: semantically size() is never + // guaranteed to be related to any accessible range + _LIBCPP_ASSERT_UNCATEGORIZED( + false == ([&]<size_t... _Idxs>(index_sequence<_Idxs...>) { + size_type __prod = 1; + return (__builtin_mul_overflow(__prod, extent(_Idxs), &__prod) || ... || false); + }(make_index_sequence<rank()>())), + "mdspan: size() is not representable as size_type"); + return [&]<size_t... _Idxs>(index_sequence<_Idxs...>) { + return ((static_cast<size_type>(__map_.extents().extent(_Idxs))) * ... * size_type(1)); + }(make_index_sequence<rank()>()); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const noexcept { + return [&]<size_t... _Idxs>(index_sequence<_Idxs...>) { + return (rank() > 0) && ((__map_.extents().extent(_Idxs) == index_type(0)) || ... || false); + }(make_index_sequence<rank()>()); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr void swap(mdspan& __x, mdspan& __y) noexcept { + swap(__x.__ptr_, __y.__ptr_); + swap(__x.__map_, __y.__map_); + swap(__x.__acc_, __y.__acc_); + } + + _LIBCPP_HIDE_FROM_ABI constexpr const extents_type& extents() const noexcept { return __map_.extents(); }; + _LIBCPP_HIDE_FROM_ABI constexpr const data_handle_type& data_handle() const noexcept { return __ptr_; }; + _LIBCPP_HIDE_FROM_ABI constexpr const mapping_type& mapping() const noexcept { return __map_; }; + _LIBCPP_HIDE_FROM_ABI constexpr const accessor_type& accessor() const noexcept { return __acc_; }; + + _LIBCPP_HIDE_FROM_ABI static constexpr bool is_always_unique() { return mapping_type::is_always_unique(); }; + _LIBCPP_HIDE_FROM_ABI static constexpr bool is_always_exhaustive() { return mapping_type::is_always_exhaustive(); }; + _LIBCPP_HIDE_FROM_ABI static constexpr bool is_always_strided() { return mapping_type::is_always_strided(); }; + + _LIBCPP_HIDE_FROM_ABI constexpr bool is_unique() const { return __map_.is_unique(); }; + _LIBCPP_HIDE_FROM_ABI constexpr bool is_exhaustive() const { return __map_.is_exhaustive(); }; + _LIBCPP_HIDE_FROM_ABI constexpr bool is_strided() const { return __map_.is_strided(); }; + _LIBCPP_HIDE_FROM_ABI constexpr index_type stride(rank_type __r) const { return __map_.stride(__r); }; + +private: + _LIBCPP_NO_UNIQUE_ADDRESS data_handle_type __ptr_{}; + _LIBCPP_NO_UNIQUE_ADDRESS mapping_type __map_{}; + _LIBCPP_NO_UNIQUE_ADDRESS accessor_type __acc_{}; + + template <class, class, class, class> + friend class mdspan; +}; + +template <class _ElementType, class... _OtherIndexTypes> + requires((is_convertible_v<_OtherIndexTypes, size_t> && ...) && (sizeof...(_OtherIndexTypes) > 0)) +explicit mdspan(_ElementType*, _OtherIndexTypes...) + -> mdspan<_ElementType, dextents<size_t, sizeof...(_OtherIndexTypes)>>; + +template <class _Pointer> + requires(is_pointer_v<remove_reference_t<_Pointer>>) +mdspan(_Pointer&&) -> mdspan<remove_pointer_t<remove_reference_t<_Pointer>>, extents<size_t>>; + +template <class _CArray> + requires(is_array_v<_CArray> && (rank_v<_CArray> == 1)) +mdspan(_CArray&) -> mdspan<remove_all_extents_t<_CArray>, extents<size_t, extent_v<_CArray, 0>>>; + +template <class _ElementType, class _OtherIndexType, size_t _Size> +mdspan(_ElementType*, const array<_OtherIndexType, _Size>&) -> mdspan<_ElementType, dextents<size_t, _Size>>; + +template <class _ElementType, class _OtherIndexType, size_t _Size> +mdspan(_ElementType*, span<_OtherIndexType, _Size>) -> mdspan<_ElementType, dextents<size_t, _Size>>; + +// This one is necessary because all the constructors take `data_handle_type`s, not +// `_ElementType*`s, and `data_handle_type` is taken from `accessor_type::data_handle_type`, which +// seems to throw off automatic deduction guides. +template <class _ElementType, class _OtherIndexType, size_t... _ExtentsPack> +mdspan(_ElementType*, const extents<_OtherIndexType, _ExtentsPack...>&) + -> mdspan<_ElementType, extents<_OtherIndexType, _ExtentsPack...>>; + +template <class _ElementType, class _MappingType> +mdspan(_ElementType*, const _MappingType&) + -> mdspan<_ElementType, typename _MappingType::extents_type, typename _MappingType::layout_type>; + +template <class _MappingType, class _AccessorType> +mdspan(const typename _AccessorType::data_handle_type, const _MappingType&, const _AccessorType&) + -> mdspan<typename _AccessorType::element_type, + typename _MappingType::extents_type, + typename _MappingType::layout_type, + _AccessorType>; + +#endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___MDSPAN_MDSPAN_H diff --git a/contrib/llvm-project/libcxx/include/__std_clang_module b/contrib/llvm-project/libcxx/include/__std_clang_module new file mode 100644 index 000000000000..4d02336d30b0 --- /dev/null +++ b/contrib/llvm-project/libcxx/include/__std_clang_module @@ -0,0 +1,226 @@ +// -*- 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 +// +//===----------------------------------------------------------------------===// + +// WARNING, this entire header is generated by +// utils/generate_std_clang_module_header.py +// DO NOT MODIFY! + +// This header should not be directly included, it's exclusively to import all +// of the libc++ public clang modules for the `std` clang module to export. In +// other words, it's to facilitate `@import std;` in Objective-C++ and `import std` +// in Swift to expose all of the libc++ interfaces. This is generally not +// recommended, however there are some clients that need to import all of libc++ +// without knowing what "all" is. +#if !__building_module(std) +# error "Do not include this header directly, include individual headers instead" +#endif + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#include <algorithm> +#include <any> +#include <array> +#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) +# include <atomic> +#endif +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include <barrier> +#endif +#include <bit> +#include <bitset> +#include <cassert> +#include <ccomplex> +#include <cctype> +#include <cerrno> +#include <cfenv> +#include <cfloat> +#include <charconv> +#include <chrono> +#include <cinttypes> +#include <ciso646> +#include <climits> +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <clocale> +#endif +#include <cmath> +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <codecvt> +#endif +#include <compare> +#include <complex.h> +#include <complex> +#include <concepts> +#include <condition_variable> +#include <coroutine> +#include <csetjmp> +#include <csignal> +#include <cstdarg> +#include <cstdbool> +#include <cstddef> +#include <cstdint> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <ctgmath> +#include <ctime> +#include <ctype.h> +#include <cuchar> +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) +# include <cwchar> +#endif +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) +# include <cwctype> +#endif +#include <deque> +#include <errno.h> +#include <exception> +#include <execution> +#include <expected> +#include <experimental/deque> +#include <experimental/forward_list> +#include <experimental/iterator> +#include <experimental/list> +#include <experimental/map> +#include <experimental/memory_resource> +#include <experimental/propagate_const> +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <experimental/regex> +#endif +#include <experimental/set> +#include <experimental/simd> +#include <experimental/string> +#include <experimental/type_traits> +#include <experimental/unordered_map> +#include <experimental/unordered_set> +#include <experimental/utility> +#include <experimental/vector> +#include <fenv.h> +#include <filesystem> +#include <float.h> +#include <format> +#include <forward_list> +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <fstream> +#endif +#include <functional> +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include <future> +#endif +#include <initializer_list> +#include <inttypes.h> +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <iomanip> +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <ios> +#endif +#include <iosfwd> +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <iostream> +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <istream> +#endif +#include <iterator> +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include <latch> +#endif +#include <limits.h> +#include <limits> +#include <list> +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <locale.h> +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <locale> +#endif +#include <map> +#include <math.h> +#include <mdspan> +#include <memory> +#include <memory_resource> +#include <mutex> +#include <new> +#include <numbers> +#include <numeric> +#include <optional> +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <ostream> +#endif +#include <print> +#include <queue> +#include <random> +#include <ranges> +#include <ratio> +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <regex> +#endif +#include <scoped_allocator> +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include <semaphore> +#endif +#include <set> +#include <setjmp.h> +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include <shared_mutex> +#endif +#include <source_location> +#include <span> +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <sstream> +#endif +#include <stack> +#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) +# include <stdatomic.h> +#endif +#include <stdbool.h> +#include <stddef.h> +#include <stdexcept> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include <stop_token> +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <streambuf> +#endif +#include <string.h> +#include <string> +#include <string_view> +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <strstream> +#endif +#include <system_error> +#include <tgmath.h> +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include <thread> +#endif +#include <tuple> +#include <type_traits> +#include <typeindex> +#include <typeinfo> +#include <uchar.h> +#include <unordered_map> +#include <unordered_set> +#include <utility> +#include <valarray> +#include <variant> +#include <vector> +#include <version> +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) +# include <wchar.h> +#endif +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) +# include <wctype.h> +#endif diff --git a/contrib/llvm-project/libcxx/include/__type_traits/is_nothrow_constructible.h b/contrib/llvm-project/libcxx/include/__type_traits/is_nothrow_constructible.h index d4686d89fd96..4949062433b7 100644 --- a/contrib/llvm-project/libcxx/include/__type_traits/is_nothrow_constructible.h +++ b/contrib/llvm-project/libcxx/include/__type_traits/is_nothrow_constructible.h @@ -22,7 +22,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if __has_builtin(__is_nothrow_constructible) +// GCC is disabled due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106611 +#if __has_builtin(__is_nothrow_constructible) && !defined(_LIBCPP_COMPILER_GCC) template < class _Tp, class... _Args> struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible diff --git a/contrib/llvm-project/libcxx/include/mdspan b/contrib/llvm-project/libcxx/include/mdspan index 701def50b40a..9082eb8bdb55 100644 --- a/contrib/llvm-project/libcxx/include/mdspan +++ b/contrib/llvm-project/libcxx/include/mdspan @@ -208,6 +208,135 @@ namespace std { }; } +// mdspan synopsis + +namespace std { + template<class ElementType, class Extents, class LayoutPolicy = layout_right, + class AccessorPolicy = default_accessor<ElementType>> + class mdspan { + public: + using extents_type = Extents; + using layout_type = LayoutPolicy; + using accessor_type = AccessorPolicy; + using mapping_type = typename layout_type::template mapping<extents_type>; + using element_type = ElementType; + using value_type = remove_cv_t<element_type>; + using index_type = typename extents_type::index_type; + using size_type = typename extents_type::size_type; + using rank_type = typename extents_type::rank_type; + using data_handle_type = typename accessor_type::data_handle_type; + using reference = typename accessor_type::reference; + + static constexpr rank_type rank() noexcept { return extents_type::rank(); } + static constexpr rank_type rank_dynamic() noexcept { return extents_type::rank_dynamic(); } + static constexpr size_t static_extent(rank_type r) noexcept + { return extents_type::static_extent(r); } + constexpr index_type extent(rank_type r) const noexcept { return extents().extent(r); } + + // [mdspan.mdspan.cons], constructors + constexpr mdspan(); + constexpr mdspan(const mdspan& rhs) = default; + constexpr mdspan(mdspan&& rhs) = default; + + template<class... OtherIndexTypes> + constexpr explicit mdspan(data_handle_type ptr, OtherIndexTypes... exts); + template<class OtherIndexType, size_t N> + constexpr explicit(N != rank_dynamic()) + mdspan(data_handle_type p, span<OtherIndexType, N> exts); + template<class OtherIndexType, size_t N> + constexpr explicit(N != rank_dynamic()) + mdspan(data_handle_type p, const array<OtherIndexType, N>& exts); + constexpr mdspan(data_handle_type p, const extents_type& ext); + constexpr mdspan(data_handle_type p, const mapping_type& m); + constexpr mdspan(data_handle_type p, const mapping_type& m, const accessor_type& a); + + template<class OtherElementType, class OtherExtents, + class OtherLayoutPolicy, class OtherAccessorPolicy> + constexpr explicit(see below) + mdspan(const mdspan<OtherElementType, OtherExtents, + OtherLayoutPolicy, OtherAccessorPolicy>& other); + + constexpr mdspan& operator=(const mdspan& rhs) = default; + constexpr mdspan& operator=(mdspan&& rhs) = default; + + // [mdspan.mdspan.members], members + template<class... OtherIndexTypes> + constexpr reference operator[](OtherIndexTypes... indices) const; + template<class OtherIndexType> + constexpr reference operator[](span<OtherIndexType, rank()> indices) const; + template<class OtherIndexType> + constexpr reference operator[](const array<OtherIndexType, rank()>& indices) const; + + constexpr size_type size() const noexcept; + [[nodiscard]] constexpr bool empty() const noexcept; + + friend constexpr void swap(mdspan& x, mdspan& y) noexcept; + + constexpr const extents_type& extents() const noexcept { return map_.extents(); } + constexpr const data_handle_type& data_handle() const noexcept { return ptr_; } + constexpr const mapping_type& mapping() const noexcept { return map_; } + constexpr const accessor_type& accessor() const noexcept { return acc_; } + + static constexpr bool is_always_unique() + { return mapping_type::is_always_unique(); } + static constexpr bool is_always_exhaustive() + { return mapping_type::is_always_exhaustive(); } + static constexpr bool is_always_strided() + { return mapping_type::is_always_strided(); } + + constexpr bool is_unique() const + { return map_.is_unique(); } + constexpr bool is_exhaustive() const + { return map_.is_exhaustive(); } + constexpr bool is_strided() const + { return map_.is_strided(); } + constexpr index_type stride(rank_type r) const + { return map_.stride(r); } + + private: + accessor_type acc_; // exposition only + mapping_type map_; // exposition only + data_handle_type ptr_; // exposition only + }; + + template<class CArray> + requires(is_array_v<CArray> && rank_v<CArray> == 1) + mdspan(CArray&) + -> mdspan<remove_all_extents_t<CArray>, extents<size_t, extent_v<CArray, 0>>>; + + template<class Pointer> + requires(is_pointer_v<remove_reference_t<Pointer>>) + mdspan(Pointer&&) + -> mdspan<remove_pointer_t<remove_reference_t<Pointer>>, extents<size_t>>; + + template<class ElementType, class... Integrals> + requires((is_convertible_v<Integrals, size_t> && ...) && sizeof...(Integrals) > 0) + explicit mdspan(ElementType*, Integrals...) + -> mdspan<ElementType, dextents<size_t, sizeof...(Integrals)>>; + + template<class ElementType, class OtherIndexType, size_t N> + mdspan(ElementType*, span<OtherIndexType, N>) + -> mdspan<ElementType, dextents<size_t, N>>; + + template<class ElementType, class OtherIndexType, size_t N> + mdspan(ElementType*, const array<OtherIndexType, N>&) + -> mdspan<ElementType, dextents<size_t, N>>; + + template<class ElementType, class IndexType, size_t... ExtentsPack> + mdspan(ElementType*, const extents<IndexType, ExtentsPack...>&) + -> mdspan<ElementType, extents<IndexType, ExtentsPack...>>; + + template<class ElementType, class MappingType> + mdspan(ElementType*, const MappingType&) + -> mdspan<ElementType, typename MappingType::extents_type, + typename MappingType::layout_type>; + + template<class MappingType, class AccessorType> + mdspan(const typename AccessorType::data_handle_type&, const MappingType&, + const AccessorType&) + -> mdspan<typename AccessorType::element_type, typename MappingType::extents_type, + typename MappingType::layout_type, AccessorType>; +} */ #ifndef _LIBCPP_MDSPAN @@ -219,6 +348,7 @@ namespace std { #include <__mdspan/extents.h> #include <__mdspan/layout_left.h> #include <__mdspan/layout_right.h> +#include <__mdspan/mdspan.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/contrib/llvm-project/libcxx/include/module.modulemap.in b/contrib/llvm-project/libcxx/include/module.modulemap.in index 9ff8b67a6a20..37a9edcd7ece 100644 --- a/contrib/llvm-project/libcxx/include/module.modulemap.in +++ b/contrib/llvm-project/libcxx/include/module.modulemap.in @@ -16,7 +16,6 @@ module std_atomic [system] { export * } module std_barrier [system] { - @requires_LIBCXX_ENABLE_THREADS@ header "barrier" export * } @@ -37,7 +36,6 @@ module std_chrono [system] { export * } module std_codecvt [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "codecvt" export * } @@ -78,7 +76,6 @@ module std_expected [system] { export * } module std_filesystem [system] { - @requires_LIBCXX_ENABLE_FILESYSTEM@ header "filesystem" export * } @@ -91,8 +88,6 @@ module std_forward_list [system] { export * } module std_fstream [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ - @requires_LIBCXX_ENABLE_FILESYSTEM@ header "fstream" export * } @@ -101,7 +96,6 @@ module std_functional [system] { export * } module std_future [system] { - @requires_LIBCXX_ENABLE_THREADS@ header "future" export * } @@ -110,12 +104,10 @@ module std_initializer_list [system] { export * } module std_iomanip [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "iomanip" export * } module std_ios [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "ios" export * } @@ -124,12 +116,10 @@ module std_iosfwd [system] { export * } module std_iostream [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "iostream" export * } module std_istream [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "istream" export * } @@ -138,7 +128,6 @@ module std_iterator [system] { export * } module std_latch [system] { - @requires_LIBCXX_ENABLE_THREADS@ header "latch" export * } @@ -151,7 +140,6 @@ module std_list [system] { export * } module std_locale [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "locale" export * } @@ -192,7 +180,6 @@ module std_optional [system] { export * } module std_ostream [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "ostream" export * } @@ -217,7 +204,6 @@ module std_ratio [system] { export * } module std_regex [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "regex" export * } @@ -226,7 +212,6 @@ module std_scoped_allocator [system] { export * } module std_semaphore [system] { - @requires_LIBCXX_ENABLE_THREADS@ header "semaphore" export * } @@ -235,7 +220,6 @@ module std_set [system] { export * } module std_shared_mutex [system] { - @requires_LIBCXX_ENABLE_THREADS@ header "shared_mutex" export std_version } @@ -250,7 +234,6 @@ module std_span [system] { export std_private_span_span_fwd } module std_sstream [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "sstream" export * } @@ -263,12 +246,10 @@ module std_stdexcept [system] { export * } module std_stop_token { - @requires_LIBCXX_ENABLE_THREADS@ header "stop_token" export * } module std_streambuf [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "streambuf" export * } @@ -281,7 +262,6 @@ module std_string_view [system] { export * } module std_strstream [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "strstream" export * } @@ -290,7 +270,6 @@ module std_system_error [system] { export * } module std_thread [system] { - @requires_LIBCXX_ENABLE_THREADS@ header "thread" export * } @@ -377,7 +356,6 @@ module std_climits [system] { export * } module std_clocale [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "clocale" export * } @@ -435,12 +413,10 @@ module std_cuchar [system] { export * } module std_cwchar [system] { - @requires_LIBCXX_ENABLE_WIDE_CHARACTERS@ header "cwchar" export * } module std_cwctype [system] { - @requires_LIBCXX_ENABLE_WIDE_CHARACTERS@ header "cwctype" export * } @@ -477,7 +453,6 @@ module std_limits_h [system] { export * } module std_locale_h [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "locale.h" export * } @@ -493,8 +468,6 @@ module std_setjmp_h [system] { // FIXME: <stdalign.h> is missing. // <stdarg.h> provided by compiler. module std_stdatomic_h [system] { - @requires_LIBCXX_ENABLE_THREADS@ - requires cplusplus23 header "stdatomic.h" export * } @@ -536,21 +509,17 @@ module std_uchar_h [system] { } // <time.h> provided by C library. module std_wchar_h [system] { - @requires_LIBCXX_ENABLE_WIDE_CHARACTERS@ // <wchar.h>'s __need_* macros require textual inclusion. textual header "wchar.h" export * } module std_wctype_h [system] { - @requires_LIBCXX_ENABLE_WIDE_CHARACTERS@ header "wctype.h" export * } // Experimental C++ standard library interfaces module std_experimental [system] { - requires cplusplus11 - module deque { header "experimental/deque" export * @@ -627,6 +596,13 @@ module std_experimental [system] { } } +// Convenience method to get all of the above modules in a single import statement. +// Importing only the needed modules is likely to be more performant. +module std [system] { + header "__std_clang_module" + export * +} + // Implementation detail headers that are private to libc++. These modules // must not be directly imported. module std_private_assert [system] { @@ -650,7 +626,6 @@ module std_private_hash_table [system] { export * } module std_private_locale [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "__locale" export * } @@ -819,6 +794,7 @@ module std_private_algorithm_pstl_generate [system module std_private_algorithm_pstl_is_partitioned [system] { header "__algorithm/pstl_is_partitioned.h" } module std_private_algorithm_pstl_merge [system] { header "__algorithm/pstl_merge.h" } module std_private_algorithm_pstl_replace [system] { header "__algorithm/pstl_replace.h" } +module std_private_algorithm_pstl_sort [system] { header "__algorithm/pstl_sort.h" } module std_private_algorithm_pstl_stable_sort [system] { header "__algorithm/pstl_stable_sort.h" export std_private_functional_operations @@ -1188,7 +1164,6 @@ module std_private_chrono_duration [system] { } module std_private_chrono_file_clock [system] { header "__chrono/file_clock.h" } module std_private_chrono_formatter [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "__chrono/formatter.h" } module std_private_chrono_hh_mm_ss [system] { header "__chrono/hh_mm_ss.h" } @@ -1202,11 +1177,9 @@ module std_private_chrono_month [system] { header "__chrono/mon module std_private_chrono_month_weekday [system] { header "__chrono/month_weekday.h" } module std_private_chrono_monthday [system] { header "__chrono/monthday.h" } module std_private_chrono_ostream [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "__chrono/ostream.h" } module std_private_chrono_parser_std_format_spec [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "__chrono/parser_std_format_spec.h" } module std_private_chrono_statically_widen [system] { header "__chrono/statically_widen.h" } @@ -1516,6 +1489,7 @@ module std_private_mdspan_extents [system] { } module std_private_mdspan_layout_left [system] { header "__mdspan/layout_left.h" } module std_private_mdspan_layout_right [system] { header "__mdspan/layout_right.h" } +module std_private_mdspan_mdspan [system] { header "__mdspan/mdspan.h" } module std_private_mdspan_mdspan_fwd [system] { header "__fwd/mdspan.h" } module std_private_memory_addressof [system] { header "__memory/addressof.h" } @@ -1529,7 +1503,10 @@ module std_private_memory_allocator_destructor [system] { header "__m module std_private_memory_allocator_traits [system] { header "__memory/allocator_traits.h" } module std_private_memory_assume_aligned [system] { header "__memory/assume_aligned.h" } module std_private_memory_auto_ptr [system] { header "__memory/auto_ptr.h" } -module std_private_memory_builtin_new_allocator [system] { header "__memory/builtin_new_allocator.h" } +module std_private_memory_builtin_new_allocator [system] { + header "__memory/builtin_new_allocator.h" + export * +} module std_private_memory_compressed_pair [system] { header "__memory/compressed_pair.h" } module std_private_memory_concepts [system] { header "__memory/concepts.h" @@ -1636,9 +1613,15 @@ module std_private_random_piecewise_linear_distribution [system] { export * } module std_private_random_poisson_distribution [system] { header "__random/poisson_distribution.h" } -module std_private_random_random_device [system] { header "__random/random_device.h" } +module std_private_random_random_device [system] { + header "__random/random_device.h" + export * +} module std_private_random_ranlux [system] { header "__random/ranlux.h" } -module std_private_random_seed_seq [system] { header "__random/seed_seq.h" } +module std_private_random_seed_seq [system] { + header "__random/seed_seq.h" + export * +} module std_private_random_shuffle_order_engine [system] { header "__random/shuffle_order_engine.h" } module std_private_random_student_t_distribution [system] { header "__random/student_t_distribution.h" } module std_private_random_subtract_with_carry_engine [system] { header "__random/subtract_with_carry_engine.h" } @@ -1681,7 +1664,6 @@ module std_private_ranges_filter_view [system] { module std_private_ranges_from_range [system] { header "__ranges/from_range.h" } module std_private_ranges_iota_view [system] { header "__ranges/iota_view.h" } module std_private_ranges_istream_view [system] { - @requires_LIBCXX_ENABLE_LOCALIZATION@ header "__ranges/istream_view.h" } module std_private_ranges_join_view [system] { @@ -1748,7 +1730,10 @@ module std_private_stop_token_stop_token [system] { export * } -module std_private_string_char_traits [system] { header "__string/char_traits.h" } +module std_private_string_char_traits [system] { + header "__string/char_traits.h" + export * +} module std_private_string_constexpr_c_functions [system] { header "__string/constexpr_c_functions.h" export std_private_type_traits_is_equality_comparable diff --git a/contrib/llvm-project/libcxx/include/sstream b/contrib/llvm-project/libcxx/include/sstream index d7ad0213eb34..40930df24c6d 100644 --- a/contrib/llvm-project/libcxx/include/sstream +++ b/contrib/llvm-project/libcxx/include/sstream @@ -399,8 +399,12 @@ public: _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return str(__str_.get_allocator()); } _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { + string_type __result; const basic_string_view<_CharT, _Traits> __view = view(); - string_type __result(std::move(__str_), __view.data() - __str_.data(), __view.size()); + if (!__view.empty()) { + auto __pos = __view.data() - __str_.data(); + __result.assign(std::move(__str_), __pos, __view.size()); + } __str_.clear(); __init_buf_ptrs(); return __result; @@ -415,7 +419,7 @@ public: } _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept; -#endif +#endif // _LIBCPP_STD_VER >= 20 void str(const string_type& __s) { __str_ = __s; @@ -900,20 +904,22 @@ public: return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); } -#if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); } +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) + _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } +#else + _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return __sb_.str(); } + _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { return std::move(__sb_).str(); } +#endif + +#if _LIBCPP_STD_VER >= 20 template <class _SAlloc> requires __is_allocator<_SAlloc>::value _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { return __sb_.str(__sa); } - _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } - _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } -#else // _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } #endif // _LIBCPP_STD_VER >= 20 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } @@ -1023,20 +1029,22 @@ public: return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); } -#if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); } +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) + _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } +#else + _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return __sb_.str(); } + + _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { return std::move(__sb_).str(); } +#endif +#if _LIBCPP_STD_VER >= 20 template <class _SAlloc> requires __is_allocator<_SAlloc>::value _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { return __sb_.str(__sa); } - _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } - _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } -#else // _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } #endif // _LIBCPP_STD_VER >= 20 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } @@ -1145,20 +1153,22 @@ public: return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); } -#if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); } +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) + _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } +#else + _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return __sb_.str(); } + + _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { return std::move(__sb_).str(); } +#endif +#if _LIBCPP_STD_VER >= 20 template <class _SAlloc> requires __is_allocator<_SAlloc>::value _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { return __sb_.str(__sa); } - _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } - _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } -#else // _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } #endif // _LIBCPP_STD_VER >= 20 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } |