-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Add __builtin_expect
tag on assert conditions; NFC
#99498
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
[libc] Add __builtin_expect
tag on assert conditions; NFC
#99498
Conversation
@llvm/pr-subscribers-libc Author: None (goldsteinn) ChangesFull diff: https://github.com/llvm/llvm-project/pull/99498.diff 2 Files Affected:
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember discussing something similar with @AaronBallman about adding __builtin_assume
to the assert macros. I think the answer then was that the C standard specifies exactly what assert
should look like so we can't change it? I think LIBC_ASSERT
probably should though.
|
Was the response I got earlier, but I guess that only applies to making |
Yeah, I think this is okay. One thing I did note when I reviewed the code is that the definition of |
709a7f1
to
c2c7943
Compare
Whats the status of this PR? Looks like it's good to go? |
Still waiting on approval. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/196/builds/119 Here is the relevant piece of the build log for the reference
|
No description provided.