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

Fix Folly to build with current VS version #4048

Merged
merged 10 commits into from
Jan 7, 2021
121 changes: 118 additions & 3 deletions recipes/folly/all/patches/0007-allow-builtins.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,128 @@
diff --git a/folly/portability/Builtins.h b/folly/portability/Builtins.h
dmn-star marked this conversation as resolved.
Show resolved Hide resolved
index 971cb88..102fda1 100644
index 971cb8819..e68de4456 100644
--- a/folly/portability/Builtins.h
+++ b/folly/portability/Builtins.h
@@ -41,7 +41,7 @@ FOLLY_ALWAYS_INLINE void __builtin___clear_cache(char* begin, char* end) {
@@ -41,7 +41,6 @@ FOLLY_ALWAYS_INLINE void __builtin___clear_cache(char* begin, char* end) {
}
}

-#if !defined(_MSC_VER) || (_MSC_VER < 1923)
+#if !defined(_MSC_VER) || (_MSC_VER < 1930)
FOLLY_ALWAYS_INLINE int __builtin_clz(unsigned int x) {
unsigned long index;
return int(_BitScanReverse(&index, (unsigned long)x) ? 31 - index : 32);
@@ -93,7 +92,6 @@ FOLLY_ALWAYS_INLINE int __builtin_ctzll(unsigned long long x) {
return int(_BitScanForward64(&index, x) ? index : 64);
}
#endif
-#endif // !defined(_MSC_VER) || (_MSC_VER < 1923)

FOLLY_ALWAYS_INLINE int __builtin_ffs(int x) {
unsigned long index;
@@ -119,15 +117,12 @@ FOLLY_ALWAYS_INLINE int __builtin_popcount(unsigned int x) {
return int(__popcnt(x));
}

-#if !defined(_MSC_VER) || (_MSC_VER < 1923)
FOLLY_ALWAYS_INLINE int __builtin_popcountl(unsigned long x) {
static_assert(sizeof(x) == 4, "");
return int(__popcnt(x));
}
-#endif // !defined(_MSC_VER) || (_MSC_VER < 1923)
#endif

-#if !defined(_MSC_VER) || (_MSC_VER < 1923)
#if defined(_M_IX86)
FOLLY_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x) {
return int(__popcnt((unsigned int)(x >> 32))) +
@@ -138,7 +133,6 @@ FOLLY_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x) {
return int(__popcnt64(x));
}
#endif
-#endif // !defined(_MSC_VER) || (_MSC_VER < 1923)

FOLLY_ALWAYS_INLINE void* __builtin_return_address(unsigned int frame) {
// I really hope frame is zero...
--

diff --git a/folly/portability/Builtins.h b/folly/portability/Builtins.h
index e68de4456..30caf4003 100644
--- a/folly/portability/Builtins.h
+++ b/folly/portability/Builtins.h
@@ -16,7 +16,7 @@

#pragma once

dmn-star marked this conversation as resolved.
Show resolved Hide resolved
-#if defined(_WIN32) && !defined(__clang__)
+#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__clang__)
#include <assert.h>
#include <folly/Portability.h>
#include <intrin.h>
--
see https://github.com/facebook/folly/issues/1412
diff --git a/folly/portability/Builtins.h b/folly/portability/Builtins.h
index 30caf4003..e8ef97266 100644
--- a/folly/portability/Builtins.h
+++ b/folly/portability/Builtins.h
@@ -22,6 +22,14 @@
#include <intrin.h>
#include <stdint.h>

+// MSVC had added support for __builtin_clz etc. in 16.3 (1923) but it will be
dmn-star marked this conversation as resolved.
Show resolved Hide resolved
+// removed in 16.8 (1928).
+#if (_MSC_VER >= 1923) && (_MSC_VER < 1928)
+#define FOLLY_DETAILFOLLY_DETAIL_MSC_BUILTIN_SUPPORT 1
+#else
+#define FOLLY_DETAILFOLLY_DETAIL_MSC_BUILTIN_SUPPORT 0
+#endif
+
namespace folly {
namespace portability {
namespace detail {
@@ -41,6 +49,7 @@ FOLLY_ALWAYS_INLINE void __builtin___clear_cache(char* begin, char* end) {
}
}

+#if !defined(_MSC_VER) || !defined(FOLLY_DETAIL_MSC_BUILTIN_SUPPORT)
FOLLY_ALWAYS_INLINE int __builtin_clz(unsigned int x) {
unsigned long index;
return int(_BitScanReverse(&index, (unsigned long)x) ? 31 - index : 32);
@@ -92,6 +101,7 @@ FOLLY_ALWAYS_INLINE int __builtin_ctzll(unsigned long long x) {
return int(_BitScanForward64(&index, x) ? index : 64);
}
#endif
+#endif // !defined(_MSC_VER) || !defined(FOLLY_DETAIL_MSC_BUILTIN_SUPPORT)

FOLLY_ALWAYS_INLINE int __builtin_ffs(int x) {
unsigned long index;
@@ -117,12 +127,15 @@ FOLLY_ALWAYS_INLINE int __builtin_popcount(unsigned int x) {
return int(__popcnt(x));
}

+#if !defined(_MSC_VER) || !defined(FOLLY_DETAIL_MSC_BUILTIN_SUPPORT)
FOLLY_ALWAYS_INLINE int __builtin_popcountl(unsigned long x) {
static_assert(sizeof(x) == 4, "");
return int(__popcnt(x));
}
+#endif // !defined(_MSC_VER) || !defined(FOLLY_DETAIL_MSC_BUILTIN_SUPPORT)
#endif

+#if !defined(_MSC_VER) || !defined(FOLLY_DETAIL_MSC_BUILTIN_SUPPORT)
#if defined(_M_IX86)
FOLLY_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x) {
return int(__popcnt((unsigned int)(x >> 32))) +
@@ -133,6 +146,7 @@ FOLLY_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x) {
return int(__popcnt64(x));
}
#endif
+#endif // !defined(_MSC_VER) || !defined(FOLLY_DETAIL_MSC_BUILTIN_SUPPORT)

FOLLY_ALWAYS_INLINE void* __builtin_return_address(unsigned int frame) {
// I really hope frame is zero...
@@ -141,3 +155,5 @@ FOLLY_ALWAYS_INLINE void* __builtin_return_address(unsigned int frame) {
return _ReturnAddress();
}
#endif
+
+#undef FOLLY_DETAIL_MSC_BUILTIN_SUPPORT
--