Skip to content

release/21.x: [libc++][hardening] Add a greppable prefix to assertion messages. (#150560) #151921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2025

Conversation

llvmbot
Copy link
Member

@llvmbot llvmbot commented Aug 4, 2025

Backport 4ef9246

Requested by: @var-const

@llvmbot llvmbot requested a review from a team as a code owner August 4, 2025 08:50
@llvmbot llvmbot added this to the LLVM 21.x Release milestone Aug 4, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Aug 4, 2025
@llvmbot
Copy link
Member Author

llvmbot commented Aug 4, 2025

@var-const What do you think about merging this PR to the release branch?

@llvmbot llvmbot requested a review from var-const August 4, 2025 08:50
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Aug 4, 2025
@llvmbot
Copy link
Member Author

llvmbot commented Aug 4, 2025

@llvm/pr-subscribers-libcxx

Author: None (llvmbot)

Changes

Backport 4ef9246

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 --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);
 

@github-project-automation github-project-automation bot moved this from Needs Triage to Needs Merge in LLVM Release Status Aug 4, 2025
@var-const var-const added the hardening Issues related to the hardening effort label Aug 5, 2025
…vm#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.

(cherry picked from commit 4ef9246)
@tru tru merged commit 16bd92c into llvm:release/21.x Aug 5, 2025
1 check was pending
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status Aug 5, 2025
Copy link

github-actions bot commented Aug 5, 2025

@var-const (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hardening Issues related to the hardening effort libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
Development

Successfully merging this pull request may close these issues.

3 participants