diff --git a/libcxx/include/__assert b/libcxx/include/__assert --- a/libcxx/include/__assert +++ b/libcxx/include/__assert @@ -45,7 +45,7 @@ # define _LIBCPP_ASSERT(expression, message) \ (__builtin_expect(static_cast(expression), 1) ? \ (void)0 : \ - ::std::__libcpp_verbose_abort("%s:%d: assertion %s failed: %s", __FILE__, __LINE__, #expression, message)) + _LIBCPP_ASSERTION_ABORT(expression, message)) #elif !defined(_LIBCPP_ASSERTIONS_DISABLE_ASSUME) && __has_builtin(__builtin_assume) # define _LIBCPP_ASSERT(expression, message) \ (_LIBCPP_DIAGNOSTIC_PUSH \ diff --git a/libcxx/include/__filesystem/filesystem_error.h b/libcxx/include/__filesystem/filesystem_error.h --- a/libcxx/include/__filesystem/filesystem_error.h +++ b/libcxx/include/__filesystem/filesystem_error.h @@ -90,8 +90,8 @@ throw filesystem_error(_VSTD::forward<_Args>(__args)...); } #else -void __throw_filesystem_error(_Args&&...) { - _VSTD::abort(); +void __throw_filesystem_error(_Args&&... __args) { + _LIBCPP_EXCEPTION_ABORT(filesystem_error(_VSTD::forward<_Args>(__args)...).what()); } #endif _LIBCPP_AVAILABILITY_FILESYSTEM_POP 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 @@ -62,7 +62,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_function_call(); #else - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT("bad_function_call"); #endif } diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h --- a/libcxx/include/__memory/shared_ptr.h +++ b/libcxx/include/__memory/shared_ptr.h @@ -140,7 +140,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_weak_ptr(); #else - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT("bad_weak_ptr"); #endif } diff --git a/libcxx/include/__utility/unreachable.h b/libcxx/include/__utility/unreachable.h --- a/libcxx/include/__utility/unreachable.h +++ b/libcxx/include/__utility/unreachable.h @@ -10,7 +10,7 @@ #define _LIBCPP___UTILITY_UNREACHABLE_H #include <__config> -#include +#include <__verbose_abort> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -23,7 +23,7 @@ #if __has_builtin(__builtin_unreachable) __builtin_unreachable(); #else - std::abort(); + std::__libcpp_verbose_abort("__libcpp_unreachable reached\n"); #endif } diff --git a/libcxx/include/__verbose_abort b/libcxx/include/__verbose_abort --- a/libcxx/include/__verbose_abort +++ b/libcxx/include/__verbose_abort @@ -48,4 +48,30 @@ #endif +_LIBCPP_BEGIN_NAMESPACE_STD + +// Define utilities to abort with specific semantics. +// +// This is used to provide additional useful information in cases where we want to abort the program. + +// Handler for when an exception would be thrown but the code is compiled with -fno-exceptions +#define _LIBCPP_EXCEPTION_ABORT(__msg) \ + ::std::__exception_abort(__FILE__, __LINE__, __msg) + +_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI inline +void __exception_abort(char const* __file, int __line, char const* __msg) { + std::__libcpp_verbose_abort("%s:%d: Exception thrown with exceptions disabled: %s\n", __file, __line, __msg); +} + +// Handler for when an assertion fails +#define _LIBCPP_ASSERTION_ABORT(__expr, __msg) \ + ::std::__assertion_abort(__FILE__, __LINE__, #__expr, __msg) + +_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI inline +void __assertion_abort(char const* __file, int __line, char const* __expr, char const* __msg) { + std::__libcpp_verbose_abort("%s:%d: Assertion %s failed: %s\n", __file, __line, __expr, __msg); +} + +_LIBCPP_END_NAMESPACE_STD + #endif // _LIBCPP___VERBOSE_ABORT diff --git a/libcxx/include/any b/libcxx/include/any --- a/libcxx/include/any +++ b/libcxx/include/any @@ -121,7 +121,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_any_cast(); #else - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT("bad_any_cast"); #endif } diff --git a/libcxx/include/future b/libcxx/include/future --- a/libcxx/include/future +++ b/libcxx/include/future @@ -527,11 +527,11 @@ #endif void __throw_future_error(future_errc __ev) { + std::error_code __ec = make_error_code(__ev); #ifndef _LIBCPP_NO_EXCEPTIONS - throw future_error(make_error_code(__ev)); + throw future_error(__ec); #else - ((void)__ev); - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(__ec.message().c_str()); #endif } diff --git a/libcxx/include/ios b/libcxx/include/ios --- a/libcxx/include/ios +++ b/libcxx/include/ios @@ -449,8 +449,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw ios_base::failure(__msg); #else - ((void)__msg); - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(__msg); #endif } diff --git a/libcxx/include/new b/libcxx/include/new --- a/libcxx/include/new +++ b/libcxx/include/new @@ -156,7 +156,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_array_new_length(); #else - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT("bad_array_new_length"); #endif } diff --git a/libcxx/include/optional b/libcxx/include/optional --- a/libcxx/include/optional +++ b/libcxx/include/optional @@ -224,7 +224,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_optional_access(); #else - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT("bad_optional_access"); #endif } diff --git a/libcxx/include/regex b/libcxx/include/regex --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -1018,7 +1018,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw regex_error(_Ev); #else - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(regex_error(_Ev).what()); #endif } diff --git a/libcxx/include/stdexcept b/libcxx/include/stdexcept --- a/libcxx/include/stdexcept +++ b/libcxx/include/stdexcept @@ -223,8 +223,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw logic_error(__msg); #else - ((void)__msg); - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(__msg); #endif } @@ -234,8 +233,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw domain_error(__msg); #else - ((void)__msg); - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(__msg); #endif } @@ -245,8 +243,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw invalid_argument(__msg); #else - ((void)__msg); - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(__msg); #endif } @@ -256,8 +253,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw length_error(__msg); #else - ((void)__msg); - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(__msg); #endif } @@ -267,8 +263,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw out_of_range(__msg); #else - ((void)__msg); - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(__msg); #endif } @@ -278,8 +273,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw range_error(__msg); #else - ((void)__msg); - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(__msg); #endif } @@ -289,8 +283,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw overflow_error(__msg); #else - ((void)__msg); - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(__msg); #endif } @@ -300,8 +293,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw underflow_error(__msg); #else - ((void)__msg); - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(__msg); #endif } diff --git a/libcxx/include/typeinfo b/libcxx/include/typeinfo --- a/libcxx/include/typeinfo +++ b/libcxx/include/typeinfo @@ -377,7 +377,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_cast(); #else - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT("bad_cast"); #endif } _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/variant b/libcxx/include/variant --- a/libcxx/include/variant +++ b/libcxx/include/variant @@ -267,7 +267,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_variant_access(); #else - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT("bad_variant_access"); #endif } diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp --- a/libcxx/src/locale.cpp +++ b/libcxx/src/locale.cpp @@ -121,8 +121,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw runtime_error(msg); #else - (void)msg; - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(msg.c_str()); #endif } @@ -6539,8 +6538,7 @@ #ifndef _LIBCPP_NO_EXCEPTIONS throw runtime_error(msg); #else - (void)msg; - _VSTD::abort(); + _LIBCPP_EXCEPTION_ABORT(msg); #endif }