[libcxx-commits] [libcxx] [libcxx] add Android assertion handler (PR #198831)
George Burgess IV via libcxx-commits
libcxx-commits at lists.llvm.org
Wed May 27 16:47:18 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); })
+
+#elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_ENFORCE
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// Calling this saves code size compared to
+// `__libcpp_verbose_abort("%s", "error message")`.
+[[__noreturn__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_NOINLINE
----------------
gburgessiv wrote:
> HIDE_FROM_ABI isn't required anymore in most places
Ack, Android did really want this to be hidden (in part to avoid runtime relocation costs, in part because there are some... interesting CI setups), so I assume _LIBCPP_HIDDEN would be more appropriate to require that?
> and noinline should be fully redundant with noreturn. .
Right, the inliner should assume `noreturn` is incredibly cold, so _generally_ shouldn't inline it. Happy to remove NOINLINE until there's a practical example of what it prevents.
Though it's irrelevant here, I'm a bit surprised that Clang refuses to inline single-use `static` noreturn functions that would bloat the caller, but I suppose that's a fringe enough edge-case.
https://github.com/llvm/llvm-project/pull/198831
More information about the libcxx-commits
mailing list