[libcxx-commits] [libcxx] 16d1b0e - [libc++] Use __verbose_abort instead of std::abort in __throw_ functions

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 14 11:33:26 PDT 2023


Author: Nikolas Klauser
Date: 2023-03-14T19:33:19+01:00
New Revision: 16d1b0e1059eb5bcc1cb7581598734b3cbc89509

URL: https://github.com/llvm/llvm-project/commit/16d1b0e1059eb5bcc1cb7581598734b3cbc89509
DIFF: https://github.com/llvm/llvm-project/commit/16d1b0e1059eb5bcc1cb7581598734b3cbc89509.diff

LOG: [libc++] Use __verbose_abort instead of std::abort in __throw_ functions

This results in proper error messages instead of just an abort.

Reviewed By: ldionne, Mordante, #libc

Spies: #libc_vendors, smeenai, libcxx-commits

Differential Revision: https://reviews.llvm.org/D141222

Added: 
    

Modified: 
    libcxx/include/__expected/expected.h
    libcxx/include/__filesystem/filesystem_error.h
    libcxx/include/__functional/function.h
    libcxx/include/__memory/shared_ptr.h
    libcxx/include/any
    libcxx/include/future
    libcxx/include/ios
    libcxx/include/new
    libcxx/include/optional
    libcxx/include/regex
    libcxx/include/stdexcept
    libcxx/include/typeinfo
    libcxx/include/variant

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__expected/expected.h b/libcxx/include/__expected/expected.h
index 8bb04071b1230..263207cd994bf 100644
--- a/libcxx/include/__expected/expected.h
+++ b/libcxx/include/__expected/expected.h
@@ -49,6 +49,7 @@
 #include <__utility/in_place.h>
 #include <__utility/move.h>
 #include <__utility/swap.h>
+#include <__verbose_abort>
 #include <cstdlib> // for std::abort
 #include <initializer_list>
 
@@ -68,7 +69,7 @@ _LIBCPP_HIDE_FROM_ABI void __throw_bad_expected_access(_Arg&& __arg) {
   throw bad_expected_access<_Err>(std::forward<_Arg>(__arg));
 #  else
   (void)__arg;
-  std::abort();
+  std::__libcpp_verbose_abort("bad_expected_access was thrown in -fno-exceptions mode");
 #  endif
 }
 

diff  --git a/libcxx/include/__filesystem/filesystem_error.h b/libcxx/include/__filesystem/filesystem_error.h
index 49a076a5cc6d0..304d87bdd006f 100644
--- a/libcxx/include/__filesystem/filesystem_error.h
+++ b/libcxx/include/__filesystem/filesystem_error.h
@@ -15,6 +15,7 @@
 #include <__filesystem/path.h>
 #include <__memory/shared_ptr.h>
 #include <__utility/forward.h>
+#include <__verbose_abort>
 #include <iosfwd>
 #include <new>
 #include <system_error>
@@ -91,7 +92,7 @@ void __throw_filesystem_error(_Args&&... __args) {
 }
 #else
 void __throw_filesystem_error(_Args&&...) {
-  _VSTD::abort();
+    std::__libcpp_verbose_abort("filesystem_error was thrown in -fno-exceptions mode");
 }
 #endif
 _LIBCPP_AVAILABILITY_FILESYSTEM_POP

diff  --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h
index 1d2d2a1c8da37..bd62344eff3ba 100644
--- a/libcxx/include/__functional/function.h
+++ b/libcxx/include/__functional/function.h
@@ -31,6 +31,7 @@
 #include <__utility/move.h>
 #include <__utility/piecewise_construct.h>
 #include <__utility/swap.h>
+#include <__verbose_abort>
 #include <exception>
 #include <new>
 #include <tuple>
@@ -73,7 +74,7 @@ void __throw_bad_function_call()
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw bad_function_call();
 #else
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("bad_function_call was thrown in -fno-exceptions mode");
 #endif
 }
 

diff  --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index c88ced2c5bbe5..dd10d4cd14ab9 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -47,6 +47,7 @@
 #include <__utility/forward.h>
 #include <__utility/move.h>
 #include <__utility/swap.h>
