[libcxx-commits] [libcxx] 5951c44 - [libc++] Introduce the _LIBCPP_VERBOSE_TRAP macro (#148262)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jul 14 06:56:23 PDT 2025
Author: Konstantin Varlamov
Date: 2025-07-14T09:56:19-04:00
New Revision: 5951c44573203710901c6bdb06a382efbcc907fa
URL: https://github.com/llvm/llvm-project/commit/5951c44573203710901c6bdb06a382efbcc907fa
DIFF: https://github.com/llvm/llvm-project/commit/5951c44573203710901c6bdb06a382efbcc907fa.diff
LOG: [libc++] Introduce the _LIBCPP_VERBOSE_TRAP macro (#148262)
Split out the calls to __builtin_verbose_trap into a separate header.
This is just a refactoring to make the code a bit more structured.
Added:
libcxx/include/__cxx03/__verbose_trap
libcxx/include/__verbose_trap
Modified:
libcxx/include/CMakeLists.txt
libcxx/include/module.modulemap.in
libcxx/vendor/llvm/default_assertion_handler.in
Removed:
################################################################################
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index c8e6d28584623..4f2a8dddad92c 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -944,6 +944,7 @@ set(files
__vector/vector_bool.h
__vector/vector_bool_formatter.h
__verbose_abort
+ __verbose_trap
algorithm
any
array
@@ -1569,6 +1570,7 @@ set(files
__cxx03/__utility/unreachable.h
__cxx03/__variant/monostate.h
__cxx03/__verbose_abort
+ __cxx03/__verbose_trap
__cxx03/algorithm
__cxx03/array
__cxx03/atomic
diff --git a/libcxx/include/__cxx03/__verbose_trap b/libcxx/include/__cxx03/__verbose_trap
new file mode 100644
index 0000000000000..755124b97a5ac
--- /dev/null
+++ b/libcxx/include/__cxx03/__verbose_trap
@@ -0,0 +1,36 @@
+// -*- 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___CXX03___VERBOSE_TRAP
+#define _LIBCPP___CXX03___VERBOSE_TRAP
+
+#include <__cxx03/__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if __has_builtin(__builtin_verbose_trap)
+// AppleClang shipped a slightly
diff erent version of __builtin_verbose_trap from the upstream
+// version before upstream Clang actually got the builtin.
+// TODO: Remove once AppleClang supports the two-arguments version of the builtin.
+# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700
+# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap(message)
+# else
+# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap("libc++", message)
+# endif
+#else
+# define _LIBCPP_VERBOSE_TRAP(message) ((void)message, __builtin_trap())
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CXX03___VERBOSE_TRAP
diff --git a/libcxx/include/__verbose_trap b/libcxx/include/__verbose_trap
new file mode 100644
index 0000000000000..13ea727738c3b
--- /dev/null
+++ b/libcxx/include/__verbose_trap
@@ -0,0 +1,36 @@
+// -*- 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___VERBOSE_TRAP
+#define _LIBCPP___VERBOSE_TRAP
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if __has_builtin(__builtin_verbose_trap)
+// AppleClang shipped a slightly
diff erent version of __builtin_verbose_trap from the upstream
+// version before upstream Clang actually got the builtin.
+// TODO: Remove once AppleClang supports the two-arguments version of the builtin.
+# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700
+# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap(message)
+# else
+# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap("libc++", message)
+# endif
+#else
+# define _LIBCPP_VERBOSE_TRAP(message) ((void)message, __builtin_trap())
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___VERBOSE_TRAP
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 45b9c72a05b82..61ba1c381b2b3 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -2356,6 +2356,9 @@ module std [system] {
module verbose_abort {
header "__verbose_abort"
}
+ module verbose_trap {
+ header "__verbose_trap"
+ }
module internal_assert {
header "__assert"
export *
diff --git a/libcxx/vendor/llvm/default_assertion_handler.in b/libcxx/vendor/llvm/default_assertion_handler.in
index 1d6b21fc6bb45..f115658f9f3c6 100644
--- a/libcxx/vendor/llvm/default_assertion_handler.in
+++ b/libcxx/vendor/llvm/default_assertion_handler.in
@@ -13,9 +13,11 @@
#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
# include <__cxx03/__config>
# include <__cxx03/__verbose_abort>
+# include <__cxx03/__verbose_trap>
#else
# include <__config>
# include <__verbose_abort>
+# include <__verbose_trap>
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -28,18 +30,7 @@
#else
-# if __has_builtin(__builtin_verbose_trap)
-// AppleClang shipped a slightly
diff erent version of __builtin_verbose_trap from the upstream
-// version before upstream Clang actually got the builtin.
-// TODO: Remove once AppleClang supports the two-arguments version of the builtin.
-# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700
-# define _LIBCPP_ASSERTION_HANDLER(message) __builtin_verbose_trap(message)
-# else
-# define _LIBCPP_ASSERTION_HANDLER(message) __builtin_verbose_trap("libc++", message)
-# endif
-# else
-# define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __builtin_trap())
-# endif
+# define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_TRAP(message)
#endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
More information about the libcxx-commits
mailing list