[cfe-commits] r66009 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/PR3709-int-to-pointer-sign.c
Eli Friedman
eli.friedman at gmail.com
Tue Mar 3 20:02:35 PST 2009
Author: efriedma
Date: Tue Mar 3 22:02:35 2009
New Revision: 66009
URL: http://llvm.org/viewvc/llvm-project?rev=66009&view=rev
Log:
Attempt to fix PR3709: when converting from an integer to a pointer,
first extend the integer to the correct width.
Added:
cfe/trunk/test/CodeGen/PR3709-int-to-pointer-sign.c
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=66009&r1=66008&r2=66009&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Mar 3 22:02:35 2009
@@ -403,7 +403,14 @@
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())) {
Added: cfe/trunk/test/CodeGen/PR3709-int-to-pointer-sign.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/PR3709-int-to-pointer-sign.c?rev=66009&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/PR3709-int-to-pointer-sign.c (added)
+++ cfe/trunk/test/CodeGen/PR3709-int-to-pointer-sign.c Tue Mar 3 22:02:35 2009
@@ -0,0 +1,5 @@
+// RUN: clang -emit-llvm %s -o - -O1 -triple=x86_64-gnu-linux | grep "i64 -1"
+
+// PR3709
+long long a() { return (long long)(int*)-1;}
+
More information about the cfe-commits
mailing list