comparison libcxx/include/__assert @ 252:1f2b6ac9f198 llvm-original

LLVM16-1
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 18 Aug 2023 09:04:13 +0900
parents c4bab56944e8
children
comparison
equal deleted inserted replaced
237:c80f45b162ad 252:1f2b6ac9f198
15 15
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 # pragma GCC system_header 17 # pragma GCC system_header
18 #endif 18 #endif
19 19
20 // This is for backwards compatibility with code that might have been enabling 20 #define _LIBCPP_ASSERT(expression, message) \
21 // assertions through the Debug mode previously. 21 (__builtin_expect(static_cast<bool>(expression), 1) \
22 // TODO: In LLVM 16, make it an error to define _LIBCPP_DEBUG 22 ? (void)0 \
23 #if defined(_LIBCPP_DEBUG) 23 : _LIBCPP_VERBOSE_ABORT( \
24 # ifndef _LIBCPP_ENABLE_ASSERTIONS 24 "%s:%d: assertion %s failed: %s\n", __builtin_FILE(), __builtin_LINE(), #expression, message))
25 # define _LIBCPP_ENABLE_ASSERTIONS 1
26 # endif
27 #endif
28 25
29 // Automatically enable assertions when the debug mode is enabled. 26 // TODO: __builtin_assume can currently inhibit optimizations. Until this has been fixed and we can add
30 #if defined(_LIBCPP_ENABLE_DEBUG_MODE) 27 // assumptions without a clear optimization intent, disable that to avoid worsening the code generation.
31 # ifndef _LIBCPP_ENABLE_ASSERTIONS 28 // See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a discussion.
32 # define _LIBCPP_ENABLE_ASSERTIONS 1 29 #if 0 && __has_builtin(__builtin_assume)
33 # endif 30 # define _LIBCPP_ASSUME(expression) \
34 #endif 31 (_LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \
35 32 __builtin_assume(static_cast<bool>(expression)) _LIBCPP_DIAGNOSTIC_POP)
36 #ifndef _LIBCPP_ENABLE_ASSERTIONS
37 # define _LIBCPP_ENABLE_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS_DEFAULT
38 #endif
39
40 #if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1
41 # error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1"
42 #endif
43
44 #if _LIBCPP_ENABLE_ASSERTIONS
45 # define _LIBCPP_ASSERT(expression, message) \
46 (__builtin_expect(static_cast<bool>(expression), 1) ? \
47 (void)0 : \
48 ::std::__libcpp_verbose_abort("%s:%d: assertion %s failed: %s", __FILE__, __LINE__, #expression, message))
49 #elif !defined(_LIBCPP_ASSERTIONS_DISABLE_ASSUME) && __has_builtin(__builtin_assume)
50 # define _LIBCPP_ASSERT(expression, message) \
51 (_LIBCPP_DIAGNOSTIC_PUSH \
52 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \
53 __builtin_assume(static_cast<bool>(expression)) \
54 _LIBCPP_DIAGNOSTIC_POP)
55 #else 33 #else
56 # define _LIBCPP_ASSERT(expression, message) ((void)0) 34 # define _LIBCPP_ASSUME(expression) ((void)0)
57 #endif 35 #endif
58 36
59 #endif // _LIBCPP___ASSERT 37 #endif // _LIBCPP___ASSERT