Commit 0738a21a authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[ubsan] Adapt ZoneHandleSet to new Handle internals

By matching ZoneHandleSet's internals to Handle's internals,
we can avoid a few unnecessary casts, and get rid of a few
more occurrences of Object**.

Bug: v8:3770
Change-Id: I24d6bad3a4959d977abf1f6b8db9be50bb2bc6d8
Reviewed-on: https://chromium-review.googlesource.com/c/1330907
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57418}
parent 77b53a8f
...@@ -17,8 +17,8 @@ class ZoneHandleSet final { ...@@ -17,8 +17,8 @@ class ZoneHandleSet final {
public: public:
ZoneHandleSet() : data_(kEmptyTag) {} ZoneHandleSet() : data_(kEmptyTag) {}
explicit ZoneHandleSet(Handle<T> handle) explicit ZoneHandleSet(Handle<T> handle)
: data_(bit_cast<intptr_t>(handle.address()) | kSingletonTag) { : data_(handle.address() | kSingletonTag) {
DCHECK(IsAligned(bit_cast<intptr_t>(handle.address()), kPointerAlignment)); DCHECK(IsAligned(handle.address(), kPointerAlignment));
} }
bool is_empty() const { return data_ == kEmptyTag; } bool is_empty() const { return data_ == kEmptyTag; }
...@@ -41,10 +41,10 @@ class ZoneHandleSet final { ...@@ -41,10 +41,10 @@ class ZoneHandleSet final {
Handle<T> operator[](size_t i) const { return at(i); } Handle<T> operator[](size_t i) const { return at(i); }
void insert(Handle<T> handle, Zone* zone) { void insert(Handle<T> handle, Zone* zone) {
T** const value = bit_cast<T**>(handle.address()); Address* const value = reinterpret_cast<Address*>(handle.address());
DCHECK(IsAligned(bit_cast<intptr_t>(value), kPointerAlignment)); DCHECK(IsAligned(reinterpret_cast<Address>(value), kPointerAlignment));
if ((data_ & kTagMask) == kEmptyTag) { if ((data_ & kTagMask) == kEmptyTag) {
data_ = bit_cast<intptr_t>(value) | kSingletonTag; data_ = reinterpret_cast<Address>(value) | kSingletonTag;
} else if ((data_ & kTagMask) == kSingletonTag) { } else if ((data_ & kTagMask) == kSingletonTag) {
if (singleton() == value) return; if (singleton() == value) return;
List* list = new (zone->New(sizeof(List))) List(zone); List* list = new (zone->New(sizeof(List))) List(zone);
...@@ -55,8 +55,8 @@ class ZoneHandleSet final { ...@@ -55,8 +55,8 @@ class ZoneHandleSet final {
list->push_back(value); list->push_back(value);
list->push_back(singleton()); list->push_back(singleton());
} }
DCHECK(IsAligned(bit_cast<intptr_t>(list), kPointerAlignment)); DCHECK(IsAligned(reinterpret_cast<Address>(list), kPointerAlignment));
data_ = bit_cast<intptr_t>(list) | kListTag; data_ = reinterpret_cast<Address>(list) | kListTag;
} else { } else {
DCHECK_EQ(kListTag, data_ & kTagMask); DCHECK_EQ(kListTag, data_ & kTagMask);
List const* const old_list = list(); List const* const old_list = list();
...@@ -76,8 +76,8 @@ class ZoneHandleSet final { ...@@ -76,8 +76,8 @@ class ZoneHandleSet final {
new_list->push_back(old_list->at(i)); new_list->push_back(old_list->at(i));
} }
DCHECK_EQ(old_list->size() + 1, new_list->size()); DCHECK_EQ(old_list->size() + 1, new_list->size());
DCHECK(IsAligned(bit_cast<intptr_t>(new_list), kPointerAlignment)); DCHECK(IsAligned(reinterpret_cast<Address>(new_list), kPointerAlignment));
data_ = bit_cast<intptr_t>(new_list) | kListTag; data_ = reinterpret_cast<Address>(new_list) | kListTag;
} }
} }
...@@ -105,12 +105,13 @@ class ZoneHandleSet final { ...@@ -105,12 +105,13 @@ class ZoneHandleSet final {
bool contains(Handle<T> other) const { bool contains(Handle<T> other) const {
if (data_ == kEmptyTag) return false; if (data_ == kEmptyTag) return false;
Address* other_address = reinterpret_cast<Address*>(other.address());
if ((data_ & kTagMask) == kSingletonTag) { if ((data_ & kTagMask) == kSingletonTag) {
return singleton() == bit_cast<T**>(other.address()); return singleton() == other_address;
} }
DCHECK_EQ(kListTag, data_ & kTagMask); DCHECK_EQ(kListTag, data_ & kTagMask);
return std::find(list()->begin(), list()->end(), return std::find(list()->begin(), list()->end(), other_address) !=
bit_cast<T**>(other.address())) != list()->end(); list()->end();
} }
void remove(Handle<T> handle, Zone* zone) { void remove(Handle<T> handle, Zone* zone) {
...@@ -156,19 +157,19 @@ class ZoneHandleSet final { ...@@ -156,19 +157,19 @@ class ZoneHandleSet final {
inline const_iterator end() const; inline const_iterator end() const;
private: private:
typedef ZoneVector<T**> List; typedef ZoneVector<Address*> List;
List const* list() const { List const* list() const {
DCHECK_EQ(kListTag, data_ & kTagMask); DCHECK_EQ(kListTag, data_ & kTagMask);
return bit_cast<List const*>(data_ - kListTag); return reinterpret_cast<List const*>(data_ - kListTag);
} }
T** singleton() const { Address* singleton() const {
DCHECK_EQ(kSingletonTag, data_ & kTagMask); DCHECK_EQ(kSingletonTag, data_ & kTagMask);
return bit_cast<T**>(data_ - kSingletonTag); return reinterpret_cast<Address*>(data_ - kSingletonTag);
} }
enum Tag : intptr_t { enum Tag : Address {
kSingletonTag = 0, kSingletonTag = 0,
kEmptyTag = 1, kEmptyTag = 1,
kListTag = 2, kListTag = 2,
...@@ -177,7 +178,7 @@ class ZoneHandleSet final { ...@@ -177,7 +178,7 @@ class ZoneHandleSet final {
STATIC_ASSERT(kTagMask < kPointerAlignment); STATIC_ASSERT(kTagMask < kPointerAlignment);
intptr_t data_; Address data_;
}; };
template <typename T> template <typename T>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment