Skip to content

Commit b0c645f

Browse files
committed
[libc++][hardening] Add a greppable prefix to assertion messages.
The current assertion failure messages produced by Hardening are not very grep-friendly (the common part is rarther generic and requires wildcards to match). While it's possible to use `__FILE__` for grepping, it's easier and more straighforward to simply add a libc++-specific prefix; this is especially important for the planned `observe` mode that might produce many assertion failure messages over the course of the program's execution that later need to be filtered and examined.
1 parent d750c6d commit b0c645f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-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(__FILE__ ":" _LIBCPP_TOSTRING( \
24+
__LINE__) ": libc++ Hardening assertion " _LIBCPP_TOSTRING(expression) " failed: " message "\n"))
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/test/support/check_assertion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ using Matcher = std::function<MatchResult(const std::string& /*text*/)>;
4747
MatchResult MatchAssertionMessage(const std::string& text, std::string_view expected_message) {
4848
// Extract information from the error message. This has to stay synchronized with how we format assertions in the
4949
// library.
50-
std::regex assertion_format(".*###\\n(.*):(\\d+): assertion (.*) failed: (.*)\\n###");
50+
std::regex assertion_format(".*###\\n(.*):(\\d+): libc\\+\\+ Hardening assertion (.*) failed: (.*)\\n###");
5151

5252
std::smatch match_result;
5353
bool has_match = std::regex_match(text, match_result, assertion_format);

0 commit comments

Comments
 (0)