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 *.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160456 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jordan Rose 2012-07-18 21:58:49 +00:00
parent 62a89f5808
commit 6ef4996b09

View File

@ -108,7 +108,14 @@ public:
static PointerIntPair getFromOpaqueValue(void *V) {
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
};