drive by bug fix: DenseMapInfo::isEqual should be determined according to
[oota-llvm.git] / include / llvm / ADT / PointerIntPair.h
index 0aa478b1ff61cd7117d06ce780d319f11e7959e7..85dbba2b4a4ae9b361280cb9616a3dd52bbd473f 100644 (file)
@@ -65,7 +65,8 @@ public:
   }
 
   PointerTy getPointer() const {
-    return reinterpret_cast<PointerTy>(Value & PointerBitMask);
+    return PtrTraits::getFromVoidPointer(
+                         reinterpret_cast<void*>(Value & PointerBitMask));
   }
 
   IntType getInt() const {
@@ -73,7 +74,8 @@ public:
   }
 
   void setPointer(PointerTy Ptr) {
-    intptr_t PtrVal = reinterpret_cast<intptr_t>(Ptr);
+    intptr_t PtrVal
+      = reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(Ptr));
     assert((PtrVal & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
            "Pointer is not sufficiently aligned");
     // Preserve all low bits, just update the pointer.
@@ -89,6 +91,13 @@ public:
     Value |= IntVal << IntShift;  // Set new integer.
   }
 
+  PointerTy const *getAddrOfPointer() const {
+    assert(Value == reinterpret_cast<intptr_t>(getPointer()) &&
+           "Can only return the address if IntBits is cleared and "
+           "PtrTraits doesn't change the pointer");
+    return reinterpret_cast<PointerTy const *>(&Value);
+  }
+
   void *getOpaqueValue() const { return reinterpret_cast<void*>(Value); }
   void setFromOpaqueValue(void *Val) { Value = reinterpret_cast<intptr_t>(Val);}
 
@@ -104,6 +113,12 @@ public:
   bool operator>=(const PointerIntPair &RHS) const {return Value >= RHS.Value;}
 };
 
+template <typename T> struct isPodLike;
+template<typename PointerTy, unsigned IntBits, typename IntType>
+struct isPodLike<PointerIntPair<PointerTy, IntBits, IntType> > {
+   static const bool value = true;
+};
+  
 // Provide specialization of DenseMapInfo for PointerIntPair.
 template<typename PointerTy, unsigned IntBits, typename IntType>
 struct DenseMapInfo<PointerIntPair<PointerTy, IntBits, IntType> > {
@@ -123,7 +138,6 @@ struct DenseMapInfo<PointerIntPair<PointerTy, IntBits, IntType> > {
     return unsigned(IV) ^ unsigned(IV >> 9);
   }
   static bool isEqual(const Ty &LHS, const Ty &RHS) { return LHS == RHS; }
-  static bool isPod() { return true; }
 };
 
 // Teach SmallPtrSet that PointerIntPair is "basically a pointer".
@@ -141,8 +155,7 @@ public:
     return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P);
   }
   enum {
-    NumLowBitsAvailable = 
-           PointerLikeTypeTraits<PointerTy>::NumLowBitsAvailable - IntBits
+    NumLowBitsAvailable = PtrTraits::NumLowBitsAvailable - IntBits
   };
 };