[libcxx-commits] [libcxx] [libcxx] add Android assertion handler (PR #198831)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jun 5 07:24:14 PDT 2026
================
@@ -0,0 +1,58 @@
+// -*- 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_ANDROID_ASSERTION_HANDLER
+#define __LIBCPP_ANDROID_ASSERTION_HANDLER
+
+#include <__config>
+#include <__log_hardening_failure>
+#include <__verbose_abort>
+#include <__verbose_trap>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#if _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_IGNORE
+# define _LIBCPP_ASSERTION_HANDLER(message) ((void)0)
+
+#elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_OBSERVE
+# define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_LOG_HARDENING_FAILURE(message)
+
+#elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE
+
+// Require `nomerge` for better crash attribution.
+# define _LIBCPP_ASSERTION_HANDLER(message) \
+ ({ [[clang::nomerge]] _LIBCPP_VERBOSE_TRAP(message); })
----------------
ldionne wrote:
I assume there's a code-size impact for using `nomerge` since what might have previously been a single call would now be multiple calls? Has that impact been quantified? I think this is fairly important since it could potentially have a noticeable impact on a bunch of code that has turned this on by default already.
https://github.com/llvm/llvm-project/pull/198831
More information about the libcxx-commits
mailing list