Add assertions to CastInst::getCastOpcode to catch attempted conversions
authorDan Gohman <gohman@apple.com>
Mon, 18 May 2009 18:18:57 +0000 (18:18 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 18 May 2009 18:18:57 +0000 (18:18 +0000)
between integers and pointers when the source type is marked signed,
since inttoptr and ptrtoint always use zero-extension when the destination
is larger than the source.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72025 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Instructions.cpp

index fe30271f84450d6646ac787d7d54329990836b01..0dd69a18bc938e4fbb12418c9559479892e34367 100644 (file)
@@ -2220,6 +2220,8 @@ CastInst::getCastOpcode(
     } else {
       assert(isa<PointerType>(SrcTy) &&
              "Casting from a value that is not first-class type");
+      assert(!SrcIsSigned &&
+             "Pointer types cannot be considered signed for conversions!");
       return PtrToInt;                              // ptr -> int
     }
   } else if (DestTy->isFloatingPoint()) {           // Casting to floating pt
@@ -2259,6 +2261,7 @@ CastInst::getCastOpcode(
     if (isa<PointerType>(SrcTy)) {
       return BitCast;                               // ptr -> ptr
     } else if (SrcTy->isInteger()) {
+      assert(!SrcIsSigned && "Cannot cast signed integer to pointer!");
       return IntToPtr;                              // int -> ptr
     } else {
       assert(!"Casting pointer to other than pointer or int");