Fix a bug in IntToPtr. Truncating to 64-bits only works if the integer
authorReid Spencer <rspencer@reidspencer.com>
Tue, 6 Mar 2007 03:41:50 +0000 (03:41 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Tue, 6 Mar 2007 03:41:50 +0000 (03:41 +0000)
is larger. Adjust so that it truncates to pointer width, only if necessary.

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

lib/ExecutionEngine/Interpreter/Execution.cpp

index 76104b9440c83a15a8e3cf511262a6fa9aa80f1b..4a0c58906a5f389a9a257778647870084b1a2f8b 100644 (file)
@@ -1058,7 +1058,11 @@ GenericValue Interpreter::executeIntToPtrInst(Value *SrcVal, const Type *DstTy,
   GenericValue Dest, Src = getOperandValue(SrcVal, SF);
   assert(isa<PointerType>(DstTy) && "Invalid PtrToInt instruction");
 
-  Dest.PointerVal = (PointerTy) Src.IntVal.trunc(64).getZExtValue();
+  uint32_t PtrSize = TD.getPointerSize();
+  if (PtrSize != Src.IntVal.getBitWidth())
+    Src.IntVal = Src.IntVal.trunc(PtrSize);
+
+  Dest.PointerVal = (PointerTy) Src.IntVal.getZExtValue();
   return Dest;
 }