Patch llvm::PointerIntPair to work with a C++11 enum class as the IntType
Evan Cheng
evan.cheng at apple.com
Fri Apr 5 09:03:46 PDT 2013
Hi Joe,
Using "Int" as variable name seems like a bad idea to me. Could you fix it while you are fixing the class?
Thanks,
Evan
Sent from my iPad
On Apr 5, 2013, at 8:50 AM, Joe Groff <arcata at gmail.com> wrote:
> 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);
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list