diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -99,6 +99,7 @@ __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 --- 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 --- 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 --- 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 --- /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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- a/libcxx/include/__node_handle +++ b/libcxx/include/__node_handle @@ -58,8 +58,8 @@ */ +#include <__assert> #include <__config> -#include <__debug> #include #include diff --git a/libcxx/include/__numeric/gcd_lcm.h b/libcxx/include/__numeric/gcd_lcm.h --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- a/libcxx/include/array +++ b/libcxx/include/array @@ -112,8 +112,8 @@ #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 --- a/libcxx/include/bit +++ b/libcxx/include/bit @@ -61,11 +61,11 @@ */ +#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 --- a/libcxx/include/charconv +++ b/libcxx/include/charconv @@ -77,6 +77,7 @@ */ +#include <__assert> #include <__availability> #include <__bits> #include <__charconv/chars_format.h> diff --git a/libcxx/include/deque b/libcxx/include/deque --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -169,8 +169,8 @@ #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 --- a/libcxx/include/experimental/coroutine +++ b/libcxx/include/experimental/coroutine @@ -45,7 +45,7 @@ */ -#include <__debug> +#include <__assert> #include #include #include diff --git a/libcxx/include/experimental/memory_resource b/libcxx/include/experimental/memory_resource --- a/libcxx/include/experimental/memory_resource +++ b/libcxx/include/experimental/memory_resource @@ -64,7 +64,7 @@ */ -#include <__debug> +#include <__assert> #include <__tuple> #include #include diff --git a/libcxx/include/fstream b/libcxx/include/fstream --- a/libcxx/include/fstream +++ b/libcxx/include/fstream @@ -180,9 +180,9 @@ */ #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 --- a/libcxx/include/future +++ b/libcxx/include/future @@ -361,9 +361,9 @@ */ +#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 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -184,6 +184,7 @@ #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 --- a/libcxx/include/locale +++ b/libcxx/include/locale @@ -192,6 +192,7 @@ #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 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -530,8 +530,8 @@ #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 --- a/libcxx/include/module.modulemap +++ b/libcxx/include/module.modulemap @@ -989,6 +989,7 @@ // __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 --- a/libcxx/include/optional +++ b/libcxx/include/optional @@ -158,10 +158,10 @@ */ +#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 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -763,8 +763,8 @@ */ #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 --- a/libcxx/include/set +++ b/libcxx/include/set @@ -473,8 +473,8 @@ #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 --- a/libcxx/include/span +++ b/libcxx/include/span @@ -127,6 +127,7 @@ */ +#include <__assert> #include <__config> #include <__debug> #include <__iterator/concepts.h> diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -522,6 +522,7 @@ #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 --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -196,8 +196,8 @@ */ #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 --- a/libcxx/include/thread +++ b/libcxx/include/thread @@ -82,8 +82,8 @@ */ +#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 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -515,6 +515,7 @@ */ #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 --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -460,6 +460,7 @@ */ #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 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -279,6 +279,7 @@ #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 --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -65,6 +65,7 @@ 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 --- /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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- a/libcxx/utils/generate_private_header_tests.py +++ b/libcxx/utils/generate_private_header_tests.py @@ -52,7 +52,7 @@ 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" ]