aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <tstellar@redhat.com>2018-11-15 20:27:11 +0000
committerTom Stellard <tstellar@redhat.com>2018-11-15 20:27:11 +0000
commit67666d76299e53db551541493485aad8155fe87f (patch)
tree98a5b302bb25472bb44fb10613b964cbc8632a3a
parentaacebba5e66b4bdd04b13dd5346f5a35b5e8f87d (diff)
downloadllvm-67666d76299e53db551541493485aad8155fe87f.zip
llvm-67666d76299e53db551541493485aad8155fe87f.tar.gz
llvm-67666d76299e53db551541493485aad8155fe87f.tar.bz2
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
-rw-r--r--llvm/include/llvm/ADT/Optional.h18
1 files changed, 18 insertions, 0 deletions
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 <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;
+ bool hasVal = false;
+
+ OptionalStorage() = default;
+
+ OptionalStorage(const T &y) : hasVal(true) { new (storage.buffer) T(y); }
+ OptionalStorage &operator=(const T &y) {
+ *reinterpret_cast<T *>(storage.buffer) = y;
+ hasVal = true;
+ return *this;
+ }
+
+ void reset() { hasVal = false; }
+};
+#endif
} // namespace optional_detail
template <typename T> class Optional {