[libc++] Make __libcpp_verbose_abort [[noreturn]]
authorLouis Dionne <ldionne.2@gmail.com>
Mon, 8 Aug 2022 15:53:34 +0000 (11:53 -0400)
committerTobias Hieta <tobias@hieta.se>
Fri, 12 Aug 2022 06:36:00 +0000 (08:36 +0200)
This will allow using it in functions that are [[noreturn]] themselves.

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

(cherry picked from commit f5738c51452f90d7f33963d1c0c6f8e7f3d801e3)

libcxx/include/__verbose_abort
libcxx/test/libcxx/assertions/customize_verbose_abort.backdeployment.pass.cpp
libcxx/test/libcxx/assertions/customize_verbose_abort.pass.cpp
libcxx/test/libcxx/assertions/debug_mode_compatibility.pass.cpp

index 822df215039ae75a5b37d21242bf05efa62cac5f..3c9cba824ce0bde949cd04064be3c30ab2571ba5 100644 (file)
@@ -29,9 +29,10 @@ extern "C" void abort();
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) _LIBCPP_HIDE_FROM_ABI inline
+_LIBCPP_NORETURN _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) _LIBCPP_HIDE_FROM_ABI inline
 void __libcpp_verbose_abort(const char *, ...) {
-    ::abort();
+  ::abort();
+  __builtin_unreachable(); // never reached, but needed to tell the compiler that the function never returns
 }
 
 _LIBCPP_END_NAMESPACE_STD
@@ -40,7 +41,7 @@ _LIBCPP_END_NAMESPACE_STD
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2)
+_LIBCPP_NORETURN _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2)
 void __libcpp_verbose_abort(const char *__format, ...);
 
 _LIBCPP_END_NAMESPACE_STD
index 45f92bc83a268eb59625d976b2c813f607208b27..15962671a4690a3413b6fbc28b947c06deebf72c 100644 (file)
@@ -9,20 +9,18 @@
 // Make sure that we can enable assertions when we back-deploy to older platforms
 // if we define _LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED.
 //
-// Note that this test isn't really different from customize_handler.pass.cpp when
-// run outside of back-deployment scenarios, but we still run it all the time.
+// Note that this test isn't really different from customize_verbose_abort.pass.cpp when
+// run outside of back-deployment scenarios, but we always want to run this test.
 
 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_ASSERTIONS=1 -D_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED
 
-#include <cassert>
+#include <cstdlib>
 
-bool handler_called = false;
 void std::__libcpp_verbose_abort(char const*, ...) {
-  handler_called = true;
+  std::exit(EXIT_SUCCESS);
 }
 
 int main(int, char**) {
   _LIBCPP_ASSERT(false, "message");
-  assert(handler_called);
-  return 0;
+  return EXIT_FAILURE;
 }
index 7f956742bbe71f2aebae065c7181620dfcc285bd..3ee9b7803b709b28c5cedc7846085a7d1e8fe5b1 100644 (file)
 // failures when back-deploying.
 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0|12.0}}
 
-#include <cassert>
+#include <cstdlib>
 
-bool handler_called = false;
 void std::__libcpp_verbose_abort(char const*, ...) {
-  handler_called = true;
+  std::exit(EXIT_SUCCESS);
 }
 
 int main(int, char**) {
   _LIBCPP_ASSERT(false, "message");
-  assert(handler_called);
-  return 0;
+  return EXIT_FAILURE;
 }
index b1dd54cbacd1e82eb01c1ba86a224de2737aee4c..fe7f0389de911b9e45e7e5d668d94b6e34dd28e9 100644 (file)
 // failures when back-deploying.
 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0|12.0}}
 
-#include <cassert>
+#include <cstdlib>
 
-bool handler_called = false;
 void std::__libcpp_verbose_abort(char const*, ...) {
-  handler_called = true;
+  std::exit(EXIT_SUCCESS);
 }
 
 int main(int, char**) {
   _LIBCPP_ASSERT(false, "message");
-  assert(handler_called);
-  return 0;
+  return EXIT_FAILURE;
 }