diff options
author | Chris Lattner <sabre@nondot.org> | 2008-07-23 06:31:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-07-23 06:31:27 +0000 |
commit | d258325c2bd49c2058088f47afa48df322e9145a (patch) | |
tree | 3107bdc5f2566a82e6683295f5babe0063ca6b9a | |
parent | 8a8fb908dcf4ec1fd85e4a91333bc90d40cf4918 (diff) | |
download | bcm5719-llvm-d258325c2bd49c2058088f47afa48df322e9145a.tar.gz bcm5719-llvm-d258325c2bd49c2058088f47afa48df322e9145a.zip |
Fix a codegen crash on:
int foo(void) {
float x[2];
return x;
}
rdar://6093986
llvm-svn: 53946
-rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 16 | ||||
-rw-r--r-- | clang/test/CodeGen/pointer-to-int.c | 9 |
2 files changed, 18 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index f3ac6a61f46..5a75e536692 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -533,12 +533,16 @@ Value *ScalarExprEmitter::VisitImplicitCastExpr(const ImplicitCastExpr *E) { V = Builder.CreateStructGEP(V, 0, "arraydecay"); // The resultant pointer type can be implicitly casted to other pointer - // types as well, for example void*. - const llvm::Type *DestPTy = ConvertType(E->getType()); - assert(isa<llvm::PointerType>(DestPTy) && - "Only expect implicit cast to pointer"); - if (V->getType() != DestPTy) - V = Builder.CreateBitCast(V, DestPTy, "ptrconv"); + // types as well (e.g. void*) and can be implicitly converted to integer. + const llvm::Type *DestTy = ConvertType(E->getType()); + if (V->getType() != DestTy) { + if (isa<llvm::PointerType>(DestTy)) + V = Builder.CreateBitCast(V, DestTy, "ptrconv"); + else { + assert(isa<llvm::IntegerType>(DestTy) && "Unknown array decay"); + V = Builder.CreatePtrToInt(V, DestTy, "ptrconv"); + } + } return V; } else if (E->getType()->isReferenceType()) { diff --git a/clang/test/CodeGen/pointer-to-int.c b/clang/test/CodeGen/pointer-to-int.c index 7599e0d4abe..a3eaf91bc16 100644 --- a/clang/test/CodeGen/pointer-to-int.c +++ b/clang/test/CodeGen/pointer-to-int.c @@ -1,6 +1,13 @@ -// RUN: clang -emit-llvm %s +// RUN: clang -emit-llvm %s -o - int test(void* i) { return (int)i; } + +// rdar://6093986 +int test2(void) { + float x[2]; + return x; +} + |