]> granicus.if.org Git - clang/commitdiff
Fix a codegen crash on test/CodeGen/cast.c, reported by Keith.
authorChris Lattner <sabre@nondot.org>
Wed, 12 Dec 2007 04:13:20 +0000 (04:13 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 12 Dec 2007 04:13:20 +0000 (04:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44908 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGExprScalar.cpp
clang.xcodeproj/project.pbxproj
test/CodeGen/cast.c [new file with mode: 0644]

index 9846d81d1e67945d0e812cee4b23ae88f7155022..5ef7496a6606f31dac3ee1804d549a34f4221a84 100644 (file)
@@ -512,7 +512,17 @@ Value *ScalarExprEmitter::VisitImplicitCastExpr(const ImplicitCastExpr *E) {
     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() == 
index 789b272fa4e532723e26ed0a8a79e63e292cd980..ed2ec876d39cd42735bd374a8a8af302ba9c30a4 100644 (file)
                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 (file)
index 0000000..dfd9bb8
--- /dev/null
@@ -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); }
+