[llvm-branch-commits] [libcxx] release/21.x: [libc++][hardening] Add a greppable prefix to assertion messages. (#150560) (PR #151921)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 4 01:50:57 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: None (llvmbot)

<details>
<summary>Changes</summary>

Backport 4ef92469ab341ac1bee39a9413ffaa845e307414

Requested by: @<!-- -->var-const

---
Full diff: https://github.com/llvm/llvm-project/pull/151921.diff


2 Files Affected:

- (modified) libcxx/include/__assert (+2-2) 
- (modified) libcxx/test/support/check_assertion.h (+2-2) 


``````````diff
diff --git a/libcxx/include/__assert b/libcxx/include/__assert
index 90eaa6023587b..a9451daf47f2f 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__) ": libc++ Hardening assertion " _LIBCPP_TOSTRING(expression) " failed: " message "\n"))
 
 // 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/test/support/check_assertion.h b/libcxx/test/support/check_assertion.h
index a091043195345..8416de76cfd61 100644
--- a/libcxx/test/support/check_assertion.h
+++ b/libcxx/test/support/check_assertion.h
@@ -52,8 +52,8 @@ MatchResult MatchAssertionMessage(const std::string& text, std::string_view expe
   // library.
   std::string assertion_format_string = [&] {
     if (use_marker)
-      return (".*###\\n(.*):(\\d+): assertion (.*) failed: (.*)\\n###");
-    return ("(.*):(\\d+): assertion (.*) failed: (.*)\\n");
+      return (".*###\\n(.*):(\\d+): libc\\+\\+ Hardening assertion (.*) failed: (.*)\\n###");
+    return ("(.*):(\\d+): libc\\+\\+ Hardening assertion (.*) failed: (.*)\\n");
   }();
   std::regex assertion_format(assertion_format_string);
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/151921


More information about the llvm-branch-commits mailing list