X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FPointerUnion.h;h=1b36aeea793478708ae7b64fd4a52686146bbd1a;hb=670031666cf4dea0d122a0df2ec1d18822c225e4;hp=6f5d01af86af35784626a86f6aab9d62c05ddb18;hpb=f54229192c22559389b0ef47e731fd628db963c5;p=oota-llvm.git diff --git a/include/llvm/ADT/PointerUnion.h b/include/llvm/ADT/PointerUnion.h index 6f5d01af86a..1b36aeea793 100644 --- a/include/llvm/ADT/PointerUnion.h +++ b/include/llvm/ADT/PointerUnion.h @@ -69,11 +69,13 @@ namespace llvm { PointerUnion() {} PointerUnion(PT1 V) { - Val.setPointer(PointerLikeTypeTraits::getAsVoidPointer(V)); + Val.setPointer( + const_cast(PointerLikeTypeTraits::getAsVoidPointer(V))); Val.setInt(0); } PointerUnion(PT2 V) { - Val.setPointer(PointerLikeTypeTraits::getAsVoidPointer(V)); + Val.setPointer( + const_cast(PointerLikeTypeTraits::getAsVoidPointer(V))); Val.setInt(1); } @@ -87,7 +89,7 @@ namespace llvm { int is() const { int TyNo = ::llvm::getPointerUnionTypeNum((T*)0); assert(TyNo != -1 && "Type query could never succeed on PointerUnion!"); - return Val.getInt() == TyNo; + return static_cast(Val.getInt()) == TyNo; } /// get() - Return the value of the specified pointer type. If the @@ -109,12 +111,14 @@ namespace llvm { /// Assignment operators - Allow assigning into this union from either /// pointer type, setting the discriminator to remember what it came from. const PointerUnion &operator=(const PT1 &RHS) { - Val.setPointer(PointerLikeTypeTraits::getAsVoidPointer(RHS)); + Val.setPointer( + const_cast(PointerLikeTypeTraits::getAsVoidPointer(RHS))); Val.setInt(0); return *this; } const PointerUnion &operator=(const PT2 &RHS) { - Val.setPointer(PointerLikeTypeTraits::getAsVoidPointer(RHS)); + Val.setPointer( + const_cast(PointerLikeTypeTraits::getAsVoidPointer(RHS))); Val.setInt(1); return *this; } @@ -182,10 +186,8 @@ namespace llvm { int is() const { // Is it PT1/PT2? if (::llvm::getPointerUnionTypeNum((T*)0) != -1) - return Val.get().is(); - // Must be PT3 or statically invalid. - assert(Val.is()); - return true; + return Val.is() && Val.get().is(); + return Val.is(); } /// get() - Return the value of the specified pointer type. If the @@ -193,9 +195,11 @@ namespace llvm { template T get() const { assert(is() && "Invalid accessor called"); - if (Val.is()) - return Val.get(); - return Val.get().get(); + // Is it PT1/PT2? + if (::llvm::getPointerUnionTypeNum((T*)0) != -1) + return Val.get().get(); + + return Val.get(); } /// dyn_cast() - If the current value is of the specified pointer type,