1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

ADT: Stop peeking inside AlignedCharArrayUnion, NFC

Update all the users of `AlignedCharArrayUnion` to stop peeking inside
(to look at `buffer`) so that a follow-up patch can replace it with an
alias to `std::aligned_union_t`.

This was reviewed as part of https://reviews.llvm.org/D92512, but I'm
splitting this bit out to commit first to reduce churn in case the
change to `AlignedCharArrayUnion` needs to be reverted for some
unexpected reason.
This commit is contained in:
Duncan P. N. Exon Smith 2020-12-02 13:44:16 -08:00
parent e814afa1c5
commit f1e94c82c9
8 changed files with 24 additions and 27 deletions

View File

@ -1042,7 +1042,7 @@ public:
if (Small) {
// First move the inline buckets into a temporary storage.
AlignedCharArrayUnion<BucketT[InlineBuckets]> TmpStorage;
BucketT *TmpBegin = reinterpret_cast<BucketT *>(TmpStorage.buffer);
BucketT *TmpBegin = reinterpret_cast<BucketT *>(&TmpStorage);
BucketT *TmpEnd = TmpBegin;
// Loop over the buckets, moving non-empty, non-tombstones into the
@ -1132,8 +1132,8 @@ private:
assert(Small);
// Note that this cast does not violate aliasing rules as we assert that
// the memory's dynamic type is the small, inline bucket buffer, and the
// 'storage.buffer' static type is 'char *'.
return reinterpret_cast<const BucketT *>(storage.buffer);
// 'storage' is a POD containing a char buffer.
return reinterpret_cast<const BucketT *>(&storage);
}
BucketT *getInlineBuckets() {
@ -1144,7 +1144,7 @@ private:
const LargeRep *getLargeRep() const {
assert(!Small);
// Note, same rule about aliasing as with getInlineBuckets.
return reinterpret_cast<const LargeRep *>(storage.buffer);
return reinterpret_cast<const LargeRep *>(&storage);
}
LargeRep *getLargeRep() {

View File

@ -978,10 +978,7 @@ private:
Allocator &allocator;
/// Represent data as a node type without breaking aliasing rules.
template <typename T>
T &dataAs() const {
return *bit_cast<T *>(const_cast<char *>(data.buffer));
}
template <typename T> T &dataAs() const { return *bit_cast<T *>(&data); }
const RootLeaf &rootLeaf() const {
assert(!branched() && "Cannot acces leaf data in branched root");
@ -1039,7 +1036,7 @@ private:
public:
explicit IntervalMap(Allocator &a) : height(0), rootSize(0), allocator(a) {
assert((uintptr_t(data.buffer) & (alignof(RootLeaf) - 1)) == 0 &&
assert((uintptr_t(&data) & (alignof(RootLeaf) - 1)) == 0 &&
"Insufficient alignment");
new(&rootLeaf()) RootLeaf();
}

View File

@ -383,12 +383,12 @@ private:
static_assert(std::is_standard_layout<T>::value ||
std::is_pointer<T>::value,
"Expected standard layout or pointer");
new (reinterpret_cast<void *>(Val.buffer)) T(V);
new (reinterpret_cast<void *>(&Val)) T(V);
}
template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
template <class T> T *get() { return reinterpret_cast<T *>(&Val); }
template <class T> const T *get() const {
return reinterpret_cast<const T *>(Val.buffer);
return reinterpret_cast<const T *>(&Val);
}
template <class T> void destruct() { get<T>()->~T(); }

View File

@ -629,22 +629,22 @@ private:
storage_type *getStorage() {
assert(!HasError && "Cannot get value when an error exists!");
return reinterpret_cast<storage_type *>(TStorage.buffer);
return reinterpret_cast<storage_type *>(&TStorage);
}
const storage_type *getStorage() const {
assert(!HasError && "Cannot get value when an error exists!");
return reinterpret_cast<const storage_type *>(TStorage.buffer);
return reinterpret_cast<const storage_type *>(&TStorage);
}
error_type *getErrorStorage() {
assert(HasError && "Cannot get error when a value exists!");
return reinterpret_cast<error_type *>(ErrorStorage.buffer);
return reinterpret_cast<error_type *>(&ErrorStorage);
}
const error_type *getErrorStorage() const {
assert(HasError && "Cannot get error when a value exists!");
return reinterpret_cast<const error_type *>(ErrorStorage.buffer);
return reinterpret_cast<const error_type *>(&ErrorStorage);
}
// Used by ExpectedAsOutParameter to reset the checked flag.

View File

@ -235,17 +235,17 @@ private:
storage_type *getStorage() {
assert(!HasError && "Cannot get value when an error exists!");
return reinterpret_cast<storage_type*>(TStorage.buffer);
return reinterpret_cast<storage_type *>(&TStorage);
}
const storage_type *getStorage() const {
assert(!HasError && "Cannot get value when an error exists!");
return reinterpret_cast<const storage_type*>(TStorage.buffer);
return reinterpret_cast<const storage_type *>(&TStorage);
}
std::error_code *getErrorStorage() {
assert(HasError && "Cannot get error when a value exists!");
return reinterpret_cast<std::error_code *>(ErrorStorage.buffer);
return reinterpret_cast<std::error_code *>(&ErrorStorage);
}
const std::error_code *getErrorStorage() const {

View File

@ -456,12 +456,12 @@ private:
friend class Object;
template <typename T, typename... U> void create(U &&... V) {
new (reinterpret_cast<T *>(Union.buffer)) T(std::forward<U>(V)...);
new (reinterpret_cast<T *>(&Union)) T(std::forward<U>(V)...);
}
template <typename T> T &as() const {
// Using this two-step static_cast via void * instead of reinterpret_cast
// silences a -Wstrict-aliasing false positive from GCC6 and earlier.
void *Storage = static_cast<void *>(Union.buffer);
void *Storage = static_cast<void *>(&Union);
return *static_cast<T *>(Storage);
}

View File

@ -109,7 +109,7 @@ void Value::copyFrom(const Value &M) {
case T_Boolean:
case T_Double:
case T_Integer:
memcpy(Union.buffer, M.Union.buffer, sizeof(Union.buffer));
memcpy(&Union, &M.Union, sizeof(Union));
break;
case T_StringRef:
create<StringRef>(M.as<StringRef>());
@ -133,7 +133,7 @@ void Value::moveFrom(const Value &&M) {
case T_Boolean:
case T_Double:
case T_Integer:
memcpy(Union.buffer, M.Union.buffer, sizeof(Union.buffer));
memcpy(&Union, &M.Union, sizeof(Union));
break;
case T_StringRef:
create<StringRef>(M.as<StringRef>());

View File

@ -82,11 +82,11 @@ namespace {
private:
bool insaneIntVal(int V) { return V > 4 || V < -4; }
APFloat *getFpValPtr()
{ return reinterpret_cast<APFloat *>(&FpValBuf.buffer[0]); }
APFloat *getFpValPtr() { return reinterpret_cast<APFloat *>(&FpValBuf); }
const APFloat *getFpValPtr() const
{ return reinterpret_cast<const APFloat *>(&FpValBuf.buffer[0]); }
const APFloat *getFpValPtr() const {
return reinterpret_cast<const APFloat *>(&FpValBuf);
}
const APFloat &getFpVal() const {
assert(IsFp && BufHasFpVal && "Incorret state");