Skip to content

Commit

Permalink
[libc++] Don't try to provide source_location on AppleClang 1403
Browse files Browse the repository at this point in the history
AppleClang 1403 has some bugs that prevent std::source_location from
working properly on it. Consequently, we XFAILed the unit test for
source_location with that compiler. However, we should also avoid
advertising that the feature is supported on that compiler, otherwise
our feature-test macros lie. This was noticed to break Boost.Asio
when building with a recent libc++ and AppleClang 14.0.3.

rdar://106863087

Differential Revision: https://reviews.llvm.org/D146837
  • Loading branch information
ldionne committed Mar 28, 2023
1 parent faafd26 commit c2a4238
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions libcxx/include/__config
Expand Up @@ -23,6 +23,7 @@
#endif

#if defined(__apple_build_version__)
// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403)
# define _LIBCPP_COMPILER_CLANG_BASED
# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
#elif defined(__clang__)
Expand Down
6 changes: 4 additions & 2 deletions libcxx/include/source_location
Expand Up @@ -35,7 +35,8 @@ namespace std {

_LIBCPP_BEGIN_NAMESPACE_STD

#if _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location)
#if _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location) && \
!(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)

class source_location {
// The names source_location::__impl, _M_file_name, _M_function_name, _M_line, and _M_column
Expand Down Expand Up @@ -78,7 +79,8 @@ public:
}
};

#endif // _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location)
#endif // _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) &&
// _LIBCPP_APPLE_CLANG_VER <= 1403)

_LIBCPP_END_NAMESPACE_STD

Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/version
Expand Up @@ -368,7 +368,7 @@ __cpp_lib_void_t 201411L <type_traits>
# define __cpp_lib_shared_ptr_arrays 201707L
# define __cpp_lib_shift 201806L
// # define __cpp_lib_smart_ptr_for_overwrite 202002L
# if __has_builtin(__builtin_source_location)
# if __has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)
# define __cpp_lib_source_location 201907L
# endif
# define __cpp_lib_span 202002L
Expand Down
Expand Up @@ -42,7 +42,7 @@

#elif TEST_STD_VER == 20

# if __has_builtin(__builtin_source_location)
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
# ifndef __cpp_lib_source_location
# error "__cpp_lib_source_location should be defined in c++20"
# endif
Expand All @@ -51,13 +51,13 @@
# endif
# else
# ifdef __cpp_lib_source_location
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location)' is not met!"
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)' is not met!"
# endif
# endif

#elif TEST_STD_VER > 20

# if __has_builtin(__builtin_source_location)
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
# ifndef __cpp_lib_source_location
# error "__cpp_lib_source_location should be defined in c++2b"
# endif
Expand All @@ -66,7 +66,7 @@
# endif
# else
# ifdef __cpp_lib_source_location
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location)' is not met!"
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)' is not met!"
# endif
# endif

Expand Down
Expand Up @@ -3428,7 +3428,7 @@
# endif
# endif

# if __has_builtin(__builtin_source_location)
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
# ifndef __cpp_lib_source_location
# error "__cpp_lib_source_location should be defined in c++20"
# endif
Expand All @@ -3437,7 +3437,7 @@
# endif
# else
# ifdef __cpp_lib_source_location
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location)' is not met!"
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)' is not met!"
# endif
# endif

Expand Down Expand Up @@ -4776,7 +4776,7 @@
# endif
# endif

# if __has_builtin(__builtin_source_location)
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
# ifndef __cpp_lib_source_location
# error "__cpp_lib_source_location should be defined in c++2b"
# endif
Expand All @@ -4785,7 +4785,7 @@
# endif
# else
# ifdef __cpp_lib_source_location
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location)' is not met!"
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)' is not met!"
# endif
# endif

Expand Down
3 changes: 2 additions & 1 deletion libcxx/test/support/test_macros.h
Expand Up @@ -78,7 +78,8 @@
#endif

#if defined(__apple_build_version__)
#define TEST_APPLE_CLANG_VER (__clang_major__ * 100) + __clang_minor__
// Given AppleClang XX.Y.Z, TEST_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403)
#define TEST_APPLE_CLANG_VER (__apple_build_version__ / 10000)
#elif defined(__clang_major__)
#define TEST_CLANG_VER (__clang_major__ * 100) + __clang_minor__
#elif defined(__GNUC__)
Expand Down
4 changes: 2 additions & 2 deletions libcxx/utils/generate_feature_test_macro_components.py
Expand Up @@ -650,8 +650,8 @@ def add_version_header(tc):
"name": "__cpp_lib_source_location",
"values": { "c++20": 201907 },
"headers": ["source_location"],
"test_suite_guard": "__has_builtin(__builtin_source_location)",
"libcxx_guard": "__has_builtin(__builtin_source_location)",
"test_suite_guard": "__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)",
"libcxx_guard": "__has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)",
}, {
"name": "__cpp_lib_span",
"values": { "c++20": 202002 },
Expand Down

0 comments on commit c2a4238

Please sign in to comment.