diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-03-04 04:02:35 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-03-04 04:02:35 +0000 |
commit | 25615424741bcce31fe52c896f76268f0307f00d (patch) | |
tree | 158f229570dcc760690eec8b11e055e0d4e565b5 /lib/CodeGen/CGExprScalar.cpp | |
parent | dab514fc30242c7afd6c03956e46136c400fb0d3 (diff) |
Attempt to fix PR3709: when converting from an integer to a pointer,
first extend the integer to the correct width.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66009 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprScalar.cpp')
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 0b8cc535bf..38cc3eec5d 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -403,7 +403,14 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, if (isa<llvm::PointerType>(Src->getType())) return Builder.CreateBitCast(Src, DstTy, "conv"); assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?"); - return Builder.CreateIntToPtr(Src, DstTy, "conv"); + // First, convert to the correct width so that we control the kind of + // extension. + const llvm::Type *MiddleTy = llvm::IntegerType::get(CGF.LLVMPointerWidth); + bool InputSigned = SrcType->isSignedIntegerType(); + llvm::Value* IntResult = + Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv"); + // Then, cast to pointer. + return Builder.CreateIntToPtr(IntResult, DstTy, "conv"); } if (isa<llvm::PointerType>(Src->getType())) { |