Allow PointerIntPairs to be created from const void *.

For a measure of safety, this conversion is only permitted if the
stored pointer type can also be created from a const void *.

llvm-svn: 160456
This commit is contained in:
Jordan Rose 2012-07-18 21:58:49 +00:00
parent 68777ac253
commit 82632bffbc
1 changed files with 12 additions and 1 deletions

View File

@ -109,6 +109,13 @@ public:
PointerIntPair P; P.setFromOpaqueValue(V); return P;
}
// Allow PointerIntPairs to be created from const void * if and only if the
// pointer type could be created from a const void *.
static PointerIntPair getFromOpaqueValue(const void *V) {
(void)PtrTraits::getFromVoidPointer(V);
return getFromOpaqueValue(const_cast<void *>(V));
}
bool operator==(const PointerIntPair &RHS) const {return Value == RHS.Value;}
bool operator!=(const PointerIntPair &RHS) const {return Value != RHS.Value;}
bool operator<(const PointerIntPair &RHS) const {return Value < RHS.Value;}
@ -158,6 +165,10 @@ public:
getFromVoidPointer(void *P) {
return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P);
}
static inline PointerIntPair<PointerTy, IntBits, IntType>
getFromVoidPointer(const void *P) {
return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P);
}
enum {
NumLowBitsAvailable = PtrTraits::NumLowBitsAvailable - IntBits
};