Skip to content
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

[libc++][format] Disables the FTM on older MacOS versions. #126547

Merged
merged 1 commit into from
Feb 14, 2025

Conversation

mordante
Copy link
Member

On older MacOS versions where std::to_chars for floating-point types is not available the format library can't be used. Due to some issue with the availability macro used to disable format on MacOS the issue triggers regardless of the type being formatted.

The print library has the same issue.

Fixes: #125353

@mordante mordante requested a review from a team as a code owner February 10, 2025 17:28
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Feb 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 10, 2025

@llvm/pr-subscribers-libcxx

Author: Mark de Wever (mordante)

Changes

On older MacOS versions where std::to_chars for floating-point types is not available the format library can't be used. Due to some issue with the availability macro used to disable format on MacOS the issue triggers regardless of the type being formatted.

The print library has the same issue.

Fixes: #125353


Full diff: https://github.com/llvm/llvm-project/pull/126547.diff

6 Files Affected:

  • (modified) libcxx/include/version (+6-2)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/format.version.compile.pass.cpp (+33-15)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/ostream.version.compile.pass.cpp (+22-10)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/print.version.compile.pass.cpp (+22-10)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp (+55-25)
  • (modified) libcxx/utils/generate_feature_test_macro_components.py (+11)
diff --git a/libcxx/include/version b/libcxx/include/version
index 29a71ed574e56a5..2be538ebf4f7323 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -417,7 +417,9 @@ __cpp_lib_void_t                                        201411L <type_traits>
 # define __cpp_lib_erase_if                             202002L
 # undef  __cpp_lib_execution
 // # define __cpp_lib_execution                            201902L
-# define __cpp_lib_format                               202110L
+# if _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   define __cpp_lib_format                             202110L
+# endif
 # define __cpp_lib_format_uchar                         202311L
 # define __cpp_lib_generic_unordered_lookup             201811L
 # define __cpp_lib_int_pow2                             202002L
@@ -499,7 +501,9 @@ __cpp_lib_void_t                                        201411L <type_traits>
 # undef  __cpp_lib_optional
 # define __cpp_lib_optional                             202110L
 # define __cpp_lib_out_ptr                              202106L
-# define __cpp_lib_print                                202207L
+# if _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   define __cpp_lib_print                              202207L
+# endif
 # undef  __cpp_lib_ranges
 # define __cpp_lib_ranges                               202406L
 // # define __cpp_lib_ranges_as_const                      202207L
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/format.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/format.version.compile.pass.cpp
index 7bb2fa399b09453..6a95036e27a8986 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/format.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/format.version.compile.pass.cpp
@@ -68,11 +68,17 @@
 
 #elif TEST_STD_VER == 20
 
-# ifndef __cpp_lib_format
-#   error "__cpp_lib_format should be defined in c++20"
-# endif
-# if __cpp_lib_format != 202110L
-#   error "__cpp_lib_format should have the value 202110L in c++20"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_format
+#     error "__cpp_lib_format should be defined in c++20"
+#   endif
+#   if __cpp_lib_format != 202110L
+#     error "__cpp_lib_format should have the value 202110L in c++20"
+#   endif
+# else
+#   ifdef __cpp_lib_format
+#     error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 # ifdef __cpp_lib_format_ranges
@@ -88,11 +94,17 @@
 
 #elif TEST_STD_VER == 23
 
-# ifndef __cpp_lib_format
-#   error "__cpp_lib_format should be defined in c++23"
-# endif
-# if __cpp_lib_format != 202110L
-#   error "__cpp_lib_format should have the value 202110L in c++23"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_format
+#     error "__cpp_lib_format should be defined in c++23"
+#   endif
+#   if __cpp_lib_format != 202110L
+#     error "__cpp_lib_format should have the value 202110L in c++23"
+#   endif
+# else
+#   ifdef __cpp_lib_format
+#     error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 # ifndef __cpp_lib_format_ranges
@@ -111,11 +123,17 @@
 
 #elif TEST_STD_VER > 23
 
-# ifndef __cpp_lib_format
-#   error "__cpp_lib_format should be defined in c++26"
-# endif
-# if __cpp_lib_format != 202110L
-#   error "__cpp_lib_format should have the value 202110L in c++26"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_format
+#     error "__cpp_lib_format should be defined in c++26"
+#   endif
+#   if __cpp_lib_format != 202110L
+#     error "__cpp_lib_format should have the value 202110L in c++26"
+#   endif
+# else
+#   ifdef __cpp_lib_format
+#     error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 # ifndef __cpp_lib_format_ranges
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/ostream.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/ostream.version.compile.pass.cpp
index 2a42ca080612de3..f5c609e71188024 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/ostream.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/ostream.version.compile.pass.cpp
@@ -89,11 +89,17 @@
 #   endif
 # endif
 
