[llvm-branch-commits] [libcxx] 23690ef - [libc++] Make __libcpp_verbose_abort [[noreturn]]

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Aug 11 23:37:10 PDT 2022


Author: Louis Dionne
Date: 2022-08-12T08:36:00+02:00
New Revision: 23690efc2fb4d30269d0fc5e87137b58483d44a6

URL: https://github.com/llvm/llvm-project/commit/23690efc2fb4d30269d0fc5e87137b58483d44a6
DIFF: https://github.com/llvm/llvm-project/commit/23690efc2fb4d30269d0fc5e87137b58483d44a6.diff

LOG: [libc++] Make __libcpp_verbose_abort [[noreturn]]

This will allow using it in functions that are [[noreturn]] themselves.

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

(cherry picked from commit f5738c51452f90d7f33963d1c0c6f8e7f3d801e3)

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__verbose_abort b/libcxx/include/__verbose_abort
index 822df215039ae..3c9cba824ce0b 100644
--- a/libcxx/include/__verbose_abort
+++ b/libcxx/include/__verbose_abort
@@ -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

diff  --git a/libcxx/test/libcxx/assertions/customize_verbose_abort.backdeployment.pass.cpp b/libcxx/test/libcxx/assertions/customize_verbose_abort.backdeployment.pass.cpp
index 45f92bc83a268..15962671a4690 100644
--- a/libcxx/test/libcxx/assertions/customize_verbose_abort.backdeployment.pass.cpp
+++ b/libcxx/test/libcxx/assertions/customize_verbose_abort.backdeployment.pass.cpp
@@ -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 
diff erent 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 
diff erent 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;
 }

diff  --git a/libcxx/test/libcxx/assertions/customize_verbose_abort.pass.cpp b/libcxx/test/libcxx/assertions/customize_verbose_abort.pass.cpp
index 7f956742bbe71..3ee9b7803b709 100644
--- a/libcxx/test/libcxx/assertions/customize_verbose_abort.pass.cpp
+++ b/libcxx/test/libcxx/assertions/customize_verbose_abort.pass.cpp
@@ -14,15 +14,13 @@
 // 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;
 }

diff  --git a/libcxx/test/libcxx/assertions/debug_mode_compatibility.pass.cpp b/libcxx/test/libcxx/assertions/debug_mode_compatibility.pass.cpp
index b1dd54cbacd1e..fe7f0389de911 100644
--- a/libcxx/test/libcxx/assertions/debug_mode_compatibility.pass.cpp
+++ b/libcxx/test/libcxx/assertions/debug_mode_compatibility.pass.cpp
@@ -16,15 +16,13 @@
 // 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;
 }


        


More information about the llvm-branch-commits mailing list