[libcxx-commits] [libcxx] 0a77e63 - [libcxx] Add flag to disable __builtin_assume in _LIBCPP_ASSERT
Arthur Eubanks via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Apr 7 09:03:21 PDT 2022
Author: Arthur Eubanks
Date: 2022-04-07T09:00:31-07:00
New Revision: 0a77e633226b5598e426603c03e54d62ed275670
URL: https://github.com/llvm/llvm-project/commit/0a77e633226b5598e426603c03e54d62ed275670
DIFF: https://github.com/llvm/llvm-project/commit/0a77e633226b5598e426603c03e54d62ed275670.diff
LOG: [libcxx] Add flag to disable __builtin_assume in _LIBCPP_ASSERT
Introduce _LIBCPP_ASSERTIONS_DISABLE_ASSUME which makes _LIBCPP_ASSERT
not call __builtin_assume when _LIBCPP_ENABLE_ASSERTIONS == 0.
Calling __builtin_assume was introduced in D122397.
__builtin_assume is generally supposed to improve optimizations, but can
cause regressions when LLVM has trouble handling the calls to
`llvm.assume()` (see comments in D122397).
Reviewed By: philnik
Differential Revision: https://reviews.llvm.org/D123175
Added:
Modified:
libcxx/include/__assert
libcxx/test/libcxx/assertions/single_expression.sh.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__assert b/libcxx/include/__assert
index cb397e41980f5..a9096d92bb888 100644
--- a/libcxx/include/__assert
+++ b/libcxx/include/__assert
@@ -38,16 +38,14 @@
(__builtin_expect(static_cast<bool>(expression), 1) ? \
(void)0 : \
::std::__libcpp_assertion_handler(__FILE__, __LINE__, #expression, message))
+#elif !defined(_LIBCPP_ASSERTIONS_DISABLE_ASSUME) && __has_builtin(__builtin_assume)
+# define _LIBCPP_ASSERT(expression, message) \
+ (_LIBCPP_DIAGNOSTIC_PUSH \
+ _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \
+ __builtin_assume(static_cast<bool>(expression)) \
+ _LIBCPP_DIAGNOSTIC_POP)
#else
-# if __has_builtin(__builtin_assume)
-# define _LIBCPP_ASSERT(expression, message) \
- (_LIBCPP_DIAGNOSTIC_PUSH \
- _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \
- __builtin_assume(static_cast<bool>(expression)) \
- _LIBCPP_DIAGNOSTIC_POP)
-# else
-# define _LIBCPP_ASSERT(expression, message) ((void)0)
-# endif
+# define _LIBCPP_ASSERT(expression, message) ((void)0)
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
diff --git a/libcxx/test/libcxx/assertions/single_expression.sh.cpp b/libcxx/test/libcxx/assertions/single_expression.sh.cpp
index 76635d6a7e61f..fb661103b6de6 100644
--- a/libcxx/test/libcxx/assertions/single_expression.sh.cpp
+++ b/libcxx/test/libcxx/assertions/single_expression.sh.cpp
@@ -15,6 +15,9 @@
// RUN: %{build} -Wno-macro-redefined -D_LIBCPP_ENABLE_ASSERTIONS=0
// RUN: %{run}
+// RUN: %{build} -Wno-macro-redefined -D_LIBCPP_ENABLE_ASSERTIONS=0 -D_LIBCPP_ASSERTIONS_DISABLE_ASSUME
+// RUN: %{run}
+
// We flag uses of the assertion handler in older dylibs at compile-time to avoid runtime
// failures when back-deploying.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0|12.0}}
More information about the libcxx-commits
mailing list