[libcxx-commits] [libcxx] WIP [libc++][hardening] Overhaul the termination mechanism for hardening (PR #77823)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 11 13:46:24 PST 2024


================
@@ -12,17 +12,40 @@
 
 #include <__config>
 #include <__verbose_abort>
+#include <__verbose_trap>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
 
+// _LIBCPP_ASSERT_IMPL
+
+#if defined(_LIBCPP_VERBOSE_TRAP_IMPL_OVERRIDE)
+
+#define _LIBCPP_ASSERT_IMPL(error_message, ...) _LIBCPP_VERBOSE_TRAP_IMPL_OVERRIDE(__VA_ARGS__)
+
+#elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
+
+#define _LIBCPP_ASSERT_IMPL(error_message, ...) ((void)error_message, _LIBCPP_VERBOSE_ABORT(__VA_ARGS__))
+
+#else
+
+void __use(const char*, ...);
+#define _LIBCPP_ASSERT_IMPL(error_message, ...) (decltype(__use(__VA_ARGS__))(), _LIBCPP_VERBOSE_TRAP(error_message))
+
+#endif
+
+// _LIBCPP_ASSERT
----------------
ldionne wrote:

We should add a bit of documentation here that explains that `_LIBCPP_ASSERT(expr, msg)` is a no-op if `expr` is true, and it's library-level UB in case `expr` is false.

https://github.com/llvm/llvm-project/pull/77823


More information about the libcxx-commits mailing list