From 03d499113efc9626bd73b7f5754d20346d3074ca Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Tue, 25 Sep 2018 12:08:56 +0000 Subject: [PATCH] Revert r342637 "[ADT] Try again to use the same version of llvm::Optional on all compilers" and also revert follow-ups r342643 and r342723. This caused Clang to be miscompiled by GCC 4.8.4 (Unbuntu 14.04's default compiler) and break the Chromium build (see https://crbug.com/888061). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342966 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/Optional.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/include/llvm/ADT/Optional.h b/include/llvm/ADT/Optional.h index 873933345fa..353e5d0ec9d 100644 --- a/include/llvm/ADT/Optional.h +++ b/include/llvm/ADT/Optional.h @@ -22,7 +22,6 @@ #include "llvm/Support/type_traits.h" #include #include -#include #include #include @@ -109,6 +108,7 @@ template struct OptionalStorage { } }; +#if !defined(__GNUC__) || defined(__clang__) // GCC up to GCC7 miscompiles this. /// Storage for trivially copyable types only. template struct OptionalStorage { AlignedCharArrayUnion storage; @@ -116,24 +116,20 @@ template struct OptionalStorage { OptionalStorage() = default; - OptionalStorage(const T &y) : hasVal(true) { - std::memmove(storage.buffer, &y, sizeof(y)); - } + OptionalStorage(const T &y) : hasVal(true) { new (storage.buffer) T(y); } OptionalStorage &operator=(const T &y) { - std::memmove(storage.buffer, &y, sizeof(y)); + *reinterpret_cast(storage.buffer) = y; hasVal = true; return *this; } void reset() { hasVal = false; } }; +#endif } // namespace optional_detail template class Optional { - // GCC 5.4 miscompiles the trivially copyable OptionalStorage. Blacklist it. - optional_detail::OptionalStorage::value && - !std::is_enum::value> - Storage; + optional_detail::OptionalStorage::value> Storage; public: using value_type = T; -- 2.11.4.GIT