diff options
author | Hans Wennborg <hans@hanshq.net> | 2018-09-25 12:08:56 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2018-09-25 12:08:56 +0000 |
commit | 99d98ed2b246b013fcd9769f783af880c80c7e5f (patch) | |
tree | 403d638c73dba44da28fc4fbb5fd600cd5b793c7 | |
parent | 6c2f5bd0f1b13cc24f85c3c8da8e3667644e485e (diff) | |
download | bcm5719-llvm-99d98ed2b246b013fcd9769f783af880c80c7e5f.tar.gz bcm5719-llvm-99d98ed2b246b013fcd9769f783af880c80c7e5f.zip |
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).
llvm-svn: 342966
-rw-r--r-- | llvm/include/llvm/ADT/Optional.h | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h index 873933345fa..353e5d0ec9d 100644 --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -22,7 +22,6 @@ #include "llvm/Support/type_traits.h" #include <algorithm> #include <cassert> -#include <cstring> #include <new> #include <utility> @@ -109,6 +108,7 @@ template <typename T, bool IsPodLike> struct OptionalStorage { } }; +#if !defined(__GNUC__) || defined(__clang__) // GCC up to GCC7 miscompiles this. /// Storage for trivially copyable types only. template <typename T> struct OptionalStorage<T, true> { AlignedCharArrayUnion<T> storage; @@ -116,24 +116,20 @@ template <typename T> struct OptionalStorage<T, true> { 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<T *>(storage.buffer) = y; hasVal = true; return *this; } void reset() { hasVal = false; } }; +#endif } // namespace optional_detail template <typename T> class Optional { - // GCC 5.4 miscompiles the trivially copyable OptionalStorage. Blacklist it. - optional_detail::OptionalStorage<T, isPodLike<T>::value && - !std::is_enum<T>::value> - Storage; + optional_detail::OptionalStorage<T, isPodLike<T>::value> Storage; public: using value_type = T; |