[cfe-commits] r44908 - in /cfe/trunk: CodeGen/CGExprScalar.cpp clang.xcodeproj/project.pbxproj test/CodeGen/cast.c

Chris Lattner sabre at nondot.org
Tue Dec 11 20:13:21 PST 2007


Author: lattner
Date: Tue Dec 11 22:13:20 2007
New Revision: 44908

URL: http://llvm.org/viewvc/llvm-project?rev=44908&view=rev
Log:
Fix a codegen crash on test/CodeGen/cast.c, reported by Keith.

Added:
    cfe/trunk/test/CodeGen/cast.c
Modified:
    cfe/trunk/CodeGen/CGExprScalar.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj

Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=44908&r1=44907&r2=44908&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Tue Dec 11 22:13:20 2007
@@ -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() == 

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=44908&r1=44907&r2=44908&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Dec 11 22:13:20 2007
@@ -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 = "";

Added: cfe/trunk/test/CodeGen/cast.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cast.c?rev=44908&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/cast.c (added)
+++ cfe/trunk/test/CodeGen/cast.c Tue Dec 11 22:13:20 2007
@@ -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); }
+





More information about the cfe-commits mailing list