Skip to content

[libc++] Refactor the configuration macros to being always defined #112094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

philnik777
Copy link
Contributor

This is a follow-up to #89178. This updates the <__config_site> macros.

Copy link

github-actions bot commented Oct 12, 2024

✅ With the latest revision this PR passed the Python code formatter.

Copy link

github-actions bot commented Oct 12, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@philnik777 philnik777 force-pushed the rename_config_macros branch from c44ba76 to 131d843 Compare October 16, 2024 09:09
@philnik777 philnik777 marked this pull request as ready for review October 18, 2024 15:49
@philnik777 philnik777 requested a review from a team as a code owner October 18, 2024 15:49
@llvmbot llvmbot added cmake Build system in general and CMake in particular libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. labels Oct 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 18, 2024

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

This is a follow-up to #89178. This updates the &lt;__config_site&gt; macros.


Patch is 335.08 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/112094.diff

210 Files Affected:

  • (modified) libcxx/CMakeLists.txt (+11-11)
  • (modified) libcxx/docs/DesignDocs/ThreadingSupportAPI.rst (+3-3)
  • (modified) libcxx/include/__algorithm/find.h (+3-3)
  • (modified) libcxx/include/__algorithm/lexicographical_compare.h (+3-3)
  • (modified) libcxx/include/__algorithm/sort.h (+2-2)
  • (modified) libcxx/include/__atomic/aliases.h (+1-1)
  • (modified) libcxx/include/__atomic/atomic_sync.h (+3-3)
  • (modified) libcxx/include/__chrono/convert_to_tm.h (+1-2)
  • (modified) libcxx/include/__chrono/formatter.h (+11-13)
  • (modified) libcxx/include/__chrono/high_resolution_clock.h (+1-1)
  • (modified) libcxx/include/__chrono/ostream.h (+4-4)
  • (modified) libcxx/include/__chrono/parser_std_format_spec.h (+2-2)
  • (modified) libcxx/include/__chrono/statically_widen.h (+3-3)
  • (modified) libcxx/include/__chrono/steady_clock.h (+1-1)
  • (modified) libcxx/include/__chrono/time_zone.h (+3-4)
  • (modified) libcxx/include/__chrono/time_zone_link.h (+3-3)
  • (modified) libcxx/include/__chrono/tzdb.h (+3-4)
  • (modified) libcxx/include/__chrono/tzdb_list.h (+3-4)
  • (modified) libcxx/include/__chrono/zoned_time.h (+3-4)
  • (modified) libcxx/include/__condition_variable/condition_variable.h (+4-4)
  • (modified) libcxx/include/__config (+11-14)
  • (modified) libcxx/include/__config_site.in (+11-11)
  • (modified) libcxx/include/__configuration/availability.h (+5-7)
  • (modified) libcxx/include/__filesystem/directory_entry.h (+2-2)
  • (modified) libcxx/include/__filesystem/directory_iterator.h (+2-2)
  • (modified) libcxx/include/__filesystem/operations.h (+2-2)
  • (modified) libcxx/include/__filesystem/path.h (+14-14)
  • (modified) libcxx/include/__filesystem/recursive_directory_iterator.h (+2-2)
  • (modified) libcxx/include/__format/concepts.h (+1-1)
  • (modified) libcxx/include/__format/format_arg_store.h (+2-2)
  • (modified) libcxx/include/__format/format_context.h (+8-8)
  • (modified) libcxx/include/__format/format_functions.h (+19-19)
  • (modified) libcxx/include/__format/format_parse_context.h (+1-1)
  • (modified) libcxx/include/__format/formatter_bool.h (+1-1)
  • (modified) libcxx/include/__format/formatter_char.h (+4-4)
  • (modified) libcxx/include/__format/formatter_floating_point.h (+4-4)
  • (modified) libcxx/include/__format/formatter_integral.h (+4-4)
  • (modified) libcxx/include/__format/formatter_output.h (+6-7)
  • (modified) libcxx/include/__format/formatter_string.h (+2-2)
  • (modified) libcxx/include/__format/parser_std_format_spec.h (+12-12)
  • (modified) libcxx/include/__format/unicode.h (+6-6)
  • (modified) libcxx/include/__format/write_escaped.h (+2-3)
  • (modified) libcxx/include/__functional/hash.h (+2-2)
  • (modified) libcxx/include/__fwd/fstream.h (+1-1)
  • (modified) libcxx/include/__fwd/ios.h (+1-1)
  • (modified) libcxx/include/__fwd/istream.h (+1-1)
  • (modified) libcxx/include/__fwd/ostream.h (+1-1)
  • (modified) libcxx/include/__fwd/sstream.h (+1-1)
  • (modified) libcxx/include/__fwd/streambuf.h (+1-1)
  • (modified) libcxx/include/__fwd/string.h (+5-5)
  • (modified) libcxx/include/__fwd/string_view.h (+2-2)
  • (modified) libcxx/include/__locale (+14-14)
  • (modified) libcxx/include/__locale_dir/locale_base_api.h (+3-1)
  • (modified) libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h (+4-4)
  • (modified) libcxx/include/__mbstate_t.h (+2-2)
  • (modified) libcxx/include/__memory/shared_ptr.h (+6-6)
  • (modified) libcxx/include/__memory_resource/synchronized_pool_resource.h (+4-4)
  • (modified) libcxx/include/__mutex/mutex.h (+2-2)
  • (modified) libcxx/include/__ostream/basic_ostream.h (+5-5)
  • (modified) libcxx/include/__ostream/print.h (+11-11)
  • (modified) libcxx/include/__random/random_device.h (+2-2)
  • (modified) libcxx/include/__ranges/istream_view.h (+1-1)
  • (modified) libcxx/include/__stop_token/atomic_unique_lock.h (+1-1)
  • (modified) libcxx/include/__stop_token/stop_callback.h (+2-2)
  • (modified) libcxx/include/__stop_token/stop_source.h (+2-2)
  • (modified) libcxx/include/__stop_token/stop_state.h (+2-2)
  • (modified) libcxx/include/__stop_token/stop_token.h (+2-2)
  • (modified) libcxx/include/__string/char_traits.h (+3-3)
  • (modified) libcxx/include/__support/xlocale/__posix_l_fallback.h (+5-5)
  • (modified) libcxx/include/__support/xlocale/__strtonum_fallback.h (+1-1)
  • (modified) libcxx/include/__thread/formatter.h (+2-2)
  • (modified) libcxx/include/__thread/id.h (+2-2)
  • (modified) libcxx/include/__thread/jthread.h (+2-2)
  • (modified) libcxx/include/__thread/support.h (+2-2)
  • (modified) libcxx/include/__thread/this_thread.h (+2-2)
  • (modified) libcxx/include/__thread/thread.h (+5-5)
  • (modified) libcxx/include/__thread/timed_backoff_policy.h (+2-2)
  • (modified) libcxx/include/__type_traits/is_integral.h (+1-1)
  • (modified) libcxx/include/barrier (+2-2)
  • (modified) libcxx/include/chrono (+3-4)
  • (modified) libcxx/include/codecvt (+6-6)
  • (modified) libcxx/include/complex (+3-3)
  • (modified) libcxx/include/condition_variable (+2-2)
  • (modified) libcxx/include/cstdlib (+1-1)
  • (modified) libcxx/include/deque (+1-1)
  • (modified) libcxx/include/format (+1-1)
  • (modified) libcxx/include/fstream (+2-2)
  • (modified) libcxx/include/future (+2-2)
  • (modified) libcxx/include/iomanip (+2-2)
  • (modified) libcxx/include/ios (+4-4)
  • (modified) libcxx/include/iosfwd (+3-3)
  • (modified) libcxx/include/iostream (+1-1)
  • (modified) libcxx/include/istream (+3-3)
  • (modified) libcxx/include/latch (+2-2)
  • (modified) libcxx/include/list (+1-1)
  • (modified) libcxx/include/locale (+21-21)
  • (modified) libcxx/include/mutex (+2-2)
  • (modified) libcxx/include/ostream (+2-2)
  • (modified) libcxx/include/print (+21-21)
  • (modified) libcxx/include/ranges (+1-1)
  • (modified) libcxx/include/regex (+17-17)
  • (modified) libcxx/include/semaphore (+2-2)
  • (modified) libcxx/include/shared_mutex (+2-2)
  • (modified) libcxx/include/sstream (+2-2)
  • (modified) libcxx/include/stdatomic.h (+1-1)
  • (modified) libcxx/include/stop_token (+2-2)
  • (modified) libcxx/include/streambuf (+3-3)
  • (modified) libcxx/include/string (+8-8)
  • (modified) libcxx/include/string_view (+2-2)
  • (modified) libcxx/include/syncstream (+10-10)
  • (modified) libcxx/include/thread (+2-2)
  • (modified) libcxx/include/vector (+2-2)
  • (modified) libcxx/include/version (+10-10)
  • (modified) libcxx/include/wchar.h (+2-2)
  • (modified) libcxx/modules/std.compat.cppm.in (+1-1)
  • (modified) libcxx/modules/std.compat/clocale.inc (+2-2)
  • (modified) libcxx/modules/std.compat/cstdlib.inc (+1-1)
  • (modified) libcxx/modules/std.compat/cwchar.inc (+2-2)
  • (modified) libcxx/modules/std.compat/cwctype.inc (+2-2)
  • (modified) libcxx/modules/std.cppm.in (+14-14)
  • (modified) libcxx/modules/std/atomic.inc (+1-1)
  • (modified) libcxx/modules/std/barrier.inc (+2-2)
  • (modified) libcxx/modules/std/chrono.inc (+8-12)
  • (modified) libcxx/modules/std/clocale.inc (+2-2)
  • (modified) libcxx/modules/std/codecvt.inc (+2-2)
  • (modified) libcxx/modules/std/complex.inc (+2-2)
  • (modified) libcxx/modules/std/condition_variable.inc (+2-2)
  • (modified) libcxx/modules/std/cstdlib.inc (+1-1)
  • (modified) libcxx/modules/std/cwchar.inc (+2-2)
  • (modified) libcxx/modules/std/cwctype.inc (+2-2)
  • (modified) libcxx/modules/std/filesystem.inc (+6-6)
  • (modified) libcxx/modules/std/format.inc (+5-5)
  • (modified) libcxx/modules/std/fstream.inc (+7-7)
  • (modified) libcxx/modules/std/future.inc (+2-2)
  • (modified) libcxx/modules/std/iomanip.inc (+2-2)
  • (modified) libcxx/modules/std/ios.inc (+3-3)
  • (modified) libcxx/modules/std/iosfwd.inc (+2-2)
  • (modified) libcxx/modules/std/iostream.inc (+3-3)
  • (modified) libcxx/modules/std/istream.inc (+4-4)
  • (modified) libcxx/modules/std/latch.inc (+2-2)
  • (modified) libcxx/modules/std/locale.inc (+2-2)
  • (modified) libcxx/modules/std/memory.inc (+2-2)
  • (modified) libcxx/modules/std/mutex.inc (+2-2)
  • (modified) libcxx/modules/std/ostream.inc (+5-5)
  • (modified) libcxx/modules/std/print.inc (+2-2)
  • (modified) libcxx/modules/std/random.inc (+1-1)
  • (modified) libcxx/modules/std/ranges.inc (+3-3)
  • (modified) libcxx/modules/std/regex.inc (+8-8)
  • (modified) libcxx/modules/std/semaphore.inc (+2-2)
  • (modified) libcxx/modules/std/shared_mutex.inc (+2-2)
  • (modified) libcxx/modules/std/spanstream.inc (+4-4)
  • (modified) libcxx/modules/std/sstream.inc (+6-6)
  • (modified) libcxx/modules/std/stop_token.inc (+2-2)
  • (modified) libcxx/modules/std/streambuf.inc (+3-3)
  • (modified) libcxx/modules/std/string.inc (+3-3)
  • (modified) libcxx/modules/std/string_view.inc (+1-1)
  • (modified) libcxx/modules/std/strstream.inc (+2-2)
  • (modified) libcxx/modules/std/syncstream.inc (+4-4)
  • (modified) libcxx/modules/std/thread.inc (+4-4)
  • (modified) libcxx/src/algorithm.cpp (+1-1)
  • (modified) libcxx/src/call_once.cpp (+5-5)
  • (modified) libcxx/src/chrono.cpp (+2-2)
  • (modified) libcxx/src/experimental/include/tzdb/tzdb_list_private.h (+6-6)
  • (modified) libcxx/src/filesystem/time_utils.h (+2-2)
  • (modified) libcxx/src/include/atomic_support.h (+4-4)
  • (modified) libcxx/src/include/config_elast.h (+1-1)
  • (modified) libcxx/src/ios.cpp (+1-1)
  • (modified) libcxx/src/ios.instantiations.cpp (+2-2)
  • (modified) libcxx/src/iostream.cpp (+10-10)
  • (modified) libcxx/src/locale.cpp (+94-94)
  • (modified) libcxx/src/memory.cpp (+3-3)
  • (modified) libcxx/src/memory_resource.cpp (+2-2)
  • (modified) libcxx/src/ostream.cpp (+2-2)
  • (modified) libcxx/src/print.cpp (+2-2)
  • (modified) libcxx/src/random_shuffle.cpp (+4-4)
  • (modified) libcxx/src/std_stream.h (+3-3)
  • (modified) libcxx/src/string.cpp (+13-13)
  • (modified) libcxx/src/system_error.cpp (+3-3)
  • (modified) libcxx/test/benchmarks/std_format_spec_string_unicode.bench.cpp (+2-2)
  • (modified) libcxx/test/benchmarks/std_format_spec_string_unicode_escape.bench.cpp (+2-2)
  • (modified) libcxx/test/libcxx/depr/depr.c.headers/extern_c.pass.cpp (+5-5)
  • (modified) libcxx/test/libcxx/feature_test_macro/ftm_metadata.sh.py (+2-2)
  • (modified) libcxx/test/libcxx/feature_test_macro/test_data.json (+2-3)
  • (modified) libcxx/test/libcxx/feature_test_macro/version_header.sh.py (+2-2)
  • (modified) libcxx/test/libcxx/feature_test_macro/version_header_implementation.sh.py (+2-2)
  • (modified) libcxx/test/libcxx/include_as_c.sh.cpp (+7-7)
  • (modified) libcxx/test/libcxx/vendor/apple/availability-with-pedantic-errors.compile.pass.cpp (+1-1)
  • (modified) libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h (+3-3)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/barrier.version.compile.pass.cpp (+6-6)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/filesystem.version.compile.pass.cpp (+8-8)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/fstream.version.compile.pass.cpp (+2-2)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/iomanip.version.compile.pass.cpp (+10-10)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/latch.version.compile.pass.cpp (+6-6)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/mutex.version.compile.pass.cpp (+8-8)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/semaphore.version.compile.pass.cpp (+6-6)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/shared_mutex.version.compile.pass.cpp (+18-18)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/stop_token.version.compile.pass.cpp (+6-6)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/thread.version.compile.pass.cpp (+6-6)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp (+70-70)
  • (modified) libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.tests.h (+3-3)
  • (modified) libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h (+3-3)
  • (modified) libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h (+2-2)
  • (modified) libcxx/test/support/filesystem_test_helper.h (+1-1)
  • (modified) libcxx/test/support/test_macros.h (+10-10)
  • (modified) libcxx/test/tools/clang_tidy_checks/internal_ftm_use.cpp (-13)
  • (modified) libcxx/utils/generate_feature_test_macro_components.py (+20-20)
  • (modified) libcxx/utils/libcxx/header_information.py (+15-15)
  • (modified) libcxx/utils/libcxx/test/dsl.py (+1-1)
  • (modified) libcxx/utils/libcxx/test/features.py (+21-12)
  • (modified) runtimes/cmake/Modules/HandleFlags.cmake (-6)
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 75c926f5432aea..bb03b443178861 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -741,24 +741,24 @@ config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
 config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE)
 config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM)
 config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT)