-# ifndef __cpp_lib_print
-#   error "__cpp_lib_print should be defined in c++23"
-# endif
-# if __cpp_lib_print != 202207L
-#   error "__cpp_lib_print should have the value 202207L in c++23"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_print
+#     error "__cpp_lib_print should be defined in c++23"
+#   endif
+#   if __cpp_lib_print != 202207L
+#     error "__cpp_lib_print should have the value 202207L in c++23"
+#   endif
+# else
+#   ifdef __cpp_lib_print
+#     error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 #elif TEST_STD_VER > 23
@@ -111,11 +117,17 @@
 #   endif
 # endif
 
-# ifndef __cpp_lib_print
-#   error "__cpp_lib_print should be defined in c++26"
-# endif
-# if __cpp_lib_print != 202207L
-#   error "__cpp_lib_print should have the value 202207L in c++26"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_print
+#     error "__cpp_lib_print should be defined in c++26"
+#   endif
+#   if __cpp_lib_print != 202207L
+#     error "__cpp_lib_print should have the value 202207L in c++26"
+#   endif
+# else
+#   ifdef __cpp_lib_print
+#     error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 #endif // TEST_STD_VER > 23
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/print.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/print.version.compile.pass.cpp
index f4ccea4e86304c8..56c984178326e2b 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/print.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/print.version.compile.pass.cpp
@@ -50,20 +50,32 @@
 
 #elif TEST_STD_VER == 23
 
-# ifndef __cpp_lib_print
-#   error "__cpp_lib_print should be defined in c++23"
-# endif
-# if __cpp_lib_print != 202207L
-#   error "__cpp_lib_print should have the value 202207L in c++23"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_print
+#     error "__cpp_lib_print should be defined in c++23"
+#   endif
+#   if __cpp_lib_print != 202207L
+#     error "__cpp_lib_print should have the value 202207L in c++23"
+#   endif
+# else
+#   ifdef __cpp_lib_print
+#     error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 #elif TEST_STD_VER > 23
 
-# ifndef __cpp_lib_print
-#   error "__cpp_lib_print should be defined in c++26"
-# endif
-# if __cpp_lib_print != 202207L
-#   error "__cpp_lib_print should have the value 202207L in c++26"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_print
+#     error "__cpp_lib_print should be defined in c++26"
+#   endif
+#   if __cpp_lib_print != 202207L
+#     error "__cpp_lib_print should have the value 202207L in c++26"
+#   endif
+# else
+#   ifdef __cpp_lib_print
+#     error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 #endif // TEST_STD_VER > 23
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
index 8f5788d2bed203e..d8d11f7117cff6d 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
@@ -3685,11 +3685,17 @@
 #   error "__cpp_lib_flat_set should not be defined before c++23"
 # endif
 
-# ifndef __cpp_lib_format
-#   error "__cpp_lib_format should be defined in c++20"
-# endif
-# if __cpp_lib_format != 202110L
-#   error "__cpp_lib_format should have the value 202110L in c++20"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_format
+#     error "__cpp_lib_format should be defined in c++20"
+#   endif
+#   if __cpp_lib_format != 202110L
+#     error "__cpp_lib_format should have the value 202110L in c++20"
+#   endif
+# else
+#   ifdef __cpp_lib_format
+#     error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 # ifdef __cpp_lib_format_path
@@ -5146,11 +5152,17 @@
 #   endif
 # endif
 
-# ifndef __cpp_lib_format
-#   error "__cpp_lib_format should be defined in c++23"
-# endif
-# if __cpp_lib_format != 202110L
-#   error "__cpp_lib_format should have the value 202110L in c++23"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_format
+#     error "__cpp_lib_format should be defined in c++23"
+#   endif
+#   if __cpp_lib_format != 202110L
+#     error "__cpp_lib_format should have the value 202110L in c++23"
+#   endif
+# else
+#   ifdef __cpp_lib_format
+#     error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 # ifdef __cpp_lib_format_path
@@ -5679,11 +5691,17 @@
 #   endif
 # endif
 
-# ifndef __cpp_lib_print
-#   error "__cpp_lib_print should be defined in c++23"
-# endif
-# if __cpp_lib_print != 202207L
-#   error "__cpp_lib_print should have the value 202207L in c++23"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_print
+#     error "__cpp_lib_print should be defined in c++23"
+#   endif
+#   if __cpp_lib_print != 202207L
+#     error "__cpp_lib_print should have the value 202207L in c++23"
+#   endif
+# else
+#   ifdef __cpp_lib_print
+#     error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 # if !defined(_LIBCPP_VERSION) || _LIBCPP_HAS_LOCALIZATION
@@ -6853,11 +6871,17 @@
 #   endif
 # endif
 