+#include <__verbose_abort>
 #include <cstddef>
 #include <cstdlib> // abort
 #include <iosfwd>
@@ -136,7 +137,7 @@ void __throw_bad_weak_ptr()
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw bad_weak_ptr();
 #else
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("bad_weak_ptr was thrown in -fno-exceptions mode");
 #endif
 }
 

diff  --git a/libcxx/include/any b/libcxx/include/any
index addd6d4285c0b..6ffbd6441f3c9 100644
--- a/libcxx/include/any
+++ b/libcxx/include/any
@@ -106,6 +106,7 @@ namespace std {
 #include <__utility/in_place.h>
 #include <__utility/move.h>
 #include <__utility/unreachable.h>
+#include <__verbose_abort>
 #include <cstdlib>
 #include <initializer_list>
 #include <typeinfo>
@@ -134,7 +135,7 @@ void __throw_bad_any_cast()
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw bad_any_cast();
 #else
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("bad_any_cast was thrown in -fno-exceptions mode");
 #endif
 }
 

diff  --git a/libcxx/include/future b/libcxx/include/future
index e0e56efa32999..d8a404f1fcdb4 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -377,6 +377,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
 #include <__utility/auto_cast.h>
 #include <__utility/forward.h>
 #include <__utility/move.h>
+#include <__verbose_abort>
 #include <exception>
 #include <mutex>
 #include <new>
@@ -532,8 +533,8 @@ void __throw_future_error(future_errc __ev)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw future_error(make_error_code(__ev));
 #else
-    ((void)__ev);
-    _VSTD::abort();
+    (void)__ev;
+    std::__libcpp_verbose_abort("future_error was thrown in -fno-exceptions mode");
 #endif
 }
 

diff  --git a/libcxx/include/ios b/libcxx/include/ios
index 0682ecfe5f6c6..056ede16a1040 100644
--- a/libcxx/include/ios
+++ b/libcxx/include/ios
@@ -220,6 +220,7 @@ storage-class-specifier const error_category& iostream_category() noexcept;
 #include <__ios/fpos.h>
 #include <__locale>
 #include <__utility/swap.h>
+#include <__verbose_abort>
 #include <system_error>
 #include <version>
 
@@ -451,8 +452,7 @@ void __throw_failure(char const* __msg) {
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw ios_base::failure(__msg);
 #else
-    ((void)__msg);
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("ios_base::failure was thrown in -fno-exceptions mode with message \"%s\"", __msg);
 #endif
 }
 

diff  --git a/libcxx/include/new b/libcxx/include/new
index be8033e33db91..ce1d9169f623e 100644
--- a/libcxx/include/new
+++ b/libcxx/include/new
@@ -92,6 +92,7 @@ void  operator delete[](void* ptr, void*) noexcept;
 #include <__type_traits/is_function.h>
 #include <__type_traits/is_same.h>
 #include <__type_traits/remove_cv.h>
+#include <__verbose_abort>
 #include <cstddef>
 #include <cstdlib>
 #include <exception>
@@ -176,7 +177,7 @@ void __throw_bad_array_new_length()
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw bad_array_new_length();
 #else
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("bad_array_new_length was thrown in -fno-exceptions mode");
 #endif
 }
 

diff  --git a/libcxx/include/optional b/libcxx/include/optional
index 641745b7bda94..d31c5088ca4d3 100644
--- a/libcxx/include/optional
+++ b/libcxx/include/optional
@@ -181,6 +181,7 @@ template<class T>
 #include <__utility/in_place.h>
 #include <__utility/move.h>
 #include <__utility/swap.h>
+#include <__verbose_abort>
 #include <initializer_list>
 #include <new>
 #include <stdexcept>
@@ -220,7 +221,7 @@ void __throw_bad_optional_access() {
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
         throw bad_optional_access();
 #else
-        _VSTD::abort();
+    std::__libcpp_verbose_abort("bad_optional_access was thrown in -fno-exceptions mode");
 #endif
 }
 

diff  --git a/libcxx/include/regex b/libcxx/include/regex
index 1fe93a19a5157..b4a58c27f3360 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -776,6 +776,7 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
 #include <__utility/move.h>
 #include <__utility/pair.h>
 #include <__utility/swap.h>
