Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ add_header_library(
DEPENDS
.integer_to_string
libc.src.__support.OSUtil.osutil
libc.src.__support.macros.optimization
)

add_header_library(
Expand Down
5 changes: 3 additions & 2 deletions libc/src/__support/libc_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include "src/__support/OSUtil/exit.h"
#include "src/__support/OSUtil/io.h"
#include "src/__support/integer_to_string.h"
#include "src/__support/macros/attributes.h" // For LIBC_INLINE
#include "src/__support/macros/attributes.h" // For LIBC_INLINE
#include "src/__support/macros/optimization.h" // For LIBC_UNLIKELY

namespace LIBC_NAMESPACE_DECL {

Expand Down Expand Up @@ -71,7 +72,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: '"); \
Expand Down
16 changes: 13 additions & 3 deletions libc/src/assert/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@
#ifdef NDEBUG
#define assert(e) (void)0
#else

#ifdef __has_builtin
#if __has_builtin(__builtin_expect)
#define __LIBC_ASSERT_LIKELY(e) __builtin_expect(e, 1)
#endif
#endif
#ifndef __LIBC_ASSERT_LIKELY
#define __LIBC_ASSERT_LIKELY(e) e
#endif

#define assert(e) \
((e) ? (void)0 \
: LIBC_NAMESPACE::__assert_fail(#e, __FILE__, __LINE__, \
__PRETTY_FUNCTION__))
(__LIBC_ASSERT_LIKELY(e) ? (void)0 \
: LIBC_NAMESPACE::__assert_fail( \
#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
#endif // NDEBUG