[libcxx-commits] [PATCH] D153968: [libc++] Stop using __builtin_assume in _LIBCPP_ASSERT

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 29 14:01:24 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7c63c0e90a9: [libc++] Stop using __builtin_assume in _LIBCPP_ASSERT (authored by ldionne).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153968/new/

https://reviews.llvm.org/D153968

Files:
  libcxx/include/__assert
  libcxx/src/filesystem/posix_compat.h


Index: libcxx/src/filesystem/posix_compat.h
===================================================================
--- libcxx/src/filesystem/posix_compat.h
+++ libcxx/src/filesystem/posix_compat.h
@@ -383,7 +383,7 @@
 
 inline wchar_t *getcwd(wchar_t *buff, size_t size) { return _wgetcwd(buff, size); }
 
-inline wchar_t *realpath(const wchar_t *path, wchar_t *resolved_name) {
+inline wchar_t *realpath(const wchar_t *path, [[maybe_unused]] wchar_t *resolved_name) {
   // Only expected to be used with us allocating the buffer.
   _LIBCPP_ASSERT_UNCATEGORIZED(resolved_name == nullptr,
                  "Windows realpath() assumes a null resolved_name");
Index: libcxx/include/__assert
===================================================================
--- libcxx/include/__assert
+++ libcxx/include/__assert
@@ -38,7 +38,10 @@
          ? (void)0                                                                                                     \
          : _LIBCPP_VERBOSE_ABORT(                                                                                      \
                "%s:%d: assertion %s failed: %s\n", __builtin_FILE(), __builtin_LINE(), #expression, message))
-#elif !defined(_LIBCPP_ASSERTIONS_DISABLE_ASSUME) && __has_builtin(__builtin_assume)
+// TODO: __builtin_assume can currently inhibit optimizations. Until this has been fixed and we can add
+//       assumptions without a clear optimization intent, disable that to avoid worsening the code generation.
+//       See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a discussion.
+#elif 0 && __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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153968.535990.patch
Type: text/x-patch
Size: 1957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230629/b86fc760/attachment.bin>


More information about the libcxx-commits mailing list