[ADT] Bring back memmove to make GCC 5.4 happy
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 20 Sep 2018 12:21:24 +0000 (12:21 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 20 Sep 2018 12:21:24 +0000 (12:21 +0000)
All other GCCs look good so far. GCC 5.4 complains about strict
aliasing, so fix that.

llvm-svn: 342643

llvm/include/llvm/ADT/Optional.h

index 9242a0a..c09c9c7 100644 (file)
@@ -22,6 +22,7 @@
 #include "llvm/Support/type_traits.h"
 #include <algorithm>
 #include <cassert>
+#include <cstring>
 #include <new>
 #include <utility>
 
@@ -115,9 +116,11 @@ template <typename T> struct OptionalStorage<T, true> {
 
   OptionalStorage() = default;
 
-  OptionalStorage(const T &y) : hasVal(true) { new (storage.buffer) T(y); }
+  OptionalStorage(const T &y) : hasVal(true) {
+    std::memmove(storage.buffer, &y, sizeof(y));
+  }
   OptionalStorage &operator=(const T &y) {
-    *reinterpret_cast<T *>(storage.buffer) = y;
+    std::memmove(storage.buffer, &y, sizeof(y));
     hasVal = true;
     return *this;
   }