X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FPointerUnion.h;h=1b36aeea793478708ae7b64fd4a52686146bbd1a;hb=670031666cf4dea0d122a0df2ec1d18822c225e4;hp=da67c8e8c27b8aab06592cb40f22fef07931347c;hpb=e8bc475668ddd2f31f44dd00b042d15b255e1b9e;p=oota-llvm.git diff --git a/include/llvm/ADT/PointerUnion.h b/include/llvm/ADT/PointerUnion.h index da67c8e8c27..1b36aeea793 100644 --- a/include/llvm/ADT/PointerUnion.h +++ b/include/llvm/ADT/PointerUnion.h @@ -54,7 +54,7 @@ namespace llvm { /// printf("%d %d", P.is(), P.is()); // prints "1 0" /// X = P.get(); // ok. /// Y = P.get(); // runtime assertion failure. - /// Z = P.get(); // does not compile. + /// Z = P.get(); // runtime assertion failure (regardless of tag) /// P = (float*)0; /// Y = P.get(); // ok. /// X = P.get(); // runtime assertion failure. @@ -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,