Skip to content

Commit 4d5aa22

Browse files
committed
[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 emscripten-core/emscripten#24543
1 parent 2ab83e9 commit 4d5aa22

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

libcxx/include/__assert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#define _LIBCPP_ASSERT(expression, message) \
2121
(__builtin_expect(static_cast<bool>(expression), 1) \
2222
? (void)0 \
23-
: _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING( \
24-
expression) " failed: " message "\n"))
23+
: _LIBCPP_ASSERTION_HANDLER( \
24+
__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING(expression) " failed: " message))
2525

2626
// WARNING: __builtin_assume can currently inhibit optimizations. Only add assumptions with a clear
2727
// optimization intent. See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a

libcxx/src/verbose_abort.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ _LIBCPP_WEAK void __libcpp_verbose_abort(char const* format, ...) noexcept {
3030
va_list list;
3131
va_start(list, format);
3232
std::vfprintf(stderr, format, list);
33+
// Callers of `__libcpp_verbose_abort` do not include a newline but when
34+
// writing the message to stderr we need to include one.
35+
std::fputc('\n', stderr);
3336
va_end(list);
3437
}
3538

libcxx/test/support/check_assertion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void std::__libcpp_verbose_abort(char const* format, ...) noexcept {
340340

341341
std::fprintf(stderr, "%s\n", Marker);
342342
std::vfprintf(stderr, format, args);
343-
std::fprintf(stderr, "%s", Marker);
343+
std::fprintf(stderr, "\n%s", Marker);
344344

345345
va_end(args);
346346

0 commit comments

Comments
 (0)