Commit 98dc857e authored by rossberg@chromium.org's avatar rossberg@chromium.org

Use unsigned type bitsets to limit undefined behaviour

R=bmeurer@chromium.org, svenpanne@chromium.org
BUG=

Review URL: https://codereview.chromium.org/555153003

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23916 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a5b4beff
...@@ -70,7 +70,7 @@ T* ZoneTypeConfig::cast(Type* type) { ...@@ -70,7 +70,7 @@ T* ZoneTypeConfig::cast(Type* type) {
// static // static
bool ZoneTypeConfig::is_bitset(Type* type) { bool ZoneTypeConfig::is_bitset(Type* type) {
return reinterpret_cast<intptr_t>(type) & 1; return reinterpret_cast<uintptr_t>(type) & 1;
} }
...@@ -87,9 +87,9 @@ bool ZoneTypeConfig::is_class(Type* type) { ...@@ -87,9 +87,9 @@ bool ZoneTypeConfig::is_class(Type* type) {
// static // static
int ZoneTypeConfig::as_bitset(Type* type) { ZoneTypeConfig::Type::bitset ZoneTypeConfig::as_bitset(Type* type) {
DCHECK(is_bitset(type)); DCHECK(is_bitset(type));
return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1); return reinterpret_cast<Type::bitset>(type) ^ 1u;
} }
...@@ -108,13 +108,14 @@ i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { ...@@ -108,13 +108,14 @@ i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) {
// static // static
ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) { ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(Type::bitset bitset) {
return reinterpret_cast<Type*>((bitset << 1) | 1); return reinterpret_cast<Type*>(bitset | 1u);
} }
// static // static
ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) { ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(
Type::bitset bitset, Zone* Zone) {
return from_bitset(bitset); return from_bitset(bitset);
} }
...@@ -229,8 +230,9 @@ bool HeapTypeConfig::is_struct(Type* type, int tag) { ...@@ -229,8 +230,9 @@ bool HeapTypeConfig::is_struct(Type* type, int tag) {
// static // static
int HeapTypeConfig::as_bitset(Type* type) { HeapTypeConfig::Type::bitset HeapTypeConfig::as_bitset(Type* type) {
return i::Smi::cast(type)->value(); // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way.
return reinterpret_cast<Type::bitset>(type);
} }
...@@ -247,14 +249,15 @@ i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) { ...@@ -247,14 +249,15 @@ i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) {
// static // static
HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) { HeapTypeConfig::Type* HeapTypeConfig::from_bitset(Type::bitset bitset) {
return Type::cast(i::Smi::FromInt(bitset)); // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way.
return reinterpret_cast<Type*>(bitset);
} }
// static // static
i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset( i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset(
int bitset, Isolate* isolate) { Type::bitset bitset, Isolate* isolate) {
return i::handle(from_bitset(bitset), isolate); return i::handle(from_bitset(bitset), isolate);
} }
......
This diff is collapsed.
This diff is collapsed.
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