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() == 
diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj
index 789b272..ed2ec87 100644
--- a/clang.xcodeproj/project.pbxproj
+++ b/clang.xcodeproj/project.pbxproj
@@ -772,6 +772,7 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
+			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";
diff --git a/test/CodeGen/cast.c b/test/CodeGen/cast.c
new file mode 100644
index 0000000..dfd9bb8
--- /dev/null
+++ b/test/CodeGen/cast.c
@@ -0,0 +1,6 @@
+// RUN: clang %s -emit-llvm
+
+extern void go(const void *p);
+float v[2] = { 0.0, 1.0 };
+void foo(void) { go(v); }
+