[libcxx-commits] [libcxx] DRAFT [libc++][hardening] In production hardening modes, trap rather than abort (PR #78497)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 17 12:05:18 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 4f215fdd62d3f014750339eab9a46946b6fb1c4a 679718ac48a5d78bfdcae090f87c08fe4108d118 -- libcxx/include/__assert libcxx/include/__memory/assume_aligned.h libcxx/src/include/to_chars_floating_point.h libcxx/src/memory_resource.cpp libcxx/test/libcxx/assertions/modes/enabling_assertions_enables_extensive_mode.pass.cpp libcxx/test/libcxx/assertions/modes/override_with_debug_mode.pass.cpp libcxx/test/libcxx/assertions/modes/override_with_extensive_mode.pass.cpp libcxx/test/libcxx/assertions/modes/override_with_fast_mode.pass.cpp libcxx/test/libcxx/assertions/modes/override_with_unchecked_mode.pass.cpp libcxx/test/libcxx/containers/sequences/deque/asan_caterpillar.pass.cpp libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.modifying.operations/alg.move/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.nonmodifying/alg.all_of/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.nonmodifying/alg.any_of/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.nonmodifying/alg.find/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.nonmodifying/alg.none_of/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.sorting/alg.merge/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/numeric.ops/reduce/pstl.exception_handling.pass.cpp libcxx/test/std/algorithms/numeric.ops/transform.reduce/pstl.exception_handling.pass.cpp libcxx/test/support/check_assertion.h
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/test/support/check_assertion.h b/libcxx/test/support/check_assertion.h
index 6534196956..bbe5027af4 100644
--- a/libcxx/test/support/check_assertion.h
+++ b/libcxx/test/support/check_assertion.h
@@ -58,9 +58,7 @@ struct AssertionInfoMatcher {
   }
 
   bool empty() const { return is_empty_; }
-  bool IsAnyMatcher() const {
-    return msg_ == any_msg && file_ == any_file && line_ == any_line;
-  }
+  bool IsAnyMatcher() const { return msg_ == any_msg && file_ == any_file && line_ == any_line; }
 
 private:
   bool CheckLineMatches(int got_line) const {
@@ -275,11 +273,7 @@ void std::__libcpp_verbose_abort(char const* message, ...) {
   std::exit(DeathTest::RK_Terminate);
 }
 
-enum class DeathCause {
-  VerboseAbort,
-  StdTerminate,
-  HardeningAssertion
-};
+enum class DeathCause { VerboseAbort, StdTerminate, HardeningAssertion };
 
 template <class Func>
 inline bool ExpectDeath(DeathCause expected_cause, const char* stmt, Func&& func, AssertionInfoMatcher matcher) {
@@ -310,15 +304,15 @@ inline bool ExpectDeath(DeathCause expected_cause, const char* stmt, Func&& func
 
   case DeathTest::RK_Trap:
     switch (expected_cause) {
-  case DeathCause::HardeningAssertion:
+    case DeathCause::HardeningAssertion:
 #if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
-    return true;
+      return true;
 #else
-    return OnFailure("The process has trapped but was expected to invoke verbose abort.");
+      return OnFailure("The process has trapped but was expected to invoke verbose abort.");
 #endif
-  case DeathCause::VerboseAbort:
+    case DeathCause::VerboseAbort:
       return OnFailure("The process has trapped but was expected to invoke verbose abort.");
-  case DeathCause::StdTerminate:
+    case DeathCause::StdTerminate:
       return OnFailure("The process has trapped but was expected to call `std::terminate`.");
     }
 
@@ -341,10 +335,15 @@ inline bool ExpectDeath(DeathCause expected_cause, const char* stmt, Func&& func
 }
 
 /// Assert that the specified expression aborts.
-#define EXPECT_DEATH(...) /*            */ assert((ExpectDeath(DeathCause::VerboseAbort, #__VA_ARGS__, [&]() { __VA_ARGS__; } )))
-#define EXPECT_DEATH_MATCHES(matcher, ...) assert((ExpectDeath(DeathCause::VerboseAbort, #__VA_ARGS__, [&]() { __VA_ARGS__; }, matcher)))
+#define EXPECT_DEATH(...) /*            */                                                                             \
+  assert((ExpectDeath(DeathCause::VerboseAbort, #__VA_ARGS__, [&]() { __VA_ARGS__; })))
+#define EXPECT_DEATH_MATCHES(matcher, ...)                                                                             \
+  assert((ExpectDeath(                                                                                                 \
+      DeathCause::VerboseAbort, #__VA_ARGS__, [&]() { __VA_ARGS__; }, matcher)))
 #define EXPECT_STD_TERMINATE(...) /*    */ assert(ExpectDeath(DeathCause::StdTerminate, #__VA_ARGS__, __VA_ARGS__))
 
-#define TEST_LIBCPP_ASSERT_FAILURE(expr, message) assert((ExpectDeath(DeathCause::HardeningAssertion, #expr, [&]() { (void)(expr); }, AssertionInfoMatcher(message))))
+#define TEST_LIBCPP_ASSERT_FAILURE(expr, message)                                                                      \
+  assert((ExpectDeath(                                                                                                 \
+      DeathCause::HardeningAssertion, #expr, [&]() { (void)(expr); }, AssertionInfoMatcher(message))))
 
 #endif // TEST_SUPPORT_CHECK_ASSERTION_H

``````````

</details>


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


More information about the libcxx-commits mailing list