[llvm-commits] [llvm] r160456 - /llvm/trunk/include/llvm/ADT/PointerIntPair.h

Jordan Rose jordan_rose at apple.com
Wed Jul 18 14:58:49 PDT 2012


Author: jrose
Date: Wed Jul 18 16:58:49 2012
New Revision: 160456

URL: http://llvm.org/viewvc/llvm-project?rev=160456&view=rev
Log:
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 *.

Modified:
    llvm/trunk/include/llvm/ADT/PointerIntPair.h

Modified: llvm/trunk/include/llvm/ADT/PointerIntPair.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/PointerIntPair.h?rev=160456&r1=160455&r2=160456&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/PointerIntPair.h (original)
+++ llvm/trunk/include/llvm/ADT/PointerIntPair.h Wed Jul 18 16:58:49 2012
@@ -108,7 +108,14 @@
   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 @@
   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
   };





More information about the llvm-commits mailing list