diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt index fb2b5be63510..1e5299f00c2e 100644 --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -99,6 +99,7 @@ set(files __algorithm/unique_copy.h __algorithm/unwrap_iter.h __algorithm/upper_bound.h + __assert __availability __bit/bit_cast.h __bit/byteswap.h diff --git a/libcxx/include/__algorithm/clamp.h b/libcxx/include/__algorithm/clamp.h index bfc96f81c331..b3762b85a0bc 100644 --- a/libcxx/include/__algorithm/clamp.h +++ b/libcxx/include/__algorithm/clamp.h @@ -10,8 +10,8 @@ #define _LIBCPP___ALGORITHM_CLAMP_H #include <__algorithm/comp.h> +#include <__assert> #include <__config> -#include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/libcxx/include/__algorithm/comp_ref_type.h b/libcxx/include/__algorithm/comp_ref_type.h index 79dda0afb29c..ed0ed5904a44 100644 --- a/libcxx/include/__algorithm/comp_ref_type.h +++ b/libcxx/include/__algorithm/comp_ref_type.h @@ -9,6 +9,7 @@ #ifndef _LIBCPP___ALGORITHM_COMP_REF_TYPE_H #define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H +#include <__assert> #include <__config> #include <__debug> #include <__utility/declval.h> diff --git a/libcxx/include/__algorithm/sample.h b/libcxx/include/__algorithm/sample.h index 0bf4fd5b9723..523496108217 100644 --- a/libcxx/include/__algorithm/sample.h +++ b/libcxx/include/__algorithm/sample.h @@ -10,8 +10,8 @@ #define _LIBCPP___ALGORITHM_SAMPLE_H #include <__algorithm/min.h> +#include <__assert> #include <__config> -#include <__debug> #include <__random/uniform_int_distribution.h> #include diff --git a/libcxx/include/__assert b/libcxx/include/__assert new file mode 100644 index 000000000000..d51512dcf379 --- /dev/null +++ b/libcxx/include/__assert @@ -0,0 +1,69 @@ +// -*- 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___ASSERT +#define _LIBCPP___ASSERT + +#include <__config> +#include // for std::string + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_DEBUG_LEVEL >= 1 +# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : ::std::__libcpp_debug_function(::std::__libcpp_debug_info(__FILE__, __LINE__, #x, m))) +#else +# define _LIBCPP_ASSERT_IMPL(x, m) ((void)0) +#endif + +// We do this dance because some of our tests re-define _LIBCPP_ASSERT to something else. +// In the future, we should find other ways to test our assertions and disallow re-defining +// _LIBCPP_ASSERT. +#if !defined(_LIBCPP_ASSERT) +# define _LIBCPP_ASSERT(x, m) _LIBCPP_ASSERT_IMPL(x, m) +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __libcpp_debug_info() + : __file_(nullptr), __line_(-1), __pred_(nullptr), __msg_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m) + : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {} + + _LIBCPP_FUNC_VIS string what() const; + + const char* __file_; + int __line_; + const char* __pred_; + const char* __msg_; +}; + +/// __libcpp_debug_function_type - The type of the assertion failure handler. +typedef void(*__libcpp_debug_function_type)(__libcpp_debug_info const&); + +/// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT +/// fails. +extern _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_function_type __libcpp_debug_function; + +/// __libcpp_abort_debug_function - A debug handler that aborts when called. +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS +void __libcpp_abort_debug_function(__libcpp_debug_info const&); + +/// __libcpp_set_debug_function - Set the debug handler to the specified +/// function. +_LIBCPP_FUNC_VIS +bool __libcpp_set_debug_function(__libcpp_debug_function_type __func); + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___ASSERT diff --git a/libcxx/include/__coroutine/coroutine_handle.h b/libcxx/include/__coroutine/coroutine_handle.h index ad399c86f8b7..4bf323789217 100644 --- a/libcxx/include/__coroutine/coroutine_handle.h +++ b/libcxx/include/__coroutine/coroutine_handle.h @@ -9,8 +9,8 @@ #ifndef _LIBCPP___COROUTINE_COROUTINE_HANDLE_H #define _LIBCPP___COROUTINE_COROUTINE_HANDLE_H +#include <__assert> #include <__config> -#include <__debug> #include <__functional/hash.h> #include <__memory/addressof.h> #include diff --git a/libcxx/include/__debug b/libcxx/include/__debug index 5d0b5bf57f4e..207591cd4058 100644 --- a/libcxx/include/__debug +++ b/libcxx/include/__debug @@ -10,6 +10,7 @@ #ifndef _LIBCPP_DEBUG_H #define _LIBCPP_DEBUG_H +#include <__assert> #include <__config> #include #include @@ -24,57 +25,16 @@ # include #endif -#if _LIBCPP_DEBUG_LEVEL == 0 +#if _LIBCPP_DEBUG_LEVEL == 0 || _LIBCPP_DEBUG_LEVEL == 1 # define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0) -# define _LIBCPP_ASSERT_IMPL(x, m) ((void)0) -#elif _LIBCPP_DEBUG_LEVEL == 1 -# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0) -# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : ::std::__libcpp_debug_function(::std::__libcpp_debug_info(__FILE__, __LINE__, #x, m))) #elif _LIBCPP_DEBUG_LEVEL == 2 # define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(::std::__libcpp_is_constant_evaluated() || (x), m) -# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : ::std::__libcpp_debug_function(::std::__libcpp_debug_info(__FILE__, __LINE__, #x, m))) #else # error _LIBCPP_DEBUG_LEVEL must be one of 0, 1, 2 #endif -#if !defined(_LIBCPP_ASSERT) -# define _LIBCPP_ASSERT(x, m) _LIBCPP_ASSERT_IMPL(x, m) -#endif - _LIBCPP_BEGIN_NAMESPACE_STD -struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info { - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - __libcpp_debug_info() - : __file_(nullptr), __line_(-1), __pred_(nullptr), __msg_(nullptr) {} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m) - : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {} - - _LIBCPP_FUNC_VIS string what() const; - - const char* __file_; - int __line_; - const char* __pred_; - const char* __msg_; -}; - -/// __libcpp_debug_function_type - The type of the assertion failure handler. -typedef void(*__libcpp_debug_function_type)(__libcpp_debug_info const&); - -/// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT -/// fails. -extern _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_function_type __libcpp_debug_function; - -/// __libcpp_abort_debug_function - A debug handler that aborts when called. -_LIBCPP_NORETURN _LIBCPP_FUNC_VIS -void __libcpp_abort_debug_function(__libcpp_debug_info const&); - -/// __libcpp_set_debug_function - Set the debug handler to the specified -/// function. -_LIBCPP_FUNC_VIS -bool __libcpp_set_debug_function(__libcpp_debug_function_type __func); - #if _LIBCPP_DEBUG_LEVEL == 2 || defined(_LIBCPP_BUILDING_LIBRARY) struct _LIBCPP_TYPE_VIS __c_node; diff --git a/libcxx/include/__filesystem/directory_iterator.h b/libcxx/include/__filesystem/directory_iterator.h index 4d45077b4ff3..87bbbfac717b 100644 --- a/libcxx/include/__filesystem/directory_iterator.h +++ b/libcxx/include/__filesystem/directory_iterator.h @@ -10,9 +10,9 @@ #ifndef _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H #define _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H +#include <__assert> #include <__availability> #include <__config> -#include <__debug> #include <__filesystem/directory_entry.h> #include <__filesystem/directory_options.h> #include <__filesystem/path.h> diff --git a/libcxx/include/__filesystem/path_iterator.h b/libcxx/include/__filesystem/path_iterator.h index 0dfb04d56265..6f2baf8f7a29 100644 --- a/libcxx/include/__filesystem/path_iterator.h +++ b/libcxx/include/__filesystem/path_iterator.h @@ -10,9 +10,9 @@ #ifndef _LIBCPP___FILESYSTEM_PATH_ITERATOR_H #define _LIBCPP___FILESYSTEM_PATH_ITERATOR_H +#include <__assert> #include <__availability> #include <__config> -#include <__debug> #include <__filesystem/path.h> #include <__iterator/iterator_traits.h> #include diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h index 8db42cdb9801..5e1565bf1595 100644 --- a/libcxx/include/__format/format_arg.h +++ b/libcxx/include/__format/format_arg.h @@ -10,6 +10,7 @@ #ifndef _LIBCPP___FORMAT_FORMAT_ARG_H #define _LIBCPP___FORMAT_FORMAT_ARG_H +#include <__assert> #include <__concepts/arithmetic.h> #include <__config> #include <__format/format_error.h> diff --git a/libcxx/include/__format/format_string.h b/libcxx/include/__format/format_string.h index 10fb471c35dc..32af6609e7b7 100644 --- a/libcxx/include/__format/format_string.h +++ b/libcxx/include/__format/format_string.h @@ -10,8 +10,8 @@ #ifndef _LIBCPP___FORMAT_FORMAT_STRING_H #define _LIBCPP___FORMAT_FORMAT_STRING_H +#include <__assert> #include <__config> -#include <__debug> #include <__format/format_error.h> #include #include diff --git a/libcxx/include/__format/formatter.h b/libcxx/include/__format/formatter.h index 7e1ae314b595..f9e0b6c84b7b 100644 --- a/libcxx/include/__format/formatter.h +++ b/libcxx/include/__format/formatter.h @@ -13,6 +13,7 @@ #include <__algorithm/copy.h> #include <__algorithm/fill_n.h> #include <__algorithm/transform.h> +#include <__assert> #include <__availability> #include <__config> #include <__format/format_error.h> diff --git a/libcxx/include/__format/formatter_floating_point.h b/libcxx/include/__format/formatter_floating_point.h index c29cda48a98e..aa32815af2a4 100644 --- a/libcxx/include/__format/formatter_floating_point.h +++ b/libcxx/include/__format/formatter_floating_point.h @@ -17,9 +17,9 @@ #include <__algorithm/min.h> #include <__algorithm/rotate.h> #include <__algorithm/transform.h> +#include <__assert> #include <__concepts/arithmetic.h> #include <__config> -#include <__debug> #include <__format/format_error.h> #include <__format/format_fwd.h> #include <__format/format_string.h> diff --git a/libcxx/include/__format/formatter_integral.h b/libcxx/include/__format/formatter_integral.h index 4f82b34462db..836082671c5a 100644 --- a/libcxx/include/__format/formatter_integral.h +++ b/libcxx/include/__format/formatter_integral.h @@ -14,6 +14,7 @@ #include <__algorithm/copy_n.h> #include <__algorithm/fill_n.h> #include <__algorithm/transform.h> +#include <__assert> #include <__config> #include <__format/format_error.h> #include <__format/format_fwd.h> diff --git a/libcxx/include/__format/formatter_pointer.h b/libcxx/include/__format/formatter_pointer.h index 15b6764000a0..83d21e1c50e6 100644 --- a/libcxx/include/__format/formatter_pointer.h +++ b/libcxx/include/__format/formatter_pointer.h @@ -11,9 +11,9 @@ #define _LIBCPP___FORMAT_FORMATTER_POINTER_H #include <__algorithm/copy.h> +#include <__assert> #include <__availability> #include <__config> -#include <__debug> #include <__format/format_error.h> #include <__format/format_fwd.h> #include <__format/formatter.h> diff --git a/libcxx/include/__format/formatter_string.h b/libcxx/include/__format/formatter_string.h index 01e2bafda4ed..54aa1215d99e 100644 --- a/libcxx/include/__format/formatter_string.h +++ b/libcxx/include/__format/formatter_string.h @@ -10,6 +10,7 @@ #ifndef _LIBCPP___FORMAT_FORMATTER_STRING_H #define _LIBCPP___FORMAT_FORMATTER_STRING_H +#include <__assert> #include <__config> #include <__format/format_error.h> #include <__format/format_fwd.h> diff --git a/libcxx/include/__format/parser_std_format_spec.h b/libcxx/include/__format/parser_std_format_spec.h index ca4eae1fa918..57f4e46e561b 100644 --- a/libcxx/include/__format/parser_std_format_spec.h +++ b/libcxx/include/__format/parser_std_format_spec.h @@ -12,8 +12,8 @@ #include <__algorithm/find_if.h> #include <__algorithm/min.h> +#include <__assert> #include <__config> -#include <__debug> #include <__format/format_arg.h> #include <__format/format_error.h> #include <__format/format_string.h> diff --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h index 170987693d5f..4698c8c2d42e 100644 --- a/libcxx/include/__functional/function.h +++ b/libcxx/include/__functional/function.h @@ -10,8 +10,8 @@ #ifndef _LIBCPP___FUNCTIONAL_FUNCTION_H #define _LIBCPP___FUNCTIONAL_FUNCTION_H +#include <__assert> #include <__config> -#include <__debug> #include <__functional/binary_function.h> #include <__functional/invoke.h> #include <__functional/unary_function.h> diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table index 6b1f65c28328..43c15d59a193 100644 --- a/libcxx/include/__hash_table +++ b/libcxx/include/__hash_table @@ -12,6 +12,7 @@ #include <__algorithm/max.h> #include <__algorithm/min.h> +#include <__assert> #include <__bits> // __libcpp_clz #include <__config> #include <__debug> diff --git a/libcxx/include/__iterator/advance.h b/libcxx/include/__iterator/advance.h index 7b07951ef6bc..da6bf052525c 100644 --- a/libcxx/include/__iterator/advance.h +++ b/libcxx/include/__iterator/advance.h @@ -10,8 +10,8 @@ #ifndef _LIBCPP___ITERATOR_ADVANCE_H #define _LIBCPP___ITERATOR_ADVANCE_H +#include <__assert> #include <__config> -#include <__debug> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> #include <__iterator/iterator_traits.h> diff --git a/libcxx/include/__iterator/common_iterator.h b/libcxx/include/__iterator/common_iterator.h index ad74dbd3df56..505e4f1f3f0d 100644 --- a/libcxx/include/__iterator/common_iterator.h +++ b/libcxx/include/__iterator/common_iterator.h @@ -10,8 +10,8 @@ #ifndef _LIBCPP___ITERATOR_COMMON_ITERATOR_H #define _LIBCPP___ITERATOR_COMMON_ITERATOR_H +#include <__assert> #include <__config> -#include <__debug> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> #include <__iterator/iter_move.h> diff --git a/libcxx/include/__iterator/counted_iterator.h b/libcxx/include/__iterator/counted_iterator.h index c67743fbe37f..826d5de51f97 100644 --- a/libcxx/include/__iterator/counted_iterator.h +++ b/libcxx/include/__iterator/counted_iterator.h @@ -9,8 +9,8 @@ #ifndef _LIBCPP___ITERATOR_COUNTED_ITERATOR_H #define _LIBCPP___ITERATOR_COUNTED_ITERATOR_H +#include <__assert> #include <__config> -#include <__debug> #include <__iterator/concepts.h> #include <__iterator/default_sentinel.h> #include <__iterator/incrementable_traits.h> diff --git a/libcxx/include/__iterator/next.h b/libcxx/include/__iterator/next.h index 9f104bc7af56..fae5989c2aaf 100644 --- a/libcxx/include/__iterator/next.h +++ b/libcxx/include/__iterator/next.h @@ -10,8 +10,8 @@ #ifndef _LIBCPP___ITERATOR_NEXT_H #define _LIBCPP___ITERATOR_NEXT_H +#include <__assert> #include <__config> -#include <__debug> #include <__iterator/advance.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> diff --git a/libcxx/include/__iterator/prev.h b/libcxx/include/__iterator/prev.h index 9779a8d2aadb..5839621eefe1 100644 --- a/libcxx/include/__iterator/prev.h +++ b/libcxx/include/__iterator/prev.h @@ -10,8 +10,8 @@ #ifndef _LIBCPP___ITERATOR_PREV_H #define _LIBCPP___ITERATOR_PREV_H +#include <__assert> #include <__config> -#include <__debug> #include <__iterator/advance.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> diff --git a/libcxx/include/__memory/construct_at.h b/libcxx/include/__memory/construct_at.h index d0328f890576..8a7bf40d7f71 100644 --- a/libcxx/include/__memory/construct_at.h +++ b/libcxx/include/__memory/construct_at.h @@ -10,8 +10,8 @@ #ifndef _LIBCPP___MEMORY_CONSTRUCT_AT_H #define _LIBCPP___MEMORY_CONSTRUCT_AT_H +#include <__assert> #include <__config> -#include <__debug> #include <__iterator/access.h> #include <__memory/addressof.h> #include <__memory/voidify.h> diff --git a/libcxx/include/__node_handle b/libcxx/include/__node_handle index fc35d0ff0b4f..71309be62f3c 100644 --- a/libcxx/include/__node_handle +++ b/libcxx/include/__node_handle @@ -58,8 +58,8 @@ public: */ +#include <__assert> #include <__config> -#include <__debug> #include #include diff --git a/libcxx/include/__numeric/gcd_lcm.h b/libcxx/include/__numeric/gcd_lcm.h index 34c0e533c928..9a53a001f211 100644 --- a/libcxx/include/__numeric/gcd_lcm.h +++ b/libcxx/include/__numeric/gcd_lcm.h @@ -10,8 +10,8 @@ #ifndef _LIBCPP___NUMERIC_GCD_LCM_H #define _LIBCPP___NUMERIC_GCD_LCM_H +#include <__assert> #include <__config> -#include <__debug> #include #include diff --git a/libcxx/include/__ranges/drop_view.h b/libcxx/include/__ranges/drop_view.h index 3fdf577eb322..079a74d4b84c 100644 --- a/libcxx/include/__ranges/drop_view.h +++ b/libcxx/include/__ranges/drop_view.h @@ -9,8 +9,8 @@ #ifndef _LIBCPP___RANGES_DROP_VIEW_H #define _LIBCPP___RANGES_DROP_VIEW_H +#include <__assert> #include <__config> -#include <__debug> #include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> #include <__iterator/next.h> diff --git a/libcxx/include/__ranges/iota_view.h b/libcxx/include/__ranges/iota_view.h index 389034e92b12..b7c099e04900 100644 --- a/libcxx/include/__ranges/iota_view.h +++ b/libcxx/include/__ranges/iota_view.h @@ -9,6 +9,7 @@ #ifndef _LIBCPP___RANGES_IOTA_VIEW_H #define _LIBCPP___RANGES_IOTA_VIEW_H +#include <__assert> #include <__compare/three_way_comparable.h> #include <__concepts/arithmetic.h> #include <__concepts/constructible.h> @@ -20,7 +21,6 @@ #include <__concepts/semiregular.h> #include <__concepts/totally_ordered.h> #include <__config> -#include <__debug> #include <__functional/ranges_operations.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> diff --git a/libcxx/include/__ranges/subrange.h b/libcxx/include/__ranges/subrange.h index 57f046166ef9..c54f7710fce6 100644 --- a/libcxx/include/__ranges/subrange.h +++ b/libcxx/include/__ranges/subrange.h @@ -9,13 +9,13 @@ #ifndef _LIBCPP___RANGES_SUBRANGE_H #define _LIBCPP___RANGES_SUBRANGE_H +#include <__assert> #include <__concepts/constructible.h> #include <__concepts/convertible_to.h> #include <__concepts/copyable.h> #include <__concepts/derived_from.h> #include <__concepts/different_from.h> #include <__config> -#include <__debug> #include <__iterator/advance.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> diff --git a/libcxx/include/__ranges/view_interface.h b/libcxx/include/__ranges/view_interface.h index b0794b02b963..eecc47511139 100644 --- a/libcxx/include/__ranges/view_interface.h +++ b/libcxx/include/__ranges/view_interface.h @@ -9,10 +9,10 @@ #ifndef _LIBCPP___RANGES_VIEW_INTERFACE_H #define _LIBCPP___RANGES_VIEW_INTERFACE_H +#include <__assert> #include <__concepts/derived_from.h> #include <__concepts/same_as.h> #include <__config> -#include <__debug> #include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> #include <__iterator/prev.h> diff --git a/libcxx/include/__string b/libcxx/include/__string index 60a67d4840cd..26aa619f2106 100644 --- a/libcxx/include/__string +++ b/libcxx/include/__string @@ -17,7 +17,9 @@ #include <__algorithm/find_end.h> #include <__algorithm/find_first_of.h> #include <__algorithm/min.h> +#include <__assert> #include <__config> +#include <__debug> #include <__functional/hash.h> // for __murmur2_or_cityhash #include <__iterator/iterator_traits.h> #include // for uint_least16_t @@ -30,8 +32,6 @@ # include // for wmemcpy #endif -#include <__debug> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif diff --git a/libcxx/include/array b/libcxx/include/array index e55ee4399567..314d24935a43 100644 --- a/libcxx/include/array +++ b/libcxx/include/array @@ -112,8 +112,8 @@ template const T&& get(const array&&) noexce #include <__algorithm/fill_n.h> #include <__algorithm/lexicographical_compare.h> #include <__algorithm/swap_ranges.h> +#include <__assert> #include <__config> -#include <__debug> #include <__tuple> #include <__utility/unreachable.h> #include diff --git a/libcxx/include/bit b/libcxx/include/bit index 16c7987d0f9f..7f9318ecde1e 100644 --- a/libcxx/include/bit +++ b/libcxx/include/bit @@ -61,11 +61,11 @@ namespace std { */ +#include <__assert> #include <__bit/bit_cast.h> #include <__bit/byteswap.h> #include <__bits> // __libcpp_clz #include <__config> -#include <__debug> #include #include #include diff --git a/libcxx/include/charconv b/libcxx/include/charconv index 8a953b049c9e..86cbbd8c9a56 100644 --- a/libcxx/include/charconv +++ b/libcxx/include/charconv @@ -77,6 +77,7 @@ namespace std { */ +#include <__assert> #include <__availability> #include <__bits> #include <__charconv/chars_format.h> diff --git a/libcxx/include/deque b/libcxx/include/deque index fc9647516a22..b0fd1487f379 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -169,8 +169,8 @@ template #include <__algorithm/remove.h> #include <__algorithm/remove_if.h> #include <__algorithm/unwrap_iter.h> +#include <__assert> #include <__config> -#include <__debug> #include <__iterator/iterator_traits.h> #include <__split_buffer> #include <__utility/forward.h> diff --git a/libcxx/include/experimental/coroutine b/libcxx/include/experimental/coroutine index d14bd26401fd..5a3a095ad104 100644 --- a/libcxx/include/experimental/coroutine +++ b/libcxx/include/experimental/coroutine @@ -45,7 +45,7 @@ template struct hash>; */ -#include <__debug> +#include <__assert> #include #include #include diff --git a/libcxx/include/experimental/memory_resource b/libcxx/include/experimental/memory_resource index da3e1033eb1e..098e25f1261f 100644 --- a/libcxx/include/experimental/memory_resource +++ b/libcxx/include/experimental/memory_resource @@ -64,7 +64,7 @@ namespace pmr { */ -#include <__debug> +#include <__assert> #include <__tuple> #include #include diff --git a/libcxx/include/fstream b/libcxx/include/fstream index d7d8fb1ce9c4..80bda63755c6 100644 --- a/libcxx/include/fstream +++ b/libcxx/include/fstream @@ -180,9 +180,9 @@ typedef basic_fstream wfstream; */ #include <__algorithm/max.h> +#include <__assert> #include <__availability> #include <__config> -#include <__debug> #include <__locale> #include <__utility/unreachable.h> #include diff --git a/libcxx/include/future b/libcxx/include/future index d49bc809783b..00f5a68ac6b6 100644 --- a/libcxx/include/future +++ b/libcxx/include/future @@ -361,9 +361,9 @@ template struct uses_allocator, Alloc>; */ +#include <__assert> #include <__availability> #include <__config> -#include <__debug> #include <__memory/allocator_arg_t.h> #include <__memory/uses_allocator.h> #include <__utility/auto_cast.h> diff --git a/libcxx/include/list b/libcxx/include/list index c643cb53dba1..ac2e466e95c2 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -184,6 +184,7 @@ template #include <__algorithm/equal.h> #include <__algorithm/lexicographical_compare.h> #include <__algorithm/min.h> +#include <__assert> #include <__config> #include <__debug> #include <__utility/forward.h> diff --git a/libcxx/include/locale b/libcxx/include/locale index fa82d4413073..fd605e320a68 100644 --- a/libcxx/include/locale +++ b/libcxx/include/locale @@ -192,6 +192,7 @@ template class messages_byname; #include <__algorithm/max.h> #include <__algorithm/reverse.h> #include <__algorithm/unwrap_iter.h> +#include <__assert> #include <__config> #include <__debug> #include <__locale> diff --git a/libcxx/include/map b/libcxx/include/map index a68c6d1c5d34..551edc58cc22 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -530,8 +530,8 @@ erase_if(multimap& c, Predicate pred); // C++20 #include <__algorithm/equal.h> #include <__algorithm/lexicographical_compare.h> +#include <__assert> #include <__config> -#include <__debug> #include <__functional/is_transparent.h> #include <__iterator/iterator_traits.h> #include <__node_handle> diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap index 95ff1ecddd69..a44493968db7 100644 --- a/libcxx/include/module.modulemap +++ b/libcxx/include/module.modulemap @@ -989,6 +989,7 @@ module std [system] { // __config not modularised due to a bug in Clang // FIXME: These should be private. + module __assert { header "__assert" export * } module __availability { private header "__availability" export * } module __bit_reference { private header "__bit_reference" export * } module __bits { private header "__bits" export * } diff --git a/libcxx/include/optional b/libcxx/include/optional index aa299f7b2d09..b20081d0e1b9 100644 --- a/libcxx/include/optional +++ b/libcxx/include/optional @@ -158,10 +158,10 @@ template */ +#include <__assert> #include <__availability> #include <__concepts/invocable.h> #include <__config> -#include <__debug> #include #include #include diff --git a/libcxx/include/regex b/libcxx/include/regex index dadd7b9dce72..68922f66e4c2 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -763,8 +763,8 @@ typedef regex_token_iterator wsregex_token_iterator; */ #include <__algorithm/find.h> +#include <__assert> #include <__config> -#include <__debug> #include <__iterator/wrap_iter.h> #include <__locale> #include diff --git a/libcxx/include/set b/libcxx/include/set index b346e5707d6e..be117d0b8fa8 100644 --- a/libcxx/include/set +++ b/libcxx/include/set @@ -473,8 +473,8 @@ erase_if(multiset& c, Predicate pred); // C++20 #include <__algorithm/equal.h> #include <__algorithm/lexicographical_compare.h> +#include <__assert> #include <__config> -#include <__debug> #include <__functional/is_transparent.h> #include <__iterator/iterator_traits.h> #include <__node_handle> diff --git a/libcxx/include/span b/libcxx/include/span index 66897406898f..46df783550b2 100644 --- a/libcxx/include/span +++ b/libcxx/include/span @@ -127,6 +127,7 @@ template */ +#include <__assert> #include <__config> #include <__debug> #include <__iterator/concepts.h> diff --git a/libcxx/include/string b/libcxx/include/string index 3e7f2e9fe6aa..892df770756e 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -522,6 +522,7 @@ basic_string operator "" s( const char32_t *str, size_t len ); // C++1 #include <__algorithm/min.h> #include <__algorithm/remove.h> #include <__algorithm/remove_if.h> +#include <__assert> #include <__config> #include <__debug> #include <__ios/fpos.h> diff --git a/libcxx/include/string_view b/libcxx/include/string_view index a5256fb4dc54..dd9239aaff65 100644 --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -196,8 +196,8 @@ namespace std { */ #include <__algorithm/min.h> +#include <__assert> #include <__config> -#include <__debug> #include <__ranges/concepts.h> #include <__ranges/data.h> #include <__ranges/enable_borrowed_range.h> diff --git a/libcxx/include/thread b/libcxx/include/thread index 5681f9d97386..5aa698e1e136 100644 --- a/libcxx/include/thread +++ b/libcxx/include/thread @@ -82,8 +82,8 @@ void sleep_for(const chrono::duration& rel_time); */ +#include <__assert> #include <__config> -#include <__debug> #include <__mutex_base> #include <__thread/poll_with_backoff.h> #include <__thread/timed_backoff_policy.h> diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map index 34c3d184a608..c8545489507f 100644 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -515,6 +515,7 @@ template */ #include <__algorithm/is_permutation.h> +#include <__assert> #include <__config> #include <__debug> #include <__functional/is_transparent.h> diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set index bf972be44ed8..2f902cc79341 100644 --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -460,6 +460,7 @@ template */ #include <__algorithm/is_permutation.h> +#include <__assert> #include <__config> #include <__debug> #include <__functional/is_transparent.h> diff --git a/libcxx/include/vector b/libcxx/include/vector index 26683ae238e9..57d35064508e 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -279,6 +279,7 @@ erase_if(vector& c, Predicate pred); // C++20 #include <__algorithm/remove_if.h> #include <__algorithm/rotate.h> #include <__algorithm/unwrap_iter.h> +#include <__assert> #include <__bit_reference> #include <__config> #include <__debug> diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt index 12dcdf954405..3395003c373b 100644 --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -65,6 +65,7 @@ set(LIBCXX_SOURCES if (LIBCXX_ENABLE_DEBUG_MODE_SUPPORT) list(APPEND LIBCXX_SOURCES + assert.cpp debug.cpp ) endif() diff --git a/libcxx/src/assert.cpp b/libcxx/src/assert.cpp new file mode 100644 index 000000000000..40c51f872bcd --- /dev/null +++ b/libcxx/src/assert.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include <__assert> +#include <__config> +#include +#include +#include + +_LIBCPP_BEGIN_NAMESPACE_STD + +std::string __libcpp_debug_info::what() const { + string msg = __file_; + msg += ":" + std::to_string(__line_) + ": _LIBCPP_ASSERT '"; + msg += __pred_; + msg += "' failed. "; + msg += __msg_; + return msg; +} + +_LIBCPP_NORETURN void __libcpp_abort_debug_function(__libcpp_debug_info const& info) { + std::fprintf(stderr, "%s\n", info.what().c_str()); + std::abort(); +} + +constinit __libcpp_debug_function_type __libcpp_debug_function = __libcpp_abort_debug_function; + +bool __libcpp_set_debug_function(__libcpp_debug_function_type __func) { + __libcpp_debug_function = __func; + return true; +} + +_LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/src/debug.cpp b/libcxx/src/debug.cpp index 14a75b10f742..8f1d328f0e0f 100644 --- a/libcxx/src/debug.cpp +++ b/libcxx/src/debug.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include <__assert> #include <__config> #include <__debug> #include <__hash_table> @@ -23,26 +24,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD -std::string __libcpp_debug_info::what() const { - string msg = __file_; - msg += ":" + to_string(__line_) + ": _LIBCPP_ASSERT '"; - msg += __pred_; - msg += "' failed. "; - msg += __msg_; - return msg; -} -_LIBCPP_NORETURN void __libcpp_abort_debug_function(__libcpp_debug_info const& info) { - std::fprintf(stderr, "%s\n", info.what().c_str()); - std::abort(); -} - -constinit __libcpp_debug_function_type __libcpp_debug_function = __libcpp_abort_debug_function; - -bool __libcpp_set_debug_function(__libcpp_debug_function_type __func) { - __libcpp_debug_function = __func; - return true; -} - _LIBCPP_FUNC_VIS __libcpp_db* __get_db() diff --git a/libcxx/src/filesystem/directory_iterator.cpp b/libcxx/src/filesystem/directory_iterator.cpp index c9294f7a328b..8b91929df877 100644 --- a/libcxx/src/filesystem/directory_iterator.cpp +++ b/libcxx/src/filesystem/directory_iterator.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include <__assert> #include <__config> #include #include diff --git a/libcxx/src/filesystem/filesystem_common.h b/libcxx/src/filesystem/filesystem_common.h index 94153567b811..c98d14416c8b 100644 --- a/libcxx/src/filesystem/filesystem_common.h +++ b/libcxx/src/filesystem/filesystem_common.h @@ -9,6 +9,7 @@ #ifndef FILESYSTEM_COMMON_H #define FILESYSTEM_COMMON_H +#include <__assert> #include <__config> #include #include diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp index 57e25397a28c..0e2ebdfe5aa7 100644 --- a/libcxx/src/filesystem/operations.cpp +++ b/libcxx/src/filesystem/operations.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include <__assert> #include <__utility/unreachable.h> #include #include diff --git a/libcxx/src/filesystem/posix_compat.h b/libcxx/src/filesystem/posix_compat.h index 6cd665008161..36116ec5a395 100644 --- a/libcxx/src/filesystem/posix_compat.h +++ b/libcxx/src/filesystem/posix_compat.h @@ -23,6 +23,7 @@ #ifndef POSIX_COMPAT_H #define POSIX_COMPAT_H +#include <__assert> #include #include "filesystem_common.h" diff --git a/libcxx/src/include/ryu/common.h b/libcxx/src/include/ryu/common.h index 52913120f107..c24115c23364 100644 --- a/libcxx/src/include/ryu/common.h +++ b/libcxx/src/include/ryu/common.h @@ -42,6 +42,7 @@ // Avoid formatting to keep the changes with the original code minimal. // clang-format off +#include <__assert> #include "__config" _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/libcxx/src/include/ryu/d2s_intrinsics.h b/libcxx/src/include/ryu/d2s_intrinsics.h index 093d8580774b..762763f9b92c 100644 --- a/libcxx/src/include/ryu/d2s_intrinsics.h +++ b/libcxx/src/include/ryu/d2s_intrinsics.h @@ -42,6 +42,7 @@ // Avoid formatting to keep the changes with the original code minimal. // clang-format off +#include <__assert> #include <__config> #include "include/ryu/ryu.h" diff --git a/libcxx/src/include/to_chars_floating_point.h b/libcxx/src/include/to_chars_floating_point.h index 3f8d3613d8bd..0bb45d0b9791 100644 --- a/libcxx/src/include/to_chars_floating_point.h +++ b/libcxx/src/include/to_chars_floating_point.h @@ -21,6 +21,7 @@ #include <__algorithm/find_if.h> #include <__algorithm/lower_bound.h> #include <__algorithm/min.h> +#include <__assert> #include <__config> #include <__iterator/access.h> #include <__iterator/size.h> diff --git a/libcxx/src/mutex.cpp b/libcxx/src/mutex.cpp index 9e780aaff64e..01b7420fa3b8 100644 --- a/libcxx/src/mutex.cpp +++ b/libcxx/src/mutex.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include <__assert> #include #include #include diff --git a/libcxx/src/ryu/d2fixed.cpp b/libcxx/src/ryu/d2fixed.cpp index bb6d62180361..c1a1f6cf9e05 100644 --- a/libcxx/src/ryu/d2fixed.cpp +++ b/libcxx/src/ryu/d2fixed.cpp @@ -39,6 +39,7 @@ // Avoid formatting to keep the changes with the original code minimal. // clang-format off +#include <__assert> #include <__config> #include #include diff --git a/libcxx/src/ryu/d2s.cpp b/libcxx/src/ryu/d2s.cpp index e22bfa4a12e6..245c2eb5908d 100644 --- a/libcxx/src/ryu/d2s.cpp +++ b/libcxx/src/ryu/d2s.cpp @@ -39,6 +39,7 @@ // Avoid formatting to keep the changes with the original code minimal. // clang-format off +#include <__assert> #include <__config> #include diff --git a/libcxx/src/ryu/f2s.cpp b/libcxx/src/ryu/f2s.cpp index e7d46d21cdbd..3bcfe462c8f7 100644 --- a/libcxx/src/ryu/f2s.cpp +++ b/libcxx/src/ryu/f2s.cpp @@ -39,6 +39,7 @@ // Avoid formatting to keep the changes with the original code minimal. // clang-format off +#include <__assert> #include <__config> #include diff --git a/libcxx/src/string.cpp b/libcxx/src/string.cpp index db7d7d5598dd..9d1de0cf6ca1 100644 --- a/libcxx/src/string.cpp +++ b/libcxx/src/string.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include <__debug> +#include <__assert> #include #include #include diff --git a/libcxx/src/strstream.cpp b/libcxx/src/strstream.cpp index c3a7eb9a8c66..87c235a97a29 100644 --- a/libcxx/src/strstream.cpp +++ b/libcxx/src/strstream.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// +#include <__assert> #include <__utility/unreachable.h> -#include <__debug> #include #include #include diff --git a/libcxx/src/support/ibm/xlocale_zos.cpp b/libcxx/src/support/ibm/xlocale_zos.cpp index 90c1ba95a313..a3f9558a0611 100644 --- a/libcxx/src/support/ibm/xlocale_zos.cpp +++ b/libcxx/src/support/ibm/xlocale_zos.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include <__assert> #include <__support/ibm/xlocale.h> #include #include diff --git a/libcxx/src/system_error.cpp b/libcxx/src/system_error.cpp index 1c4570291cb3..66db76c37b5f 100644 --- a/libcxx/src/system_error.cpp +++ b/libcxx/src/system_error.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// +#include <__assert> #include <__config> -#include <__debug> #include #include #include diff --git a/libcxx/test/libcxx/debug/debug_abort.pass.cpp b/libcxx/test/libcxx/debug/debug_abort.pass.cpp index a56c304d014f..a74fdb01adf3 100644 --- a/libcxx/test/libcxx/debug/debug_abort.pass.cpp +++ b/libcxx/test/libcxx/debug/debug_abort.pass.cpp @@ -11,9 +11,9 @@ // Test that the default debug handler aborts the program. +#include <__assert> #include #include -#include <__debug> #include "test_macros.h" diff --git a/libcxx/utils/generate_private_header_tests.py b/libcxx/utils/generate_private_header_tests.py index e6eecd68ae50..810657ea4f41 100755 --- a/libcxx/utils/generate_private_header_tests.py +++ b/libcxx/utils/generate_private_header_tests.py @@ -52,7 +52,7 @@ def relative_path(path): def is_still_public(path): rp = relative_path(path) return not rp.startswith('__support') and rp not in [ - "__bsd_locale_defaults.h", "__bsd_locale_fallbacks.h", "__config", + "__assert", "__bsd_locale_defaults.h", "__bsd_locale_fallbacks.h", "__config", "__config_site.in", "__debug", "__hash_table", "__libcpp_version", "__threading_support", "__tree", "__undef_macros" ]