-config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
-config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
-config_define_if_not(LIBCXX_HAS_TERMINAL_AVAILABLE _LIBCPP_HAS_NO_TERMINAL)
+config_define(${LIBCXX_ENABLE_THREADS} _LIBCPP_HAS_THREADS)
+config_define(${LIBCXX_ENABLE_MONOTONIC_CLOCK} _LIBCPP_HAS_MONOTONIC_CLOCK)
+config_define(${LIBCXX_HAS_TERMINAL_AVAILABLE} _LIBCPP_HAS_TERMINAL)
 if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default")
   config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION)
 endif()
 config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
 config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL)
 config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32)
-config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
+config_define(${LIBCXX_HAS_MUSL_LIBC} _LIBCPP_HAS_MUSL_LIBC)
 config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
-config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM)
-config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
-config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION)
-config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE)
-config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS)
-config_define_if_not(LIBCXX_ENABLE_TIME_ZONE_DATABASE _LIBCPP_HAS_NO_TIME_ZONE_DATABASE)
-config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
+config_define(${LIBCXX_ENABLE_FILESYSTEM} _LIBCPP_HAS_FILESYSTEM)
+config_define(${LIBCXX_ENABLE_RANDOM_DEVICE} _LIBCPP_HAS_RANDOM_DEVICE)
+config_define(${LIBCXX_ENABLE_LOCALIZATION} _LIBCPP_HAS_LOCALIZATION)
+config_define(${LIBCXX_ENABLE_UNICODE} _LIBCPP_HAS_UNICODE)
+config_define(${LIBCXX_ENABLE_WIDE_CHARACTERS} _LIBCPP_HAS_WIDE_CHARACTERS)
+config_define(${LIBCXX_ENABLE_TIME_ZONE_DATABASE} _LIBCPP_HAS_TIME_ZONE_DATABASE)
+config_define(${LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS} _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS)
 
 if (LIBCXX_ENABLE_ASSERTIONS)
   message(DEPRECATION "LIBCXX_ENABLE_ASSERTIONS is deprecated and will be removed in LLVM 20. Please use LIBCXX_HARDENING_MODE instead.")
