Commit 6b4af249 by Aaron Jacobs Committed by Copybara-Service

type_traits: don't use __is_trivially_relocatable with Clang on Windows.

It currently gives the wrong result for types with a user-provided destructor:

    struct S {
      ~S();
    };

    static_assert(!__is_trivially_relocatable(S));

PiperOrigin-RevId: 519855600
Change-Id: I5f0659ad0831974805a5ed4b615e3b6250d23154
parent 0dc94309
...@@ -495,11 +495,18 @@ using swap_internal::StdSwapIsUnconstrained; ...@@ -495,11 +495,18 @@ using swap_internal::StdSwapIsUnconstrained;
// Upstream documentation: // Upstream documentation:
// //
// https://clang.llvm.org/docs/LanguageExtensions.html#:~:text=__is_trivially_relocatable // https://clang.llvm.org/docs/LanguageExtensions.html#:~:text=__is_trivially_relocatable
//
#if ABSL_HAVE_BUILTIN(__is_trivially_relocatable)
// If the compiler offers a builtin that tells us the answer, we can use that. // If the compiler offers a builtin that tells us the answer, we can use that.
// This covers all of the cases in the fallback below, plus types that opt in // This covers all of the cases in the fallback below, plus types that opt in
// using e.g. [[clang::trivial_abi]]. // using e.g. [[clang::trivial_abi]].
//
// Clang on Windows has the builtin, but it falsely claims types with a
// user-provided destructor are trivial (http://b/275003464). So we opt out
// there.
//
// TODO(b/275003464): remove the opt-out once the bug is fixed.
#if ABSL_HAVE_BUILTIN(__is_trivially_relocatable) && \
!(defined(__clang__) && (defined(_WIN32) || defined(_WIN64)))
template <class T> template <class T>
struct is_trivially_relocatable struct is_trivially_relocatable
: std::integral_constant<bool, __is_trivially_relocatable(T)> {}; : std::integral_constant<bool, __is_trivially_relocatable(T)> {};
......
...@@ -780,20 +780,6 @@ TEST(TriviallyRelocatable, UserProvidedCopyConstructor) { ...@@ -780,20 +780,6 @@ TEST(TriviallyRelocatable, UserProvidedCopyConstructor) {
static_assert(!absl::is_trivially_relocatable<S>::value, ""); static_assert(!absl::is_trivially_relocatable<S>::value, "");
} }
// HACK: disable this test on Windows, which includes lexan, which gives the
// incorrect result for this case (http://b/275003464).
//
// TODO(b/275003464): make this hack more precise after figuring out how to
// detect --config=lexan in particular. If there is no reliable way, modify
// --config=lexan itself to set a define we can use.
//
// TODO(b/274984172): hoist this hack to the definition of
// absl::is_trivially_relocatable itself, since it's currently giving the wrong
// results under lexan. We can't trust __is_trivially_relocatable on that
// platform.
//
// TODO(b/275003464): remove this hack when the bug is fixed.
#if !(defined(_WIN32) || defined(_WIN64))
// A user-provided destructor disqualifies a type from being trivially // A user-provided destructor disqualifies a type from being trivially
// relocatable. // relocatable.
TEST(TriviallyRelocatable, UserProvidedDestructor) { TEST(TriviallyRelocatable, UserProvidedDestructor) {
...@@ -803,10 +789,12 @@ TEST(TriviallyRelocatable, UserProvidedDestructor) { ...@@ -803,10 +789,12 @@ TEST(TriviallyRelocatable, UserProvidedDestructor) {
static_assert(!absl::is_trivially_relocatable<S>::value, ""); static_assert(!absl::is_trivially_relocatable<S>::value, "");
} }
#endif
#if defined(ABSL_HAVE_ATTRIBUTE_TRIVIAL_ABI) && \ // TODO(b/275003464): remove the opt-out for Clang on Windows once
ABSL_HAVE_BUILTIN(__is_trivially_relocatable) // __is_trivially_relocatable is used there again.
#if defined(ABSL_HAVE_ATTRIBUTE_TRIVIAL_ABI) && \
ABSL_HAVE_BUILTIN(__is_trivially_relocatable) && \
!(defined(__clang__) && (defined(_WIN32) || defined(_WIN64)))
// A type marked with the "trivial ABI" attribute is trivially relocatable even // A type marked with the "trivial ABI" attribute is trivially relocatable even
// if it has user-provided move/copy constructors and a user-provided // if it has user-provided move/copy constructors and a user-provided
// destructor. // destructor.
......
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