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

Unified Diff: src/types.h

Issue 555153003: 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 | « no previous file | src/types.cc » ('j') | src/types-inl.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/types.h
diff --git a/src/types.h b/src/types.h
index cca8b3167b4bb9b86773d7fcf40959490a9164f0..b593b6461850538cc248cae0885aaab43d2ebde5 100644
--- a/src/types.h
+++ b/src/types.h
@@ -139,8 +139,8 @@ namespace internal {
// Values for bitset types
#define MASK_BITSET_TYPE_LIST(V) \
- V(Representation, static_cast<int>(0xffc00000)) \
- V(Semantic, static_cast<int>(0x003fffff))
+ V(Representation, 0xffc00000u) \
+ V(Semantic, 0x003fffffu)
#define REPRESENTATION(k) ((k) & BitsetType::kRepresentation)
#define SEMANTIC(k) ((k) & BitsetType::kSemantic)
@@ -155,8 +155,7 @@ namespace internal {
V(UntaggedFloat64, 1 << 27 | kSemantic) \
V(UntaggedPtr, 1 << 28 | kSemantic) \
V(TaggedInt, 1 << 29 | kSemantic) \
- /* MSB has to be sign-extended */ \
- V(TaggedPtr, static_cast<int>(~0u << 30) | kSemantic) \
+ V(TaggedPtr, 3u << 30 | kSemantic) /* Sign-extend MSB */ \
\
V(UntaggedInt, kUntaggedInt1 | kUntaggedInt8 | \
kUntaggedInt16 | kUntaggedInt32) \
@@ -206,7 +205,7 @@ namespace internal {
V(Receiver, kObject | kProxy) \
V(NonNumber, kBoolean | kName | kNull | kReceiver | \
kUndefined | kInternal) \
- V(Any, -1)
+ V(Any, 0xffffffffu)
#define BITSET_TYPE_LIST(V) \
MASK_BITSET_TYPE_LIST(V) \
@@ -228,11 +227,11 @@ namespace internal {
// static bool is_bitset(Type*);
// static bool is_class(Type*);
// static bool is_struct(Type*, int tag);
-// static int as_bitset(Type*);
+// static bitset as_bitset(Type*);
// static i::Handle<i::Map> as_class(Type*);
// static Handle<Struct>::type as_struct(Type*);
-// static Type* from_bitset(int bitset);
-// static Handle<Type>::type from_bitset(int bitset, Region*);
+// static Type* from_bitset(bitset);
+// static Handle<Type>::type from_bitset(bitset, Region*);
// static Handle<Type>::type from_class(i::Handle<Map>, Region*);
// static Handle<Type>::type from_struct(Handle<Struct>::type, int tag);
// static Handle<Struct>::type struct_create(int tag, int length, Region*);
@@ -251,9 +250,10 @@ class TypeImpl : public Config::Base {
public:
// Auxiliary types.
- class BitsetType; // Internal
- class StructuralType; // Internal
- class UnionType; // Internal
+ typedef uintptr_t bitset; // Internal
+ class BitsetType; // Internal
+ class StructuralType; // Internal
+ class UnionType; // Internal
class ClassType;
class ConstantType;
@@ -456,7 +456,7 @@ class TypeImpl : public Config::Base {
bool IsBitset() { return Config::is_bitset(this); }
bool IsUnion() { return Config::is_struct(this, StructuralType::kUnionTag); }
- int AsBitset() {
+ bitset AsBitset() {
DCHECK(this->IsBitset());
return static_cast<BitsetType*>(this)->Bitset();
}
@@ -464,15 +464,15 @@ class TypeImpl : public Config::Base {
// Auxiliary functions.
- int BitsetGlb() { return BitsetType::Glb(this); }
- int BitsetLub() { return BitsetType::Lub(this); }
- int InherentBitsetLub() { return BitsetType::InherentLub(this); }
+ bitset BitsetGlb() { return BitsetType::Glb(this); }
+ bitset BitsetLub() { return BitsetType::Lub(this); }
+ bitset InherentBitsetLub() { return BitsetType::InherentLub(this); }
bool SlowIs(TypeImpl* that);
- TypeHandle Rebound(int bitset, Region* region);
- int BoundBy(TypeImpl* that);
- int IndexInUnion(int bound, UnionHandle unioned, int current_size);
+ TypeHandle Rebound(bitset bound, Region* region);
+ bitset BoundBy(TypeImpl* that);
+ int IndexInUnion(bitset bound, UnionHandle unioned, int current_size);
static int ExtendUnion(
UnionHandle unioned, int current_size, TypeHandle t,
TypeHandle other, bool is_intersect, Region* region);
@@ -494,35 +494,35 @@ class TypeImpl<Config>::BitsetType : public TypeImpl<Config> {
kUnusedEOL = 0
};
- int Bitset() { return Config::as_bitset(this); }
+ bitset Bitset() { return Config::as_bitset(this); }
- static TypeImpl* New(int bitset) {
- return static_cast<BitsetType*>(Config::from_bitset(bitset));
+ static TypeImpl* New(bitset bits) {
+ return static_cast<BitsetType*>(Config::from_bitset(bits));
}
- static TypeHandle New(int bitset, Region* region) {
- return Config::from_bitset(bitset, region);
+ static TypeHandle New(bitset bits, Region* region) {
+ return Config::from_bitset(bits, region);
}
- static bool IsInhabited(int bitset) {
- return (bitset & kRepresentation) && (bitset & kSemantic);
+ static bool IsInhabited(bitset bits) {
+ return (bits & kRepresentation) && (bits & kSemantic);
}
- static bool Is(int bitset1, int bitset2) {
- return (bitset1 | bitset2) == bitset2;
+ static bool Is(bitset bits1, bitset bits2) {
+ return (bits1 | bits2) == bits2;
}
- static int Glb(TypeImpl* type); // greatest lower bound that's a bitset
- static int Lub(TypeImpl* type); // least upper bound that's a bitset
- static int Lub(i::Object* value);
- static int Lub(double value);
- static int Lub(int32_t value);
- static int Lub(uint32_t value);
- static int Lub(i::Map* map);
- static int Lub(double min, double max);
- static int InherentLub(TypeImpl* type);
+ static bitset Glb(TypeImpl* type); // greatest lower bound that's a bitset
+ static bitset Lub(TypeImpl* type); // least upper bound that's a bitset
+ static bitset Lub(i::Object* value);
+ static bitset Lub(double value);
+ static bitset Lub(int32_t value);
+ static bitset Lub(uint32_t value);
+ static bitset Lub(i::Map* map);
+ static bitset Lub(double min, double max);
+ static bitset InherentLub(TypeImpl* type);
- static const char* Name(int bitset);
- static void Print(OStream& os, int bitset); // NOLINT
+ static const char* Name(bitset);
+ static void Print(OStream& os, bitset); // NOLINT
using TypeImpl::PrintTo;
};
@@ -865,12 +865,12 @@ struct ZoneTypeConfig {
static inline bool is_class(Type* type);
static inline bool is_struct(Type* type, int tag);
- static inline int as_bitset(Type* type);
+ static inline Type::bitset as_bitset(Type* type);
static inline i::Handle<i::Map> as_class(Type* type);
static inline Struct* as_struct(Type* type);
- static inline Type* from_bitset(int bitset);
- static inline Type* from_bitset(int bitset, Zone* zone);
+ static inline Type* from_bitset(Type::bitset);
+ static inline Type* from_bitset(Type::bitset, Zone* zone);
static inline Type* from_class(i::Handle<i::Map> map, Zone* zone);
static inline Type* from_struct(Struct* structured);
@@ -912,12 +912,12 @@ struct HeapTypeConfig {
static inline bool is_class(Type* type);
static inline bool is_struct(Type* type, int tag);
- static inline int as_bitset(Type* type);
+ static inline Type::bitset as_bitset(Type* type);
static inline i::Handle<i::Map> as_class(Type* type);
static inline i::Handle<Struct> as_struct(Type* type);
- static inline Type* from_bitset(int bitset);
- static inline i::Handle<Type> from_bitset(int bitset, Isolate* isolate);
+ static inline Type* from_bitset(Type::bitset);
+ static inline i::Handle<Type> from_bitset(Type::bitset, Isolate* isolate);
static inline i::Handle<Type> from_class(
i::Handle<i::Map> map, Isolate* isolate);
static inline i::Handle<Type> from_struct(i::Handle<Struct> structure);
« no previous file with comments | « no previous file | src/types.cc » ('j') | src/types-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698