diff --git a/libcxx/docs/DesignDocs/ThreadingSupportAPI.rst b/libcxx/docs/DesignDocs/ThreadingSupportAPI.rst
index e7f3de54e6782a..d103c49e25952f 100644
--- a/libcxx/docs/DesignDocs/ThreadingSupportAPI.rst
+++ b/libcxx/docs/DesignDocs/ThreadingSupportAPI.rst
@@ -45,9 +45,9 @@ API but leaves out the implementation.
 Threading Configuration Macros
 ==============================
 
-**_LIBCPP_HAS_NO_THREADS**
-  This macro is defined when libc++ is built without threading support. It
-  should not be manually defined by the user.
+**_LIBCPP_HAS_THREADS**
+  This macro is set to 1 when libc++ is built with threading support. Otherwise
+  it is set to 0. It should not be manually defined by the user.
 
 **_LIBCPP_HAS_THREAD_API_EXTERNAL**
   This macro is defined when libc++ should use the ``<__external_threading>``
diff --git a/libcxx/include/__algorithm/find.h b/libcxx/include/__algorithm/find.h
index 6f23ec3f6fc69d..14b8a7804887b0 100644
--- a/libcxx/include/__algorithm/find.h
+++ b/libcxx/include/__algorithm/find.h
@@ -29,7 +29,7 @@
 #include <__utility/move.h>
 #include <limits>
 