+#include <__verbose_abort>
 #include <deque>
 #include <stdexcept>
 #include <string>
@@ -1017,7 +1018,7 @@ void __throw_regex_error()
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw regex_error(_Ev);
 #else
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("regex_error was thrown in -fno-exceptions mode");
 #endif
 }
 

diff  --git a/libcxx/include/stdexcept b/libcxx/include/stdexcept
index 6b7d10b5dc799..826c6f4192f38 100644
--- a/libcxx/include/stdexcept
+++ b/libcxx/include/stdexcept
@@ -43,6 +43,7 @@ public:
 
 #include <__assert> // all public C++ headers provide the assertion handler
 #include <__config>
+#include <__verbose_abort>
 #include <cstdlib>
 #include <exception>
 #include <iosfwd>  // for string forward decl
@@ -223,8 +224,7 @@ void __throw_logic_error(const char*__msg)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw logic_error(__msg);
 #else
-    ((void)__msg);
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("logic_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
 #endif
 }
 
@@ -234,8 +234,7 @@ void __throw_domain_error(const char*__msg)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw domain_error(__msg);
 #else
-    ((void)__msg);
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("domain_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
 #endif
 }
 
@@ -245,8 +244,7 @@ void __throw_invalid_argument(const char*__msg)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw invalid_argument(__msg);
 #else
-    ((void)__msg);
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("invalid_argument was thrown in -fno-exceptions mode with message \"%s\"", __msg);
 #endif
 }
 
@@ -256,8 +254,7 @@ void __throw_length_error(const char*__msg)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw length_error(__msg);
 #else
-    ((void)__msg);
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("length_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
 #endif
 }
 
@@ -267,8 +264,7 @@ void __throw_out_of_range(const char*__msg)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw out_of_range(__msg);
 #else
-    ((void)__msg);
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("out_of_range was thrown in -fno-exceptions mode with message \"%s\"", __msg);
 #endif
 }
 
@@ -278,8 +274,7 @@ void __throw_range_error(const char*__msg)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw range_error(__msg);
 #else
-    ((void)__msg);
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("range_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
 #endif
 }
 
@@ -289,8 +284,7 @@ void __throw_overflow_error(const char*__msg)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw overflow_error(__msg);
 #else
-    ((void)__msg);
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("overflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
 #endif
 }
 
@@ -300,8 +294,7 @@ void __throw_underflow_error(const char*__msg)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw underflow_error(__msg);
 #else
-    ((void)__msg);
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("underflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
 #endif
 }
 

diff  --git a/libcxx/include/typeinfo b/libcxx/include/typeinfo
index 2558e1750a383..6a40c969d9719 100644
--- a/libcxx/include/typeinfo
+++ b/libcxx/include/typeinfo
@@ -60,6 +60,7 @@ public:
 #include <__availability>
 #include <__config>
 #include <__type_traits/is_constant_evaluated.h>
+#include <__verbose_abort>
 #include <cstddef>
 #include <cstdint>
 #include <cstdlib>
@@ -408,7 +409,7 @@ void __throw_bad_cast()
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw bad_cast();
 #else
-    _VSTD::abort();
+    std::__libcpp_verbose_abort("bad_cast was thrown in -fno-exceptions mode");
 #endif
 }
 _LIBCPP_END_NAMESPACE_STD

diff  --git a/libcxx/include/variant b/libcxx/include/variant
index 88f63dd5610ab..d154d3d93637b 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -238,6 +238,7 @@ namespace std {
 #include <__utility/move.h>
 #include <__utility/swap.h>
 #include <__variant/monostate.h>
+#include <__verbose_abort>
 #include <exception>
 #include <initializer_list>
 #include <limits>
@@ -290,7 +291,7 @@ void __throw_bad_variant_access() {
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
         throw bad_variant_access();
 #else
-        _VSTD::abort();
+    std::__libcpp_verbose_abort("bad_variant_access was thrown in -fno-exceptions mode");
 #endif
 }
 


        


More information about the libcxx-commits mailing list