Skip to content

Commit 1fa1bc9

Browse files
ldionnetstellar
authored andcommitted
[libc++] Don't try to provide source_location on AppleClang 1403
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 (cherry picked from commit c2a4238)
1 parent 555e0e7 commit 1fa1bc9

File tree

7 files changed

+18
-14
lines changed

7 files changed

+18
-14
lines changed

libcxx/include/__config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#endif
2424

2525
#if defined(__apple_build_version__)
26+
// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403)
2627
# define _LIBCPP_COMPILER_CLANG_BASED
2728
# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
2829
#elif defined(__clang__)

libcxx/include/source_location

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ namespace std {
3535

3636
_LIBCPP_BEGIN_NAMESPACE_STD
3737

38-
#if _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location)
38+
#if _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location) && \
39+
!(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)
3940

4041
class source_location {
4142
// The names source_location::__impl, _M_file_name, _M_function_name, _M_line, and _M_column
@@ -78,7 +79,8 @@ public:
7879
}
7980
};
8081

81-
#endif // _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location)
82+
#endif // _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) &&
83+
// _LIBCPP_APPLE_CLANG_VER <= 1403)
8284

8385
_LIBCPP_END_NAMESPACE_STD
8486

libcxx/include/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ __cpp_lib_void_t 201411L <type_traits>
366366
# define __cpp_lib_shared_ptr_arrays 201707L
367367
# define __cpp_lib_shift 201806L
368368
// # define __cpp_lib_smart_ptr_for_overwrite 202002L
369-
# if __has_builtin(__builtin_source_location)
369+
# if __has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)
370370
# define __cpp_lib_source_location 201907L
371371
# endif
372372
# define __cpp_lib_span 202002L

libcxx/test/std/language.support/support.limits/support.limits.general/source_location.version.compile.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
#elif TEST_STD_VER == 20
4444

45-
# if __has_builtin(__builtin_source_location)
45+
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
4646
# ifndef __cpp_lib_source_location
4747
# error "__cpp_lib_source_location should be defined in c++20"
4848
# endif
@@ -51,13 +51,13 @@
5151
# endif
5252
# else
5353
# ifdef __cpp_lib_source_location
54-
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location)' is not met!"
54+
# 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!"
5555
# endif
5656
# endif
5757

5858
#elif TEST_STD_VER > 20
5959

60-
# if __has_builtin(__builtin_source_location)
60+
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
6161
# ifndef __cpp_lib_source_location
6262
# error "__cpp_lib_source_location should be defined in c++2b"
6363
# endif
@@ -66,7 +66,7 @@
6666
# endif
6767
# else
6868
# ifdef __cpp_lib_source_location
69-
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location)' is not met!"
69+
# 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!"
7070
# endif
7171
# endif
7272

libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3408,7 +3408,7 @@
34083408
# endif
34093409
# endif
34103410

3411-
# if __has_builtin(__builtin_source_location)
3411+
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
34123412
# ifndef __cpp_lib_source_location
34133413
# error "__cpp_lib_source_location should be defined in c++20"
34143414
# endif
@@ -3417,7 +3417,7 @@
34173417
# endif
34183418
# else
34193419
# ifdef __cpp_lib_source_location
3420-
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location)' is not met!"
3420+
# 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!"
34213421
# endif
34223422
# endif
34233423

@@ -4761,7 +4761,7 @@
47614761
# endif
47624762
# endif
47634763

4764-
# if __has_builtin(__builtin_source_location)
4764+
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
47654765
# ifndef __cpp_lib_source_location
47664766
# error "__cpp_lib_source_location should be defined in c++2b"
47674767
# endif
@@ -4770,7 +4770,7 @@
47704770
# endif
47714771
# else
47724772
# ifdef __cpp_lib_source_location
4773-
# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location)' is not met!"
4773+
# 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!"
47744774
# endif
47754775
# endif
47764776

libcxx/test/support/test_macros.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
#endif
7979

8080
#if defined(__apple_build_version__)
81-
#define TEST_APPLE_CLANG_VER (__clang_major__ * 100) + __clang_minor__
81+
// Given AppleClang XX.Y.Z, TEST_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403)
82+
#define TEST_APPLE_CLANG_VER (__apple_build_version__ / 10000)
8283
#elif defined(__clang_major__)
8384
#define TEST_CLANG_VER (__clang_major__ * 100) + __clang_minor__
8485
#elif defined(__GNUC__)

libcxx/utils/generate_feature_test_macro_components.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ def add_version_header(tc):
648648
"name": "__cpp_lib_source_location",
649649
"values": { "c++20": 201907 },
650650
"headers": ["source_location"],
651-
"test_suite_guard": "__has_builtin(__builtin_source_location)",
652-
"libcxx_guard": "__has_builtin(__builtin_source_location)",
651+
"test_suite_guard": "__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)",
652+
"libcxx_guard": "__has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)",
653653
}, {
654654
"name": "__cpp_lib_span",
655655
"values": { "c++20": 202002 },

0 commit comments

Comments
 (0)