-# ifndef __cpp_lib_format
-#   error "__cpp_lib_format should be defined in c++26"
-# endif
-# if __cpp_lib_format != 202110L
-#   error "__cpp_lib_format should have the value 202110L in c++26"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_format
+#     error "__cpp_lib_format should be defined in c++26"
+#   endif
+#   if __cpp_lib_format != 202110L
+#     error "__cpp_lib_format should have the value 202110L in c++26"
+#   endif
+# else
+#   ifdef __cpp_lib_format
+#     error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 # if !defined(_LIBCPP_VERSION)
@@ -7557,11 +7581,17 @@
 #   endif
 # endif
 
-# ifndef __cpp_lib_print
-#   error "__cpp_lib_print should be defined in c++26"
-# endif
-# if __cpp_lib_print != 202207L
-#   error "__cpp_lib_print should have the value 202207L in c++26"
+# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#   ifndef __cpp_lib_print
+#     error "__cpp_lib_print should be defined in c++26"
+#   endif
+#   if __cpp_lib_print != 202207L
+#     error "__cpp_lib_print should have the value 202207L in c++26"
+#   endif
+# else
+#   ifdef __cpp_lib_print
+#     error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT' is not met!"
+#   endif
 # endif
 
 # if !defined(_LIBCPP_VERSION) || _LIBCPP_HAS_LOCALIZATION
diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index 58ecd79cf7469c7..ae8a26859f98fae 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -529,6 +529,11 @@ def add_version_header(tc):
             # 202305 P2757R3 Type-checking format args
             # 202306 P2637R3 Member Visit
             "headers": ["format"],
+            # Trying to use `std::format` where to_chars floating-point is not
+            # available causes compilation errors, even with non floating-point types.
+            # https://github.com/llvm/llvm-project/issues/125353
+            "test_suite_guard": "!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT",
+            "libcxx_guard": "_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT",
         },
         {
             "name": "__cpp_lib_format_path",
@@ -1004,6 +1009,12 @@ def add_version_header(tc):
                 # "c++26": 202406, # P3235R3 std::print more types faster with less memory
             },
             "headers": ["ostream", "print"],
+            # Trying to use `std::print` where to_chars floating-point is not
+            # available causes compilation errors, even with non floating-point types.
+            # https://github.com/llvm/llvm-project/issues/125353
+            "test_suite_guard": "!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT",
+            "test_suite_guard": "!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT",
+            "libcxx_guard": "_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT",
         },
         {
             "name": "__cpp_lib_quoted_string_io",

@mordante mordante force-pushed the review/disable_format_ftm branch from c9f2048 to 577e70e Compare February 10, 2025 17:38
@mordante mordante added this to the LLVM 20.X Release milestone Feb 10, 2025
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.

LGTM. I was able to reproduce the issue locally by using an older deployment target. Also, we were already using // XFAIL: availability-fp_to_chars-missing on the format tests due to this issue.

On older MacOS versions where `std::to_chars` for floating-point types
is not available the format library can't be used. Due to some issue
with the availability macro used to disable format on MacOS the issue
triggers regardless of the type being formatted.

The print library has the same issue.

Fixes: llvm#125353
@ldionne ldionne force-pushed the review/disable_format_ftm branch from 577e70e to 146013a Compare February 12, 2025 13:53
@ldionne
Copy link
Member

ldionne commented Feb 12, 2025

I rebased and re-pushed to trigger CI. This LGTM whenever CI is green. Thanks for handling this @mordante !

@mordante mordante merged commit fbd92d0 into llvm:main Feb 14, 2025
81 checks passed
@mordante
Copy link
Member Author

/cherry-pick fbd92d0

@mordante mordante deleted the review/disable_format_ftm branch February 14, 2025 17:35
@llvmbot
Copy link
Member

llvmbot commented Feb 14, 2025

/pull-request #127232

joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
On older MacOS versions where `std::to_chars` for floating-point types
is not available the format library can't be used. Due to some issue
with the availability macro used to disable format on MacOS the issue
triggers regardless of the type being formatted.

The print library has the same issue.

Fixes: llvm#125353
swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 16, 2025
On older MacOS versions where `std::to_chars` for floating-point types
is not available the format library can't be used. Due to some issue
with the availability macro used to disable format on MacOS the issue
triggers regardless of the type being formatted.

The print library has the same issue.

Fixes: llvm#125353
(cherry picked from commit fbd92d0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
Development

Successfully merging this pull request may close these issues.

Printing std::chrono::time_point requires std::to_chars<long double>
4 participants