I've seen random crashes with GCC 4.8, GCC 6.3 and GCC 7.3, triggered by
my Optional change. All of them affect a different set of targets. This
change fixes the instance of the problem I'm seeing on my local machine,
let's hope it's good enough for the other instances too.
llvm-svn: 322859
#include <algorithm>
#include <cassert>
#include <new>
+#include <cstring>
#include <utility>
namespace llvm {
OptionalStorage() = default;
- OptionalStorage(const T &y) : hasVal(true) { new (storage.buffer) T(y); }
+ OptionalStorage(const T &y) : hasVal(true) {
+ // We use memmove here because we know that T is trivially copyable and GCC
+ // up to 7 miscompiles placement new.
+ std::memmove(storage.buffer, &y, sizeof(y));
+ }
OptionalStorage &operator=(const T &y) {
- new (storage.buffer) T(y);
hasVal = true;
+ // We use memmove here because we know that T is trivially copyable and GCC
+ // up to 7 miscompiles placement new.
+ std::memmove(storage.buffer, &y, sizeof(y));
return *this;
}