Fix a bug in IntToPtr. Truncating to 64-bits only works if the integer
is larger. Adjust so that it truncates to pointer width, only if necessary.
llvm-svn: 34954
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
index 76104b9..4a0c589 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -1058,7 +1058,11 @@
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;
}