Fix a codegen crash on test/CodeGen/cast.c, reported by Keith.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44908 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp
index 9846d81..5ef7496 100644
--- a/CodeGen/CGExprScalar.cpp
+++ b/CodeGen/CGExprScalar.cpp
@@ -512,7 +512,17 @@
llvm::Constant *Idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
llvm::Value *Ops[] = {Idx0, Idx0};
- return Builder.CreateGEP(V, Ops, Ops+2, "arraydecay");
+ V = Builder.CreateGEP(V, Ops, Ops+2, "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");
+ return V;
+
} else if (E->getType()->isReferenceType()) {
assert(cast<ReferenceType>(E->getType().getCanonicalType())->
getReferenceeType() ==