Ticket #13569: boost-atomic-patch.txt

File boost-atomic-patch.txt, 6.0 KB (added by Emil Gilliam <egilliam@…>, 4 years ago)

Patch to Boost to fix compare-and-swap of const object in newer LLVM

Line 
1diff -aur ./boost/atomic/detail/config.hpp /google/src/cloud/egilliam/lnboost/google3/third_party/boost/do_not_include_from_google3_only_third_party/boost/boost/atomic/detail/config.hpp
2--- ./boost/atomic/detail/config.hpp 2018-05-09 16:17:05.000000000 -0600
3+++ /google/src/cloud/egilliam/lnboost/google3/third_party/boost/do_not_include_from_google3_only_third_party/boost/boost/atomic/detail/config.hpp 2018-05-16 16:23:16.000000000 -0600
4@@ -36,10 +36,17 @@
5 #define BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA
6 #endif
7
8-#if (defined(__i386__) || defined(__x86_64__)) && (defined(__clang__) || (defined(BOOST_GCC) && (BOOST_GCC+0) < 40500) || defined(__SUNPRO_CC))
9 // This macro indicates that the compiler does not support allocating eax:edx or rax:rdx register pairs ("A") in asm blocks
10+#if defined(__i386__) || defined(__x86_64__)
11+#if defined(__clang__) && defined(__has_feature)
12+// Clang introduced this feature after it started supporting rax:rdx register pairs, so can use it to make this determination.
13+#if !__has_feature(__attribute_diagnose_if_objc__)
14 #define BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS
15 #endif
16+#elif (defined(BOOST_GCC) && (BOOST_GCC+0) < 40500) || defined(__SUNPRO_CC)
17+#define BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS
18+#endif
19+#endif
20
21 #if defined(__i386__) && (defined(__PIC__) || defined(__PIE__)) && !(defined(__clang__) || (defined(BOOST_GCC) && (BOOST_GCC+0) >= 50100))
22 // This macro indicates that asm blocks should preserve ebx value unchanged. Some compilers are able to maintain ebx themselves
23diff -aur ./boost/atomic/detail/ops_gcc_x86_dcas.hpp /google/src/cloud/egilliam/lnboost/google3/third_party/boost/do_not_include_from_google3_only_third_party/boost/boost/atomic/detail/ops_gcc_x86_dcas.hpp
24--- ./boost/atomic/detail/ops_gcc_x86_dcas.hpp 2018-05-09 16:17:05.000000000 -0600
25+++ /google/src/cloud/egilliam/lnboost/google3/third_party/boost/do_not_include_from_google3_only_third_party/boost/boost/atomic/detail/ops_gcc_x86_dcas.hpp 2018-05-16 16:43:51.000000000 -0600
26@@ -158,10 +158,11 @@
27 }
28 else
29 {
30+#if defined(BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS)
31 #if defined(__clang__)
32- // Clang cannot allocate eax:edx register pairs but it has sync intrinsics
33+ // Older versions of Clang cannot allocate eax:edx register pairs, but they do have sync intrinsics
34 value = __sync_val_compare_and_swap(&storage, (storage_type)0, (storage_type)0);
35-#elif defined(BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS)
36+#else // defined(__clang__)
37 uint32_t value_bits[2];
38 // We don't care for comparison result here; the previous value will be stored into value anyway.
39 // Also we don't care for ebx and ecx values, they just have to be equal to eax and edx before cmpxchg8b.
40@@ -175,6 +176,7 @@
41 : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
42 );
43 BOOST_ATOMIC_DETAIL_MEMCPY(&value, value_bits, sizeof(value));
44+#endif // defined(__clang__)
45 #else // defined(BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS)
46 // We don't care for comparison result here; the previous value will be stored into value anyway.
47 // Also we don't care for ebx and ecx values, they just have to be equal to eax and edx before cmpxchg8b.
48@@ -196,9 +198,9 @@
49 static BOOST_FORCEINLINE bool compare_exchange_strong(
50 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order, memory_order) BOOST_NOEXCEPT
51 {
52-#if defined(__clang__)
53+#if defined(BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS) && defined(__clang__)
54
55- // Clang cannot allocate eax:edx register pairs but it has sync intrinsics
56+ // Older versions of Clang cannot allocate eax:edx register pairs, but they do have sync intrinsics
57 storage_type old_expected = expected;
58 expected = __sync_val_compare_and_swap(&storage, old_expected, desired);
59 return expected == old_expected;
60@@ -401,13 +403,15 @@
61
62 static BOOST_FORCEINLINE storage_type load(storage_type const volatile& storage, memory_order) BOOST_NOEXCEPT
63 {
64+#if defined(BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS)
65+
66 #if defined(__clang__)
67
68- // Clang cannot allocate rax:rdx register pairs but it has sync intrinsics
69+ // Older versions of Clang cannot allocate rax:rdx register pairs, but they do have sync intrinsics
70 storage_type value = storage_type();
71 return __sync_val_compare_and_swap(&storage, value, value);
72
73-#elif defined(BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS)
74+#else // defined(__clang__)
75
76 // Some compilers can't allocate rax:rdx register pair either and also don't support 128-bit __sync_val_compare_and_swap
77 uint64_t value_bits[2];
78@@ -428,6 +432,8 @@
79 BOOST_ATOMIC_DETAIL_MEMCPY(&value, value_bits, sizeof(value));
80 return value;
81
82+#endif // defined(__clang__)
83+
84 #else // defined(BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS)
85
86 storage_type value;
87@@ -452,14 +458,16 @@
88 static BOOST_FORCEINLINE bool compare_exchange_strong(
89 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order, memory_order) BOOST_NOEXCEPT
90 {
91+#if defined(BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS)
92+
93 #if defined(__clang__)
94
95- // Clang cannot allocate rax:rdx register pairs but it has sync intrinsics
96+ // Older versions of Clang cannot allocate rax:rdx register pairs, but they do have sync intrinsics
97 storage_type old_expected = expected;
98 expected = __sync_val_compare_and_swap(&storage, old_expected, desired);
99 return expected == old_expected;
100
101-#elif defined(BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS)
102+#else // defined(__clang__)
103
104 // Some compilers can't allocate rax:rdx register pair either but also don't support 128-bit __sync_val_compare_and_swap
105 bool success;
106@@ -474,6 +482,8 @@
107
108 return success;
109
110+#endif // defined(__clang__)
111+
112 #else // defined(BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS)
113
114 bool success;