2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___ASSERT
11 #define _LIBCPP___ASSERT
14 #include <__verbose_abort>
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 # pragma GCC system_header
20 #define _LIBCPP_ASSERT(expression, message) \
21 (__builtin_expect(static_cast<bool>(expression), 1) \
23 : _LIBCPP_VERBOSE_ABORT( \
24 "%s:%d: assertion %s failed: %s\n", __builtin_FILE(), __builtin_LINE(), #expression, message))
26 // TODO: __builtin_assume can currently inhibit optimizations. Until this has been fixed and we can add
27 // assumptions without a clear optimization intent, disable that to avoid worsening the code generation.
28 // See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a discussion.
29 #if 0 && __has_builtin(__builtin_assume)
30 # define _LIBCPP_ASSUME(expression) \
31 (_LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \
32 __builtin_assume(static_cast<bool>(expression)) _LIBCPP_DIAGNOSTIC_POP)
34 # define _LIBCPP_ASSUME(expression) ((void)0)
37 #endif // _LIBCPP___ASSERT