[llvm-commits] [llvm] r72025 - /llvm/trunk/lib/VMCore/Instructions.cpp

Dan Gohman gohman at apple.com
Mon May 18 11:18:57 PDT 2009


Author: djg
Date: Mon May 18 13:18:57 2009
New Revision: 72025

URL: http://llvm.org/viewvc/llvm-project?rev=72025&view=rev
Log:
Add assertions to CastInst::getCastOpcode to catch attempted conversions
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.

Modified:
    llvm/trunk/lib/VMCore/Instructions.cpp

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=72025&r1=72024&r2=72025&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Mon May 18 13:18:57 2009
@@ -2220,6 +2220,8 @@
     } 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 @@
     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");





More information about the llvm-commits mailing list