From 67666d76299e53db551541493485aad8155fe87f Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Thu, 15 Nov 2018 20:27:11 +0000 Subject: [PATCH] Revert "[ADT] Drop llvm::Optional clang-specific optmization for trivially copyable types" This reverts commit r346985. It looks like one of the unittests also needs to be updated, reverting while I investigate. llvm-svn: 346990 --- llvm/include/llvm/ADT/Optional.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h index 9fe9b28..353e5d0 100644 --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -108,6 +108,24 @@ 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; + bool hasVal = false; + + OptionalStorage() = default; + + OptionalStorage(const T &y) : hasVal(true) { new (storage.buffer) T(y); } + OptionalStorage &operator=(const T &y) { + *reinterpret_cast(storage.buffer) = y; + hasVal = true; + return *this; + } + + void reset() { hasVal = false; } +}; +#endif } // namespace optional_detail template class Optional { -- 2.7.4