[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:08 PDT 2024
https://github.com/goldsteinn created https://github.com/llvm/llvm-project/pull/99498
None
>From 709a7f16d5b9335ca49401db087495b0b9358651 Mon Sep 17 00:00:00 2001
From: Noah Goldstein <goldstein.w.n at gmail.com>
Date: Thu, 18 Jul 2024 22:26:47 +0800
Subject: [PATCH] [libc] Add `__builtin_expect` tag on assert conditions; NFC
---
libc/src/__support/libc_assert.h | 2 +-
libc/src/assert/assert.h | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
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
More information about the libc-commits
mailing list