Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(703)

Unified Diff: src/types-inl.h

Issue 577563002: Re-reland "Use unsigned type bitsets to limit undefined behaviour" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/types-inl.h
diff --git a/src/types-inl.h b/src/types-inl.h
index f102ae3e137ad6c50ee4afc15c4309041b55fde7..162e658d673a960bb65dfb19d960d045027cb18a 100644
--- a/src/types-inl.h
+++ b/src/types-inl.h
@@ -70,7 +70,7 @@ T* ZoneTypeConfig::cast(Type* type) {
// static
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) {
// static
-int ZoneTypeConfig::as_bitset(Type* type) {
+ZoneTypeConfig::Type::bitset ZoneTypeConfig::as_bitset(Type* type) {
DCHECK(is_bitset(type));
- return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1);
+ return static_cast<Type::bitset>(reinterpret_cast<uintptr_t>(type) ^ 1u);
}
@@ -108,13 +108,14 @@ i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) {
// static
-ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) {
- return reinterpret_cast<Type*>((bitset << 1) | 1);
+ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(Type::bitset bitset) {
+ return reinterpret_cast<Type*>(static_cast<uintptr_t>(bitset | 1u));
}
// static
-ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) {
+ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(
+ Type::bitset bitset, Zone* Zone) {
return from_bitset(bitset);
}
@@ -229,8 +230,9 @@ bool HeapTypeConfig::is_struct(Type* type, int tag) {
// static
-int HeapTypeConfig::as_bitset(Type* type) {
- return i::Smi::cast(type)->value();
+HeapTypeConfig::Type::bitset HeapTypeConfig::as_bitset(Type* type) {
+ // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way.
+ return static_cast<Type::bitset>(reinterpret_cast<uintptr_t>(type));
}
@@ -247,14 +249,15 @@ i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) {
// static
-HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) {
- return Type::cast(i::Smi::FromInt(bitset));
+HeapTypeConfig::Type* HeapTypeConfig::from_bitset(Type::bitset bitset) {
+ // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way.
+ return reinterpret_cast<Type*>(static_cast<uintptr_t>(bitset));
}
// static
i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset(
- int bitset, Isolate* isolate) {
+ Type::bitset bitset, Isolate* isolate) {
return i::handle(from_bitset(bitset), isolate);
}
« no previous file with comments | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698