-#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#if _LIBCPP_HAS_WIDE_CHARACTERS
 #  include <cwchar>
 #endif
 
@@ -65,7 +65,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find(_Tp* __first, _T
   return __last;
 }
 
-#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#if _LIBCPP_HAS_WIDE_CHARACTERS
 template <class _Tp,
           class _Up,
           class _Proj,
@@ -77,7 +77,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find(_Tp* __first, _T
     return __ret;
   return __last;
 }
-#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#endif // _LIBCPP_HAS_WIDE_CHARACTERS
 
 // TODO: This should also be possible to get right with different signedness
 // cast integral types to allow vectorization
diff --git a/libcxx/include/__algorithm/lexicographical_compare.h b/libcxx/include/__algorithm/lexicographical_compare.h
index 1de3ca13e1b45c..ebe7e3b56a292e 100644
--- a/libcxx/include/__algorithm/lexicographical_compare.h
+++ b/libcxx/include/__algorithm/lexicographical_compare.h
@@ -26,7 +26,7 @@
 #include <__type_traits/is_trivially_lexicographically_comparable.h>
 #include <__type_traits/is_volatile.h>
 
-#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#if _LIBCPP_HAS_WIDE_CHARACTERS
 #  include <cwchar>
 #endif
 
@@ -78,14 +78,14 @@ __lexicographical_compare(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Tp* __las
       return __last1 - __first1 < __last2 - __first2;
     return __res < 0;
   }
-#  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#  if _LIBCPP_HAS_WIDE_CHARACTERS
   else if constexpr (is_same<__remove_cv_t<_Tp>, wchar_t>::value) {
     auto __res = std::__constexpr_wmemcmp(__first1, __first2, std::min(__last1 - __first1, __last2 - __first2));
     if (__res == 0)
       return __last1 - __first1 < __last2 - __first2;
     return __res < 0;
   }
-#  endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#  endif // _LIBCPP_HAS_WIDE_CHARACTERS
   else {
     auto __res = std::mismatch(__first1, __last1, __first2, __last2);
     if (__res.second == __last2)
diff --git a/libcxx/include/__algorithm/sort.h b/libcxx/include/__algorithm/sort.h
index 0b2137dee2f77e..5490d8049bf7c8 100644
--- a/libcxx/include/__algorithm/sort.h
+++ b/libcxx/include/__algorithm/sort.h
@@ -894,7 +894,7 @@ template <class _Comp, class _RandomAccessIterator>
 void __sort(_RandomAccessIterator, _RandomAccessIterator, _Comp);
 
 extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
-#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#if _LIBCPP_HAS_WIDE_CHARACTERS
 extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
 #endif
 extern template _LIBCPP_EXPORTED_FROM_ABI void
@@ -941,7 +941,7 @@ template <class _Type>
 using __sort_is_specialized_in_library = __is_any_of<
     _Type,
     char,
-#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#if _LIBCPP_HAS_WIDE_CHARACTERS
     wchar_t,
 #endif
     signed char,
diff --git a/libcxx/include/__atomic/aliases.h b/libcxx/include/__atomic/aliases.h
index afc64eaaa69e7b..605c524a3fbc38 100644
--- a/libcxx/include/__atomic/aliases.h
+++ b/libcxx/include/__atomic/aliases.h
@@ -42,7 +42,7 @@ using atomic_char8_t = atomic<char8_t>;
 #endif
 using atomic_char16_t = atomic<char16_t>;
 using atomic_char32_t = atomic<char32_t>;
-#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#if _LIBCPP_HAS_WIDE_CHARACTERS
 using atomic_wchar_t = atomic<wchar_t>;
 #endif
 
diff --git a/libcxx/include/__atomic/atomic_sync.h b/libcxx/include/__atomic/atomic_sync.h
index aaf81f58731a98..08f3497fef9f45 100644
--- a/libcxx/include/__atomic/atomic_sync.h
+++ b/libcxx/include/__atomic/atomic_sync.h
@@ -69,7 +69,7 @@ struct __atomic_wait_poll_impl {
   }
 };
 
