From 2b64fcb9463ebca5d06fa73e5e31e7625cca8f8d Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 26 Jan 2018 01:22:17 +0000 Subject: [PATCH] libcxx: Use vcruntime declarations for typeinfo on Windows. We need to use the vcruntime declarations on Windows to avoid an ODR violation involving rtti.obj, which provides the definition of the runtime function implementing dynamic_cast and depends on the vcruntime implementations of bad_cast and bad_typeid. Differential Revision: https://reviews.llvm.org/D42220 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@323491 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/typeinfo | 6 ++++++ src/support/runtime/exception_msvc.ipp | 2 +- src/typeinfo.cpp | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/typeinfo b/include/typeinfo index 7e8d3990e..74d94e9e3 100644 --- a/include/typeinfo +++ b/include/typeinfo @@ -69,6 +69,10 @@ public: #pragma GCC system_header #endif +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) +#include +#else + #if !defined(_LIBCPP_ABI_MICROSOFT) #if defined(_LIBCPP_NONUNIQUE_RTTI_BIT) #define _LIBCPP_HAS_NONUNIQUE_TYPEINFO @@ -219,6 +223,8 @@ public: } // std +#endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) + _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE void __throw_bad_cast() diff --git a/src/support/runtime/exception_msvc.ipp b/src/support/runtime/exception_msvc.ipp index 854d3864f..87d5a66fc 100644 --- a/src/support/runtime/exception_msvc.ipp +++ b/src/support/runtime/exception_msvc.ipp @@ -97,6 +97,7 @@ bad_array_length::what() const _NOEXCEPT return "bad_array_length"; } +#if defined(_LIBCPP_NO_VCRUNTIME) bad_cast::bad_cast() _NOEXCEPT { } @@ -125,7 +126,6 @@ bad_typeid::what() const _NOEXCEPT return "std::bad_typeid"; } -#if defined(_LIBCPP_NO_VCRUNTIME) exception::~exception() _NOEXCEPT { } diff --git a/src/typeinfo.cpp b/src/typeinfo.cpp index 0cb193b77..42ff9351e 100644 --- a/src/typeinfo.cpp +++ b/src/typeinfo.cpp @@ -9,7 +9,7 @@ #include "typeinfo" -#if defined(_LIBCPP_ABI_MICROSOFT) +#if defined(_LIBCPP_ABI_MICROSOFT) && defined(_LIBCPP_NO_VCRUNTIME) #include int std::type_info::__compare(const type_info &__rhs) const _NOEXCEPT { @@ -49,7 +49,8 @@ size_t std::type_info::hash_code() const _NOEXCEPT { // FIXME: Remove __APPLE__ default here once buildit is gone. // FIXME: Remove the _LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY configuration. #if (!defined(LIBCXX_BUILDING_LIBCXXABI) && !defined(LIBCXXRT) && \ - !defined(__GLIBCXX__) && !defined(__APPLE__)) || \ + !defined(__GLIBCXX__) && !defined(__APPLE__) && \ + !(defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME))) || \ defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) std::type_info::~type_info() {