[llvm] r347004 - Re-apply r346985: [ADT] Drop llvm::Optional clang-specific optimization for trivially copyable types

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 15 16:47:24 PST 2018


Author: tstellar
Date: Thu Nov 15 16:47:24 2018
New Revision: 347004

URL: http://llvm.org/viewvc/llvm-project?rev=347004&view=rev
Log:
Re-apply r346985: [ADT] Drop llvm::Optional clang-specific optimization for trivially copyable types

Remove a test case that was added with the optimization we are now
removing.

Modified:
    llvm/trunk/include/llvm/ADT/Optional.h
    llvm/trunk/unittests/ADT/OptionalTest.cpp

Modified: llvm/trunk/include/llvm/ADT/Optional.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Optional.h?rev=347004&r1=347003&r2=347004&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/Optional.h (original)
+++ llvm/trunk/include/llvm/ADT/Optional.h Thu Nov 15 16:47:24 2018
@@ -108,24 +108,6 @@ template <typename T, bool IsPodLike> st
   }
 };
 
-#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 {

Modified: llvm/trunk/unittests/ADT/OptionalTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/OptionalTest.cpp?rev=347004&r1=347003&r2=347004&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/OptionalTest.cpp (original)
+++ llvm/trunk/unittests/ADT/OptionalTest.cpp Thu Nov 15 16:47:24 2018
@@ -518,13 +518,5 @@ TEST_F(OptionalTest, OperatorGreaterEqua
   CheckRelation<GreaterEqual>(InequalityLhs, InequalityRhs, !IsLess);
 }
 
-#if __has_feature(is_trivially_copyable) && defined(_LIBCPP_VERSION)
-static_assert(std::is_trivially_copyable<Optional<int>>::value,
-              "Should be trivially copyable");
-static_assert(
-    !std::is_trivially_copyable<Optional<NonDefaultConstructible>>::value,
-    "Shouldn't be trivially copyable");
-#endif
-
 } // end anonymous namespace
 




More information about the llvm-commits mailing list