-#ifndef _LIBCPP_HAS_NO_THREADS
+#if _LIBCPP_HAS_THREADS
 
 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(void const volatile*) _NOEXCEPT;
 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(void const volatile*) _NOEXCEPT;
@@ -163,7 +163,7 @@ _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void __atomic_notify_all(const _
   std::__cxx_atomic_notify_all(__atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_contention_address(__a));
 }
 
-#else // _LIBCPP_HAS_NO_THREADS
+#else // _LIBCPP_HAS_THREADS
 
 template <class _AtomicWaitable, class _Poll>
 _LIBCPP_HIDE_FROM_ABI void __atomic_wait_unless(const _AtomicWaitable& __a, _Poll&& __poll, memory_order __order) {
@@ -177,7 +177,7 @@ _LIBCPP_HIDE_FROM_ABI void __atomic_notify_one(const _AtomicWaitable&) {}
 template <class _AtomicWaitable>
 _LIBCPP_HIDE_FROM_ABI void __atomic_notify_all(const _AtomicWaitable&) {}
 
-#endif // _LIBCPP_HAS_NO_THREADS
+#endif // _LIBCPP_HAS_THREADS
 
 template <typename _Tp>
 _LIBCPP_HIDE_FROM_ABI bool __cxx_nonatomic_compare_equal(_Tp const& __lhs, _Tp const& __rhs) {
diff --git a/libcxx/include/__chrono/convert_to_tm.h b/libcxx/include/__chrono/convert_to_tm.h
index 3a51019b80784a..5f1b2632f629a5 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -180,8 +180,7 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& __value) {
     // Has no time information.
   } else if constexpr (same_as<_ChronoT, chrono::local_info>) {
     // Has no time information.
-#    if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&                          \
-        !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#    if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
   } else if constexpr (__is_specialization_v<_ChronoT, chrono::zoned_time>) {
     return std::__convert_to_tm<_Tm>(
         chrono::sys_time<typename _ChronoT::duration>{__value.get_local_time().time_since_epoch()});
diff --git a/libcxx/include/__chrono/formatter.h b/libcxx/include/__chrono/formatter.h
index 8389e2cbf9e595..c1b57209b938d9 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -12,7 +12,7 @@
 
 #include <__config>
 
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#if _LIBCPP_HAS_LOCALIZATION
 
 #  include <__algorithm/ranges_copy.h>
 #  include <__chrono/calendar.h>
@@ -143,8 +143,7 @@ __format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::hh_mm_ss<
                    __value.fractional_width);
 }
 
-#    if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) &&                   \
-        !defined(_LIBCPP_HAS_NO_FILESYSTEM)
+#    if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
 template <class _CharT, class _Duration, class _TimeZonePtr>
 _LIBCPP_HIDE_FROM_ABI void
 __format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::zoned_time<_Duration, _TimeZonePtr>& __value) {
@@ -156,8 +155,7 @@ template <class _Tp>
 consteval bool __use_fraction() {
   if constexpr (__is_time_point<_Tp>)
     return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
-#    if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) &&                   \
-        !defined(_LIBCPP_HAS_NO_FILESYSTEM)
+#    if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
   else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
     return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
 #    endif
@@ -232,7 +230,7 @@ _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] const
 #    if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
   if constexpr (same_as<_Tp, chrono::sys_info>)
     return {__value.abbrev, __value.offset};
-#      if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
+#      if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
   else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
     return __formatter::__convert_to_time_zone(__value.get_info());
 #      endif
@@ -450,7 +448,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const _Tp& __value) {
     return true;
   else if constexpr (same_as<_Tp, chrono::local_info>)
     return true;
-#      if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
+#      if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
   else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
     return true;
 #      endif
@@ -500,7 +498,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_name_ok(const _Tp& __value) {
     return true;
   else if constexpr (same_as<_Tp, chrono::local_info>)
     return true;
-#      if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
+#      if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
   else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
     return true;
 #      endif
@@ -550,7 +548,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __date_ok(const _Tp& __value) {
     return true;
   else if constexpr (same_as<_Tp, chrono::local_info>)
     return true;
-#      if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
+#      if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
   else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
     return true;
 #      endif
@@ -600,7 +598,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __month_name_ok(const _Tp& __value) {
     return true;
   else if constexpr (same_as<_Tp, chrono::local_info>)
     return true;
-#      if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
+#      if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
   else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
     return true;
 #      endif
@@ -964,7 +962,7 @@ struct formatter<chrono::local_info, _CharT> : public __formatter_chrono<_CharT>
     return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags{});
   }
 };
-#      if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
+#      if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
 // Note due to how libc++'s formatters are implemented there is no need to add
 // the exposition only local-time-format-t abstraction.
 template <class _Duration, class _TimeZonePtr, __fmt_char_type _CharT>
@@ -977,13 +975,13 @@ struct formatter<chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT> : public _
     return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock);
   }
 };
-#      endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
+#      endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
 #    endif   // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
 
 #  endif // if _LIBCPP_STD_VER >= 20
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif // !_LIBCPP_HAS_NO_LOCALIZATION
+#endif // _LIBCPP_HAS_LOCALIZATION
 
 #endif //  _LIBCPP___CHRONO_FORMATTER_H
