mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-17 03:24:34 +00:00
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
This commit is contained in:
@@ -29,7 +29,7 @@ struct DenseMapInfo;
|
|||||||
/// on the number of bits available according to PointerLikeTypeTraits for the
|
/// on the number of bits available according to PointerLikeTypeTraits for the
|
||||||
/// type.
|
/// 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
|
/// 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
|
/// the bool into bit #2, not bit #0, which allows the low two bits to be used
|
||||||
/// for something else. For example, this allows:
|
/// for something else. For example, this allows:
|
||||||
@@ -57,13 +57,13 @@ class PointerIntPair {
|
|||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
PointerIntPair() : Value(0) {}
|
PointerIntPair() : Value(0) {}
|
||||||
PointerIntPair(PointerTy Ptr, IntType Int) {
|
PointerIntPair(PointerTy PtrVal, IntType IntVal) {
|
||||||
assert(IntBits <= PtrTraits::NumLowBitsAvailable &&
|
assert(IntBits <= PtrTraits::NumLowBitsAvailable &&
|
||||||
"PointerIntPair formed with integer size too large for pointer");
|
"PointerIntPair formed with integer size too large for pointer");
|
||||||
setPointerAndInt(Ptr, Int);
|
setPointerAndInt(PtrVal, IntVal);
|
||||||
}
|
}
|
||||||
explicit PointerIntPair(PointerTy Ptr) {
|
explicit PointerIntPair(PointerTy PtrVal) {
|
||||||
initWithPointer(Ptr);
|
initWithPointer(PtrVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
PointerTy getPointer() const {
|
PointerTy getPointer() const {
|
||||||
@@ -75,41 +75,41 @@ public:
|
|||||||
return (IntType)((Value >> IntShift) & IntMask);
|
return (IntType)((Value >> IntShift) & IntMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPointer(PointerTy Ptr) {
|
void setPointer(PointerTy PtrVal) {
|
||||||
intptr_t PtrVal
|
intptr_t PtrWord
|
||||||
= reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(Ptr));
|
= reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(PtrVal));
|
||||||
assert((PtrVal & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
|
assert((PtrWord & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
|
||||||
"Pointer is not sufficiently aligned");
|
"Pointer is not sufficiently aligned");
|
||||||
// Preserve all low bits, just update the pointer.
|
// Preserve all low bits, just update the pointer.
|
||||||
Value = PtrVal | (Value & ~PointerBitMask);
|
Value = PtrWord | (Value & ~PointerBitMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInt(IntType Int) {
|
void setInt(IntType IntVal) {
|
||||||
intptr_t IntVal = Int;
|
intptr_t IntWord = static_cast<intptr_t>(IntVal);
|
||||||
assert(IntVal < (1 << IntBits) && "Integer too large for field");
|
assert(IntWord < (1 << IntBits) && "Integer too large for field");
|
||||||
|
|
||||||
// Preserve all bits other than the ones we are updating.
|
// Preserve all bits other than the ones we are updating.
|
||||||
Value &= ~ShiftedIntMask; // Remove integer field.
|
Value &= ~ShiftedIntMask; // Remove integer field.
|
||||||
Value |= IntVal << IntShift; // Set new integer.
|
Value |= IntWord << IntShift; // Set new integer.
|
||||||
}
|
}
|
||||||
|
|
||||||
void initWithPointer(PointerTy Ptr) {
|
void initWithPointer(PointerTy PtrVal) {
|
||||||
intptr_t PtrVal
|
intptr_t PtrWord
|
||||||
= reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(Ptr));
|
= reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(PtrVal));
|
||||||
assert((PtrVal & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
|
assert((PtrWord & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
|
||||||
"Pointer is not sufficiently aligned");
|
"Pointer is not sufficiently aligned");
|
||||||
Value = PtrVal;
|
Value = PtrWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPointerAndInt(PointerTy Ptr, IntType Int) {
|
void setPointerAndInt(PointerTy PtrVal, IntType IntVal) {
|
||||||
intptr_t PtrVal
|
intptr_t PtrWord
|
||||||
= reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(Ptr));
|
= reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(PtrVal));
|
||||||
assert((PtrVal & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
|
assert((PtrWord & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
|
||||||
"Pointer is not sufficiently aligned");
|
"Pointer is not sufficiently aligned");
|
||||||
intptr_t IntVal = Int;
|
intptr_t IntWord = static_cast<intptr_t>(IntVal);
|
||||||
assert(IntVal < (1 << IntBits) && "Integer too large for field");
|
assert(IntWord < (1 << IntBits) && "Integer too large for field");
|
||||||
|
|
||||||
Value = PtrVal | (IntVal << IntShift);
|
Value = PtrWord | (IntWord << IntShift);
|
||||||
}
|
}
|
||||||
|
|
||||||
PointerTy const *getAddrOfPointer() const {
|
PointerTy const *getAddrOfPointer() const {
|
||||||
|
Reference in New Issue
Block a user