[libcxx-commits] [libcxx] [libc++][hardening] Use `__builtin_verbose_trap` if it's available. (PR #84870)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 9 11:30:08 PDT 2024


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/84870

>From ea44facce3c00321cfae9da00835dec0ca5792e4 Mon Sep 17 00:00:00 2001
From: Konstantin Varlamov <varconst at apple.com>
Date: Mon, 11 Mar 2024 21:46:39 -0700
Subject: [PATCH] [libc++][hardening] Use `__builtin_verbose_trap` if it's
 available.

Keep falling back to `__builtin_trap` on older versions of Clang.
---
 libcxx/vendor/llvm/default_assertion_handler.in | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libcxx/vendor/llvm/default_assertion_handler.in b/libcxx/vendor/llvm/default_assertion_handler.in
index 8bc0553c078b3..8b892ff7b565e 100644
--- a/libcxx/vendor/llvm/default_assertion_handler.in
+++ b/libcxx/vendor/llvm/default_assertion_handler.in
@@ -23,8 +23,11 @@
 
 #else
 
-// TODO(hardening): use `__builtin_verbose_trap(message)` once that becomes available.
-#  define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __builtin_trap())
+#  if __has_builtin(__builtin_verbose_trap)
+#    define _LIBCPP_ASSERTION_HANDLER(message) (__builtin_verbose_trap(message))
+#  else
+#    define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __builtin_trap())
+#  endif
 
 #endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
 



More information about the libcxx-commits mailing list