diff --git a/libcxx/include/__chrono/high_resolution_clock.h b/libcxx/include/__chrono/high_resolution_clock.h
index 0697fd2de9b4de..d324c7f0283bfe 100644
--- a/libcxx/include/__chrono/high_resolution_clock.h
+++ b/libcxx/include/__chrono/high_resolution_clock.h
@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace chrono {
 
-#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
+#if _LIBCPP_HAS_MONOTONIC_CLOCK
 typedef steady_clock high_resolution_clock;
 #else
 typedef system_clock high_resolution_clock;
diff --git a/libcxx/include/__chrono/ostream.h b/libcxx/include/__chrono/ostream.h
index 3420fb12bcdb0b..ca6d1605d0f87e 100644
--- a/libcxx/include/__chrono/ostream.h
+++ b/libcxx/include/__chrono/ostream.h
@@ -12,7 +12,7 @@
 
 #include <__config>
 
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#if _LIBCPP_HAS_LOCALIZATION
 
 #  include <__chrono/calendar.h>
 #  include <__chrono/day.h>
@@ -86,7 +86,7 @@ _LIBCPP_HIDE_FROM_ABI auto __units_suffix() {
   else if constexpr (same_as<typename _Period::type, nano>)
     return _LIBCPP_STATICALLY_WIDEN(_CharT, "ns");
   else if constexpr (same_as<typename _Period::type, micro>)
-#    ifndef _LIBCPP_HAS_NO_UNICODE
+#    if _LIBCPP_HAS_UNICODE
     return _LIBCPP_STATICALLY_WIDEN(_CharT, "\u00b5s");
 #    else
     return _LIBCPP_STATICALLY_WIDEN(_CharT, "us");
@@ -307,7 +307,7 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const local_info& __info) {
              _LIBCPP_STATICALLY_WIDEN(_CharT, "{}: {{{}, {}}}"), __result(), __info.first, __info.second);
 }
 
-#      if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
+#      if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
 template <class _CharT, class _Traits, class _Duration, class _TimeZonePtr>
 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os, const zoned_time<_Duration, _TimeZonePtr>& __tp) {
@@ -322,6 +322,6 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const zoned_time<_Duration, _Ti
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif // !_LIBCPP_HAS_NO_LOCALIZATION
+#endif // _LIBCPP_HAS_LOCALIZATION
 
 #endif // _LIBCPP___CHRONO_OSTREAM_H
diff --git a/libcxx/include/__chrono/parser_std_format_spec.h b/libcxx/include/__chrono/parser_std_format_spec.h
index c9cfcc6d572f41..3976864c12b983 100644
--- a/libcxx/include/__chrono/parser_std_format_spec.h
+++ b/libcxx/include/__chrono/parser_std_format_spec.h
@@ -12,7 +12,7 @@
 
 #include <__config>
 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#if _LIBCPP_HAS_LOCALIZATION
 
 #  include <__format/concepts.h>
 #  include <__format/format_error.h>
@@ -416,6 +416,6 @@ class _LIBCPP_TEMPLATE_VIS __parser_chrono {
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif // !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#endif // _LIBCPP_HAS_LOCALIZATION
 
 #endif // _LIBCPP___CHRONO_PARSER_STD_FORMAT_SPEC_H
diff --git a/libcxx/include/__chrono/statically_widen.h b/libcxx/include/__chrono/statically_widen.h
index 680483a59ac2c4..40e085633b8c16 100644
--- a/libcxx/include/__chrono/statically_widen.h
+++ b/libcxx/include/__chrono/statically_widen.h
@@ -24,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER >= 20
 
-#  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#  if _LIBCPP_HAS_WIDE_CHARACTERS
 template <__fmt_char_type _CharT>
 _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __str, const wchar_t* __wstr) {
   if constexpr (same_as<_CharT, char>)
@@ -33,7 +33,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __s
     return __wstr;
 }
 #    define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str, L##__str)
-#  else // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#  else // _LIBCPP_HAS_WIDE_CHARACTERS
 
 // Without this indirection the unit test test/libcxx/modules_include.sh.cpp
 // fails for the CI build "No wide characters". This seems like a bug.
@@ -43,7 +43,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __s
   return __str;
 }
 #    define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str)
-#  endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#  endif // _LIBCPP_HAS_WIDE_CHARACTERS
 
 #endif // _LIBCPP_STD_VER >= 20
 
