Revert "[ADT] Drop llvm::Optional clang-specific optmization for trivially copyable...
authorTom Stellard <tstellar@redhat.com>
Thu, 15 Nov 2018 20:27:11 +0000 (20:27 +0000)
committerTom Stellard <tstellar@redhat.com>
Thu, 15 Nov 2018 20:27:11 +0000 (20:27 +0000)
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

index 9fe9b28..353e5d0 100644 (file)
@@ -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 {