Patch llvm::PointerIntPair to work with a C++11 enum class as the IntType

Joe Groff arcata at gmail.com
Fri Apr 5 08:50:46 PDT 2013


Hi everyone. There's a little bug in PointerIntPair::setInt and
::setPointerAndInt where it assumes that the IntType of the container is
implicitly convertible to intptr_t, preventing PointerIntPair from being
used with an enum class as the IntType member of the pair. Here's a small
patch to fix it. Let me know if you see any problems with this change.
Thanks!

-Joe

===================================================================
--- include/llvm/ADT/PointerIntPair.h (revision 178549)
+++ include/llvm/ADT/PointerIntPair.h (working copy)
@@ -85,7 +85,7 @@
   }

   void setInt(IntType Int) {
-    intptr_t IntVal = Int;
+    intptr_t IntVal = static_cast<intptr_t>(Int);
     assert(IntVal < (1 << IntBits) && "Integer too large for field");

     // Preserve all bits other than the ones we are updating.
@@ -106,7 +106,7 @@
       = reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(Ptr));
     assert((PtrVal & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&
            "Pointer is not sufficiently aligned");
-    intptr_t IntVal = Int;
+    intptr_t IntVal = static_cast<intptr_t>(Int);
     assert(IntVal < (1 << IntBits) && "Integer too large for field");

     Value = PtrVal | (IntVal << IntShift);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130405/4f8217a7/attachment.html>


More information about the llvm-commits mailing list