Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -325,6 +325,15 @@ unset(HAVE_FFI_CALL CACHE) endif( LLVM_ENABLE_FFI ) +# Whether we can use std::is_trivially_copyable to verify llvm::is_trivially_copyable. +CHECK_CXX_SOURCE_COMPILES(" +#include +struct T { int val; }; +static_assert(std::is_trivially_copyable::value, \"ok\"); +int main() { return 0;} +" HAVE_STD_IS_TRIVIALLY_COPYABLE) + + # Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported. include(CheckAtomic) Index: include/llvm/ADT/PointerIntPair.h =================================================================== --- include/llvm/ADT/PointerIntPair.h +++ include/llvm/ADT/PointerIntPair.h @@ -14,6 +14,7 @@ #define LLVM_ADT_POINTERINTPAIR_H #include "llvm/Support/PointerLikeTypeTraits.h" +#include "llvm/Support/type_traits.h" #include #include #include @@ -125,6 +126,19 @@ } }; +// Specialize is_trivially_copyable to avoid limitation of llvm::is_trivially_copyable +// when compiled with gcc 4.9. +template +struct is_trivially_copyable> : std::true_type { +#ifdef HAVE_STD_IS_TRIVIALLY_COPYABLE + static_assert(std::is_trivially_copyable>::value, + "inconsistent behavior between llvm:: and std:: implementation of is_trivially_copyable"); +#endif +}; + + template struct PointerIntPairInfo { static_assert(PtrTraits::NumLowBitsAvailable < Index: include/llvm/Config/config.h.cmake =================================================================== --- include/llvm/Config/config.h.cmake +++ include/llvm/Config/config.h.cmake @@ -338,6 +338,9 @@ /* Define as the return type of signal handlers (`int' or `void'). */ #cmakedefine RETSIGTYPE ${RETSIGTYPE} +/* Define if std::is_trivially_copyable is supported */ +#cmakedefine HAVE_STD_IS_TRIVIALLY_COPYABLE ${HAVE_STD_IS_TRIVIALLY_COPYABLE} + /* Define to a function implementing stricmp */ #cmakedefine stricmp ${stricmp} Index: include/llvm/Support/type_traits.h =================================================================== --- include/llvm/Support/type_traits.h +++ include/llvm/Support/type_traits.h @@ -95,6 +95,7 @@ union trivial_helper { T t; }; + } // end namespace detail /// An implementation of `std::is_trivially_copy_constructible` since we have @@ -119,6 +120,24 @@ template struct is_trivially_move_constructible : std::true_type {}; + +template +struct is_copy_assignable { + template + static auto get(F*) -> decltype(std::declval() = std::declval(), std::true_type{}); + static std::false_type get(...); + static constexpr bool value = decltype(get((T*)nullptr))::value; +}; + +template +struct is_move_assignable { + template + static auto get(F*) -> decltype(std::declval() = std::declval(), std::true_type{}); + static std::false_type get(...); + static constexpr bool value = decltype(get((T*)nullptr))::value; +}; + + // An implementation of `std::is_trivially_copyable` since STL version // is not equally supported by all compilers, especially GCC 4.9. // Uniform implementation of this trait is important for ABI compatibility @@ -140,15 +159,15 @@ // copy assign static constexpr bool has_trivial_copy_assign = - std::is_copy_assignable>::value; + is_copy_assignable>::value; static constexpr bool has_deleted_copy_assign = - !std::is_copy_assignable::value; + !is_copy_assignable::value; // move assign static constexpr bool has_trivial_move_assign = - std::is_move_assignable>::value; + is_move_assignable>::value; static constexpr bool has_deleted_move_assign = - !std::is_move_assignable::value; + !is_move_assignable::value; // destructor static constexpr bool has_trivial_destructor = @@ -163,10 +182,14 @@ (has_deleted_copy_assign || has_trivial_copy_assign) && (has_deleted_copy_constructor || has_trivial_copy_constructor); -#if (__has_feature(is_trivially_copyable) || (defined(__GNUC__) && __GNUC__ >= 5)) - static_assert(value == std::is_trivially_copyable::value, "inconsistent behavior between llvm:: and std:: implementation of is_trivially_copyable"); +#ifdef HAVE_STD_IS_TRIVIALLY_COPYABLE + static_assert(value == std::is_trivially_copyable::value, + "inconsistent behavior between llvm:: and std:: implementation of is_trivially_copyable"); #endif }; +template +class is_trivially_copyable : public std::true_type { +}; } // end namespace llvm