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

Unified Diff: src/types-inl.h

Issue 567333002: 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..9e16fdf1872a3ebbcd9dd2511c7cf42013a771fc 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 reinterpret_cast<Type::bitset>(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*>(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 reinterpret_cast<Type::bitset>(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*>(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