[libcxx-commits] [libcxx] [libc++] Remove trailing newline from _LIBCPP_ASSERTION_HANDLER calls (PR #143573)
Sam Clegg via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jun 10 14:29:59 PDT 2025
https://github.com/sbc100 updated https://github.com/llvm/llvm-project/pull/143573
>From 40f48322f373269bf65fde14aadc09ecb6dad284 Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Tue, 10 Jun 2025 10:18:52 -0700
Subject: [PATCH] [libc++] Remove trailing newline from
_LIBCPP_ASSERTION_HANDLER calls
This newline was originally added in https://reviews.llvm.org/D142184
but I think updating `__libcpp_verbose_abort` to add newline instead
is more consistent, and works for other callers of
`_LIBCPP_VERBOSE_ABORT`.
The `_LIBCPP_ASSERTION_HANDLER` calls through to either
`_LIBCPP_VERBOSE_ABORT` macro or the `__builtin_verbose_trap`
>From what I can tell neither of these function expect a trailing
newline (At least non of the usage of `_LIBCPP_VERBOSE_ABORT` or
`__builtin_verbose_trap` that I can find include a trailing newline
except _LIBCPP_ASSERTION_HANDLER).
I noticed this discrepancy when working on
https://github.com/emscripten-core/emscripten/pull/24543
---
libcxx/include/__assert | 4 ++--
libcxx/include/__cxx03/__assert | 4 ++--
libcxx/src/verbose_abort.cpp | 3 +++
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/libcxx/include/__assert b/libcxx/include/__assert
index 90eaa6023587b..1bfed2890b79f 100644
--- a/libcxx/include/__assert
+++ b/libcxx/include/__assert
@@ -20,8 +20,8 @@
#define _LIBCPP_ASSERT(expression, message) \
(__builtin_expect(static_cast<bool>(expression), 1) \
? (void)0 \
- : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING( \
- expression) " failed: " message "\n"))
+ : _LIBCPP_ASSERTION_HANDLER( \
+ __FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING(expression) " failed: " message))
// WARNING: __builtin_assume can currently inhibit optimizations. Only add assumptions with a clear
// optimization intent. See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a
diff --git a/libcxx/include/__cxx03/__assert b/libcxx/include/__cxx03/__assert
index f6c4d8e4a5d09..f1027866b9622 100644
--- a/libcxx/include/__cxx03/__assert
+++ b/libcxx/include/__cxx03/__assert
@@ -20,8 +20,8 @@
#define _LIBCPP_ASSERT(expression, message) \
(__builtin_expect(static_cast<bool>(expression), 1) \
? (void)0 \
- : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING( \
- expression) " failed: " message "\n"))
+ : _LIBCPP_ASSERTION_HANDLER( \
+ __FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING(expression) " failed: " message))
// TODO: __builtin_assume can currently inhibit optimizations. Until this has been fixed and we can add
// assumptions without a clear optimization intent, disable that to avoid worsening the code generation.
diff --git a/libcxx/src/verbose_abort.cpp b/libcxx/src/verbose_abort.cpp
index 94bdb451dee7a..92466a2fb62f6 100644
--- a/libcxx/src/verbose_abort.cpp
+++ b/libcxx/src/verbose_abort.cpp
@@ -30,6 +30,9 @@ _LIBCPP_WEAK void __libcpp_verbose_abort(char const* format, ...) noexcept {
va_list list;
va_start(list, format);
std::vfprintf(stderr, format, list);
+ // Callers of `__libcpp_verbose_abort` do not include a newline but when
+ // writing the message to stderr we need to include one.
+ std::fputs(stderr, "\n");
va_end(list);
}
More information about the libcxx-commits
mailing list