diff --git a/libcxx/include/__chrono/steady_clock.h b/libcxx/include/__chrono/steady_clock.h
index 612a7f156e6343..1b247b2c286094 100644
--- a/libcxx/include/__chrono/steady_clock.h
+++ b/libcxx/include/__chrono/steady_clock.h
@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace chrono {
 
-#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
+#if _LIBCPP_HAS_MONOTONIC_CLOCK
 class _LIBCPP_EXPORTED_FROM_ABI steady_clock {
 public:
   typedef nanoseconds duration;
diff --git a/libcxx/include/__chrono/time_zone.h b/libcxx/include/__chrono/time_zone.h
index de11dac1eef0c2..3bfe482a146244 100644
--- a/libcxx/include/__chrono/time_zone.h
+++ b/libcxx/include/__chrono/time_zone.h
@@ -37,8 +37,7 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#  if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&   \
-      !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#  if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
 
 namespace chrono {
 
@@ -170,8 +169,8 @@ operator<=>(const time_zone& __x, const time_zone& __y) noexcept {
 
 } // namespace chrono
 
-#  endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
-         // && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#  endif // _LIBCPP_STD_VE...
[truncated]

@philnik777 philnik777 force-pushed the rename_config_macros branch from 131d843 to e27bca3 Compare November 4, 2024 19:53
@philnik777 philnik777 force-pushed the rename_config_macros branch from e27bca3 to d80d1d9 Compare November 4, 2024 22:01
Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM w/ CI green.

@philnik777 philnik777 force-pushed the rename_config_macros branch from d80d1d9 to 3a189c3 Compare November 5, 2024 15:14
@philnik777 philnik777 merged commit c6f3b7b into llvm:main Nov 6, 2024
64 checks passed
@mstorsjo
Copy link
Member

mstorsjo commented Nov 6, 2024

This caused a surprising issue in external code that is checking these libcxx config macros. Is this change slated to be backported to 19.x, or is this strictly for 20.x development going forward?

Since b4130be (#109525) we have code in compiler-rt/libfuzzer, which tries to check the kind of thread API used for c++ threads, by doing

#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) ||                                 \
    defined(_GLIBCXX_GCC_GTHR_POSIX_H)

Admittedly, this is known to not be a supported construct. (CC @Zentrik)

Now after this change, we suddenly end up picking this pthread codepath every time. The way forward of fixing this, is to extend the condition like this:

#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && _LIBCPP_HAS_THREAD_API_PTHREAD) || \
    defined(_GLIBCXX_GCC_GTHR_POSIX_H)

However with the previous form, we'd have

#define _LIBCPP_HAS_THREAD_API_PTHREAD

where the macro expands to nothing (contrary to -D _LIBCPP_HAS_THREAD_API_PTHREAD which would be equal to -D_LIBCPP_HAS_THREAD_API_PTHREAD=1).

If we try doing that with the new form of the ifdef, we end up with this error:

test.cpp:4:79: error: expected value in expression
    4 | #if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && _LIBCPP_HAS_THREAD_API_PTHREAD) || \
      |                                                                               ^
1 error generated.

Do you see any way of adjusting the #if condition so that it works both with the old and new forms of the define? As the old define doesn't expand to anything, it's hard to do any sort of comparison with it.

If not, I'm afraid that we'd need to rip out the libc++ specific part of #109525, or entirely skip setting the thread names in libfuzzer on mingw targets.

@ldionne
Copy link
Member

ldionne commented Nov 6, 2024

As you mentioned, checking libc++ internal macros is not something we support. If we supported that, we couldn't make any modifications to the code base without breaking people.

Perhaps you could do something along those lines instead?

if constexpr (std::is_same_v<std::thread::native_handle_type, pthread_t>) {
  // assume pthread
}

@mstorsjo
Copy link
Member

mstorsjo commented Nov 6, 2024

As you mentioned, checking libc++ internal macros is not something we support. If we supported that, we couldn't make any modifications to the code base without breaking people.

Perhaps you could do something along those lines instead?

if constexpr (std::is_same_v<std::thread::native_handle_type, pthread_t>) {
  // assume pthread
}

Hmm, but that expression can't be compiled at all, if the type pthread_t isn't declared at this point; in regular builds of libcxx on Windows, there are no pthread headers (which is an optional third party library) included here.

@mstorsjo
Copy link
Member

mstorsjo commented Nov 6, 2024

As you mentioned, checking libc++ internal macros is not something we support. If we supported that, we couldn't make any modifications to the code base without breaking people.

Yep - I guess this is a case of us thinking "how bad can it be" (https://xkcd.com/292/).

I guess I assumed that if things change/break (e.g. if the macro is renamed) we'd fail by not picking up libcxx built with pthreads (which, TBH, is a very rare configuration - I think this was added to work with libstdc++ builds on top of pthread, which is a very common configuration). I.e. we assumed that if things break, we'd get false negatives, but instead we get false positives for the condition here.

@ldionne
Copy link
Member

ldionne commented Nov 6, 2024

Here's what I would suggest:

#if __has_include(<pthread.h>)

#include <pthread.h>
inline void maybe_set_thread_name(std::thread& t, std::string const& name) {
  if constexpr (std::is_same_v<std::thread::native_handle_type, ::pthread_t>) {
    (void)pthread_setname_np(t.native_handle(), name.c_str());
  }
}

#else

inline void maybe_set_thread_name(std::thread& t, std::string const& name) {
  // don't even try
}

#endif

@mstorsjo
Copy link
Member

mstorsjo commented Nov 6, 2024

Here's what I would suggest:

#if __has_include(<pthread.h>)

#include <pthread.h>
inline void maybe_set_thread_name(std::thread& t, std::string const& name) {
  if constexpr (std::is_same_v<std::thread::native_handle_type, ::pthread_t>) {
    (void)pthread_setname_np(t.native_handle(), name.c_str());
  }
}

#else

inline void maybe_set_thread_name(std::thread& t, std::string const& name) {
  // don't even try
}

#endif

Thanks - that might indeed work. As the other alternative is to set the thread name with win32 threads, we could also check for that data type - assuming that pthread_t and HANDLE boil down to distinct types (but it can also very well be that both of them are void* underneath...).

Although - I'm potentially leaning towards simply skipping this entirely for mingw, as this is used in libfuzzer which isn't even usable in mingw contexts yet (libfuzzer gets compiled but clang doesn't let you use it); no need to bend over backwards for quality of life improvements for such a configuration.

@ldionne
Copy link
Member

ldionne commented Nov 6, 2024

That's your call!

@mstorsjo
Copy link
Member

mstorsjo commented Nov 6, 2024

FWIW, that setup with if constexpr doesn't work, as the call to pthread_setname_np is invalid for these data types, even if if constexpr would eliminate it:

llvm-project/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp:249:11: error: no matching function for call to 'pthread_setname_np'
  249 |     (void)pthread_setname_np(thread.native_handle(), name.c_str());
      |           ^~~~~~~~~~~~~~~~~~
/opt/llvm-mingw/x86_64-w64-mingw32/include/pthread.h:323:26: note: candidate function not viable: cannot convert argument of incomplete type 'native_handle_type' (aka 'void *') to 'pthread_t' (aka 'unsigned long long') for 1st argument
  323 | WINPTHREAD_API int       pthread_setname_np(pthread_t thread, const char *name);
      |                          ^                  ~~~~~~~~~~~~~~~~
1 error generated.

I posted a PR to simply skip this on mingw targets, in #115167.

@ldionne
Copy link
Member

ldionne commented Nov 6, 2024

@mstorsjo I think the problem is that your if condition isn't dependent. I think something like this would fix it:

template <class Thread>
void maybe_set_thread_name(Thread& t, std::string const& name) {
  if constexpr (std::is_same_v<typename Thread::native_handle_type, ::pthread_t>) {
    (void)pthread_setname_np(t.native_handle(), name.c_str());
  }
}

This might be worth trying out.

@mstorsjo
Copy link
Member

mstorsjo commented Nov 7, 2024

@mstorsjo I think the problem is that your if condition isn't dependent. I think something like this would fix it:

template <class Thread>
void maybe_set_thread_name(Thread& t, std::string const& name) {
  if constexpr (std::is_same_v<typename Thread::native_handle_type, ::pthread_t>) {
    (void)pthread_setname_np(t.native_handle(), name.c_str());
  }
}

This might be worth trying out.

Thanks! With that form, I did manage to seemingly get it to work.

I've posted such a solution for future reference, but I think we'll steer clear of that for practical reasons for now. But if we want to go down that route - we now have a proper solution. Thanks!

philnik777 pushed a commit that referenced this pull request Nov 11, 2024
…5774)

Noticed this while debugging a few things following
#112094. Amended error message
to reflect conditional check.
Groverkss pushed a commit to iree-org/llvm-project that referenced this pull request Nov 15, 2024
…m#115774)

Noticed this while debugging a few things following
llvm#112094. Amended error message
to reflect conditional check.
alicelovescake added a commit to electron/electron that referenced this pull request Dec 6, 2024
alicelovescake added a commit to electron/electron that referenced this pull request Dec 6, 2024
ckerr added a commit to electron/electron that referenced this pull request Dec 10, 2024
* chore: bump chromium in DEPS to 133.0.6858.0

* chore: bump chromium in DEPS to 133.0.6860.0

* chore: update patches

v8/revert_fastapi_remove_dynamic_overload_resolution.patch had some additions due to https://chromium-review.googlesource.com/c/v8/v8/+/6023139

* 6044060: Reland "Moves shared GN templates into //build/config/apple."
https://chromium-review.googlesource.com/c/chromium/src/+/6044060

* Revert "6023139: [fastapi] Add support for attribute setters"
https://chromium-review.googlesource.com/c/v8/v8/+/6023139

* Update printing.patch

The removed include is present in the original source file now, just slightly before where it was being added.

6015430: Reduce platform-like buildflags in sandbox code
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/6015430

* 6039836: Migrate Command::IsMediaKey to be a member of ui::Accelerator
https://chromium-review.googlesource.com/c/chromium/src/+/6039836

* 6038659: [CodeHealth] Clean up the feature ZstdContentEncoding
https://chromium-review.googlesource.com/c/chromium/src/+/6038659

* chore: bump chromium in DEPS to 133.0.6862.0

* chore: update patches

* 72747: crypto: switch to C++
https://boringssl-review.googlesource.com/c/boringssl/+/72747

* fixup! 72747: crypto: switch to C++ https://boringssl-review.googlesource.com/c/boringssl/+/72747

* chore: gen libc++ filenames

* 6042601: [shared storage] Implement with_lock option for methods from response headers
https://chromium-review.googlesource.com/c/chromium/src/+/6042601

* chore: bump chromium in DEPS to 133.0.6864.0

* chore: bump chromium in DEPS to 133.0.6866.0

* chore: bump chromium in DEPS to 133.0.6868.0

* chore: bump chromium in DEPS to 133.0.6870.0

* chore: bump chromium in DEPS to 133.0.6872.0

* chore: bump chromium in DEPS to 133.0.6874.0

* chore: bump chromium in DEPS to 133.0.6876.0

* 6039992: Fix false activation logic for context menu. | https://chromium-review.googlesource.com/c/chromium/src/+/6039992

* chore: update patches

* chore: update patches

* chore: bump chromium in DEPS to 133.0.6878.0

* chore: update patches

* [Build] Organize //components/dbus into a single component

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/6055280

* Merge //components/dbus/* into a single //components/dbus, which
  matches how most components are organized. This avoids having
  many small shared libraries which incurs unnecessary overhead.
* Limit visibility of //components/dbus/* to //components/dbus

* fixup! Update _LIBCPP_ABI_VERSION to always have a default value while keeping unstable false due to changes in llvm llvm/llvm-project#112094

* 6040416: Let s know which widget the input came on. | https://chromium-review.googlesource.com/c/chromium/src/+/6040416

* 6056267: [MPArch guest view] Fix authentication for MPArch guests | https://chromium-review.googlesource.com/c/chromium/src/+/6056267

* make_span() is deprecated: https://issues.chromium.org/issues/341907909

* fixup: https://issues.chromium.org/issues/341907909

* chore: delete extra bracket from removing make_span commit

* fixup: 6059305: Make WTF::UTF8ConversionMode a scoped enum | https://chromium-review.googlesource.com/c/chromium/src/+/6059305

* 6051058: CookieInclusionStatus: Remove ctors which bypass invariants | https://chromium-review.googlesource.com/c/chromium/src/+/6051058

* 6038981: Remove most remaining CHECK(false)s | https://chromium-review.googlesource.com/c/chromium/src/+/6038981

* build: use third_party/simdutf in Node.js

* chore: node ./script/gen-libc++-filenames.js

* chore: fix strict-cast conversion error in subspan()

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/6044946

* chore: fix strict-cast conversion error in base::as_bytes()

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/6044946

* chore: fix strict-cast conversion error in span.split_at()

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/6044946

* chore: use shorthand target name

* chore: better docs in build_add_public_config_simdutf_config.patch

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: clavin <[email protected]>
Co-authored-by: alice <[email protected]>
Co-authored-by: Charles Kerr <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants