summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/PointerIntPair.h
diff options
context:
space:
mode:
authorJoe Groff <arcata@gmail.com>2013-04-09 00:01:51 +0000
committerJoe Groff <arcata@gmail.com>2013-04-09 00:01:51 +0000
commitb3d25a940cfd44ffbac71adc6d8f3759ad8a8cb4 (patch)
tree375fc1af06591b62b49770d4c4aee244996e131c /include/llvm/ADT/PointerIntPair.h
parent3388589fc102b873ee9b73ffdab0f532ee3ceda6 (diff)
downloadllvm-b3d25a940cfd44ffbac71adc6d8f3759ad8a8cb4.tar.gz
llvm-b3d25a940cfd44ffbac71adc6d8f3759ad8a8cb4.tar.bz2
llvm-b3d25a940cfd44ffbac71adc6d8f3759ad8a8cb4.tar.xz
Fix PointerIntPair to be enum class compatible.
Some parts of PointerIntPair assumed that the IntType of the pair was implicitly convertible to intptr_t, which is not the case for enum class values. Add a static_cast<intptr_t> to make these conversions explicit and allow PointerIntPair to be used with an enum class IntType. While we're here, rename some of the argument values so we don't have variables named "Int" floating around. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179073 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/PointerIntPair.h')
-rw-r--r--include/llvm/ADT/PointerIntPair.h52
1 files changed, 26 insertions, 26 deletions
diff --git a/include/llvm/ADT/PointerIntPair.h b/include/llvm/ADT/PointerIntPair.h
index cce2efb6ac..0299a83c44 100644
--- a/include/llvm/ADT/PointerIntPair.h
+++ b/include/llvm/ADT/PointerIntPair.h
@@ -29,7 +29,7 @@ struct DenseMapInfo;
/// on the number of bits available according to PointerLikeTypeTraits for the
/// type.
///
-/// Note that PointerIntPair always puts the Int part in the highest bits
+/// Note that PointerIntPair always puts the IntVal part in the highest bits
/// possible. For example, PointerIntPair<void*, 1, bool> will put the bit for
/// the bool into bit #2, not bit #0, which allows the low two bits to be used
/// for something else. For example, this allows:
@@ -57,13 +57,13 @@ class PointerIntPair {
};
public:
PointerIntPair() : Value(0) {}
- PointerIntPair(PointerTy Ptr, IntType Int) {
+ PointerIntPair(PointerTy PtrVal, IntType IntVal) {
assert(IntBits <= PtrTraits::NumLowBitsAvailable &&
"PointerIntPair formed with integer size too large for pointer");
- setPointerAndInt(Ptr, Int);
+ setPointerAndInt(PtrVal, IntVal);
}
- explicit PointerIntPair(PointerTy Ptr) {
- initWithPointer(Ptr);
+ explicit PointerIntPair(PointerTy PtrVal) {
+ initWithPointer(PtrVal);
}
PointerTy getPointer() const {
@@ -75,41 +75,41 @@ public:
return (IntType)((Value >> IntShift) & IntMask);
}
- void setPointer(PointerTy Ptr) {
- intptr_t PtrVal
- = reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(Ptr));
- assert((PtrVal & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
+ void setPointer(PointerTy PtrVal) {
+ intptr_t PtrWord
+ = reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(PtrVal));
+ assert((PtrWord & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
"Pointer is not sufficiently aligned");
// Preserve all low bits, just update the pointer.
- Value = PtrVal | (Value & ~PointerBitMask);
+ Value = PtrWord | (Value & ~PointerBitMask);
}
- void setInt(IntType Int) {
- intptr_t IntVal = Int;
- assert(IntVal < (1 << IntBits) && "Integer too large for field");
+ void setInt(IntType IntVal) {
+ intptr_t IntWord = static_cast<intptr_t>(IntVal);
+ assert(IntWord < (1 << IntBits) && "Integer too large for field");
// Preserve all bits other than the ones we are updating.
Value &= ~ShiftedIntMask; // Remove integer field.
- Value |= IntVal << IntShift; // Set new integer.
+ Value |= IntWord << IntShift; // Set new integer.
}
- void initWithPointer(PointerTy Ptr) {
- intptr_t PtrVal
- = reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(Ptr));
- assert((PtrVal & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
+ void initWithPointer(PointerTy PtrVal) {
+ intptr_t PtrWord
+ = reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(PtrVal));
+ assert((PtrWord & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
"Pointer is not sufficiently aligned");
- Value = PtrVal;
+ Value = PtrWord;
}
- void setPointerAndInt(PointerTy Ptr, IntType Int) {
- intptr_t PtrVal
- = reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(Ptr));
- assert((PtrVal & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
+ void setPointerAndInt(PointerTy PtrVal, IntType IntVal) {
+ intptr_t PtrWord
+ = reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(PtrVal));
+ assert((PtrWord & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
"Pointer is not sufficiently aligned");
- intptr_t IntVal = Int;
- assert(IntVal < (1 << IntBits) && "Integer too large for field");
+ intptr_t IntWord = static_cast<intptr_t>(IntVal);
+ assert(IntWord < (1 << IntBits) && "Integer too large for field");
- Value = PtrVal | (IntVal << IntShift);
+ Value = PtrWord | (IntWord << IntShift);
}
PointerTy const *getAddrOfPointer() const {