Commit a228d714 authored by Shoaib Meenai's avatar Shoaib Meenai Committed by Facebook Github Bot

Correct exception wrapper MSVC conditional

Summary:
The layout of an exception_ptr is determined by the ABI, not the OS. MinGW (and
Cygwin, depending on the build settings) define `_WIN32` and would therefore
have `kIsWindows` be true, but they use the Itanium ABI instead of Microsoft's,
so we shouldn't take the MSVC codepath for them.

Unfortunately, there isn't a reliable preprocessor method to determine the ABI
being used. `_MSC_VER` can be defined even when using the Itanium ABI (e.g.
when using windows-itanium triples with clang), and `_MSC_VER` can be undefined
even when using the Microsoft ABI (e.g. when building with `-fno-ms-extensions`
with clang).

To address this, introduce `kMicrosoftAbiVer`, which defaults to `_MSC_VER`,
but can be overridden manually if necessary. This should do the right thing by
default most of the time, while providing an escape hatch for when `_MSC_VER`
would be incorrect to use directly.

Reviewed By: yfeldblum

Differential Revision: D7377853

fbshipit-source-id: dd868370e9a496b98dd26dec77c4a75c49147c3c
parent 37515540
...@@ -163,3 +163,10 @@ ...@@ -163,3 +163,10 @@
#else #else
#define FOLLY_ATTR_WEAK #define FOLLY_ATTR_WEAK
#endif #endif
// Microsoft ABI version (can be overridden manually if necessary)
#ifndef FOLLY_MICROSOFT_ABI_VER
#ifdef _MSC_VER
#define FOLLY_MICROSOFT_ABI_VER _MSC_VER
#endif
#endif
...@@ -93,14 +93,14 @@ inline std::exception const* exception_wrapper::as_exception_or_null_( ...@@ -93,14 +93,14 @@ inline std::exception const* exception_wrapper::as_exception_or_null_(
} }
static_assert( static_assert(
!kIsWindows || (kMscVer >= 1900 && kMscVer <= 2000), !kMicrosoftAbiVer || (kMicrosoftAbiVer >= 1900 && kMicrosoftAbiVer <= 2000),
"exception_wrapper is untested and possibly broken on your version of " "exception_wrapper is untested and possibly broken on your version of "
"MSVC"); "MSVC");
inline std::uintptr_t exception_wrapper::ExceptionPtr::as_int_( inline std::uintptr_t exception_wrapper::ExceptionPtr::as_int_(
std::exception_ptr const& ptr, std::exception_ptr const& ptr,
std::exception const& e) { std::exception const& e) {
if (!kIsWindows) { if (!kMicrosoftAbiVer) {
return reinterpret_cast<std::uintptr_t>(&e); return reinterpret_cast<std::uintptr_t>(&e);
} else { } else {
// On Windows, as of MSVC2017, all thrown exceptions are copied to the stack // On Windows, as of MSVC2017, all thrown exceptions are copied to the stack
......
...@@ -357,6 +357,12 @@ constexpr auto kMscVer = _MSC_VER; ...@@ -357,6 +357,12 @@ constexpr auto kMscVer = _MSC_VER;
constexpr auto kMscVer = 0; constexpr auto kMscVer = 0;
#endif #endif
#if FOLLY_MICROSOFT_ABI_VER
constexpr auto kMicrosoftAbiVer = FOLLY_MICROSOFT_ABI_VER;
#else
constexpr auto kMicrosoftAbiVer = 0;
#endif
// TODO: Remove when removing support for gcc4.9 // TODO: Remove when removing support for gcc4.9
#if __GLIBCXX__ && __GLIBCXX__ == 20150123 #if __GLIBCXX__ && __GLIBCXX__ == 20150123
constexpr auto kIsGlib49 = true; constexpr auto kIsGlib49 = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment