Skip to content

Commit cc980bf

Browse files
committed
Speculatively revert r354051 "Recommit Optional specialization for trivially copyable types"
and r354055 "Optional specialization for trivially copyable types, part2" These are suspected to cause Clang to get miscompiled on Ubuntu 14.04 (Trusty) which uses GCC 4.8.4. Reverting for an hour to see if this helps. See llvm-commits thread. > Recommit Optional specialization for trivially copyable types > > Unfortunately the original code gets misscompiled by GCC (at least 8.1), > this is a tentative workaround using std::memcpy instead of inplace new > for trivially copyable types. I'll revert if it breaks. > > Original revision: https://reviews.llvm.org/D57097 llvm-svn: 354126
1 parent 4f85014 commit cc980bf

File tree

2 files changed

+0
-65
lines changed

2 files changed

+0
-65
lines changed

llvm/include/llvm/ADT/Optional.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "llvm/Support/type_traits.h"
2222
#include <algorithm>
2323
#include <cassert>
24-
#include <cstring>
2524
#include <new>
2625
#include <utility>
2726

@@ -110,50 +109,6 @@ template <typename T, bool = is_trivially_copyable<T>::value> struct OptionalSto
110109
}
111110
};
112111

113-
template <typename T> struct OptionalStorage<T, true> {
114-
AlignedCharArrayUnion<T> storage;
115-
bool hasVal = false;
116-
117-
OptionalStorage() = default;
118-
119-
OptionalStorage(const T &y) : hasVal(true) {
120-
std::memcpy(storage.buffer, reinterpret_cast<char const *>(&y), sizeof(T));
121-
}
122-
OptionalStorage(const OptionalStorage &O) = default;
123-
OptionalStorage(T &&y) : hasVal(true) {
124-
std::memcpy(storage.buffer, reinterpret_cast<char*>(&y), sizeof(T));
125-
}
126-
127-
OptionalStorage(OptionalStorage &&O) = default;
128-
129-
OptionalStorage &operator=(T &&y) {
130-
hasVal = true;
131-
std::memcpy(storage.buffer, reinterpret_cast<char*>(&y), sizeof(T));
132-
return *this;
133-
}
134-
OptionalStorage &operator=(OptionalStorage &&O) = default;
135-
136-
OptionalStorage &operator=(const T &y) {
137-
hasVal = true;
138-
std::memcpy(storage.buffer, reinterpret_cast<char const*>(&y), sizeof(T));
139-
return *this;
140-
}
141-
OptionalStorage &operator=(const OptionalStorage &O) = default;
142-
143-
~OptionalStorage() = default;
144-
145-
T *getPointer() {
146-
assert(hasVal);
147-
return reinterpret_cast<T *>(storage.buffer);
148-
}
149-
const T *getPointer() const {
150-
assert(hasVal);
151-
return reinterpret_cast<const T *>(storage.buffer);
152-
}
153-
154-
void reset() { hasVal = false; }
155-
};
156-
157112
} // namespace optional_detail
158113

159114
template <typename T> class Optional {

llvm/unittests/ADT/OptionalTest.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ using namespace llvm;
1818

1919
namespace {
2020

21-
static_assert(llvm::is_trivially_copyable<Optional<int>>::value,
22-
"trivially copyable");
23-
24-
static_assert(llvm::is_trivially_copyable<Optional<std::array<int, 3>>>::value,
25-
"trivially copyable");
26-
2721
struct NonDefaultConstructible {
2822
static unsigned CopyConstructions;
2923
static unsigned Destructions;
@@ -51,10 +45,6 @@ unsigned NonDefaultConstructible::CopyConstructions = 0;
5145
unsigned NonDefaultConstructible::Destructions = 0;
5246
unsigned NonDefaultConstructible::CopyAssignments = 0;
5347

54-
static_assert(
55-
!llvm::is_trivially_copyable<Optional<NonDefaultConstructible>>::value,
56-
"not trivially copyable");
57-
5848
// Test fixture
5949
class OptionalTest : public testing::Test {
6050
};
@@ -213,10 +203,6 @@ struct MultiArgConstructor {
213203
};
214204
unsigned MultiArgConstructor::Destructions = 0;
215205

216-
static_assert(
217-
!llvm::is_trivially_copyable<Optional<MultiArgConstructor>>::value,
218-
"not trivially copyable");
219-
220206
TEST_F(OptionalTest, Emplace) {
221207
MultiArgConstructor::ResetCounts();
222208
Optional<MultiArgConstructor> A;
@@ -264,9 +250,6 @@ unsigned MoveOnly::MoveConstructions = 0;
264250
unsigned MoveOnly::Destructions = 0;
265251
unsigned MoveOnly::MoveAssignments = 0;
266252

267-
static_assert(!llvm::is_trivially_copyable<Optional<MoveOnly>>::value,
268-
"not trivially copyable");
269-
270253
TEST_F(OptionalTest, MoveOnlyNull) {
271254
MoveOnly::ResetCounts();
272255
Optional<MoveOnly> O;
@@ -368,9 +351,6 @@ struct Immovable {
368351
unsigned Immovable::Constructions = 0;
369352
unsigned Immovable::Destructions = 0;
370353

371-
static_assert(!llvm::is_trivially_copyable<Optional<Immovable>>::value,
372-
"not trivially copyable");
373-
374354
TEST_F(OptionalTest, ImmovableEmplace) {
375355
Optional<Immovable> A;
376356
Immovable::ResetCounts();

0 commit comments

Comments
 (0)