[libc-commits] [libc] [libc] Add `__builtin_expect` tag on assert conditions; NFC (PR #99498)

via libc-commits libc-commits at lists.llvm.org
Thu Jul 18 07:28:40 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: None (goldsteinn)

<details>
<summary>Changes</summary>



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


2 Files Affected:

- (modified) libc/src/__support/libc_assert.h (+1-1) 
- (modified) libc/src/assert/assert.h (+3-3) 


``````````diff
diff --git a/libc/src/__support/libc_assert.h b/libc/src/__support/libc_assert.h
index e3235199780c2..8bbd06c14fb66 100644
--- a/libc/src/__support/libc_assert.h
+++ b/libc/src/__support/libc_assert.h
@@ -71,7 +71,7 @@ LIBC_INLINE void report_assertion_failure(const char *assertion,
 
 #define LIBC_ASSERT(COND)                                                      \
   do {                                                                         \
-    if (!(COND)) {                                                             \
+    if (LIBC_UNLIKELY(!(COND))) {                                              \
       LIBC_NAMESPACE::write_to_stderr(__FILE__ ":" __LIBC_LINE_STR__           \
                                                ": Assertion failed: '" #COND   \
                                                "' in function: '");            \
diff --git a/libc/src/assert/assert.h b/libc/src/assert/assert.h
index 6f352af1988b3..a1104a79bfc3e 100644
--- a/libc/src/assert/assert.h
+++ b/libc/src/assert/assert.h
@@ -19,7 +19,7 @@
 #define assert(e) (void)0
 #else
 #define assert(e)                                                              \
-  ((e) ? (void)0                                                               \
-       : LIBC_NAMESPACE::__assert_fail(#e, __FILE__, __LINE__,                 \
-                                       __PRETTY_FUNCTION__))
+  (LIBC_LIKELY(e) ? (void)0                                                    \
+                  : LIBC_NAMESPACE::__assert_fail(#e, __FILE__, __LINE__,      \
+                                                  __PRETTY_FUNCTION__))
 #endif // NDEBUG

``````````

</details>


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


More information about the libc-commits mailing list