[libc++][hardening] Add a greppable prefix to assertion messages. (#150560)

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.
This commit is contained in:
Konstantin Varlamov 2025-07-31 02:52:17 -07:00 committed by GitHub
parent 6540c93aa9
commit 4ef92469ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -20,8 +20,8 @@
#define _LIBCPP_ASSERT(expression, message) \ #define _LIBCPP_ASSERT(expression, message) \
(__builtin_expect(static_cast<bool>(expression), 1) \ (__builtin_expect(static_cast<bool>(expression), 1) \
? (void)0 \ ? (void)0 \
: _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING( \ : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING( \
expression) " failed: " message "\n")) __LINE__) ": libc++ Hardening assertion " _LIBCPP_TOSTRING(expression) " failed: " message "\n"))
// WARNING: __builtin_assume can currently inhibit optimizations. Only add assumptions with a clear // 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 // optimization intent. See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a

View File

@ -52,8 +52,8 @@ MatchResult MatchAssertionMessage(const std::string& text, std::string_view expe
// library. // library.
std::string assertion_format_string = [&] { std::string assertion_format_string = [&] {
if (use_marker) if (use_marker)
return (".*###\\n(.*):(\\d+): assertion (.*) failed: (.*)\\n###"); return (".*###\\n(.*):(\\d+): libc\\+\\+ Hardening assertion (.*) failed: (.*)\\n###");
return ("(.*):(\\d+): assertion (.*) failed: (.*)\\n"); return ("(.*):(\\d+): libc\\+\\+ Hardening assertion (.*) failed: (.*)\\n");
}(); }();
std::regex assertion_format(assertion_format_string); std::regex assertion_format(assertion_format_string);