From: Chris Lattner Date: Wed, 12 Dec 2007 04:13:20 +0000 (+0000) Subject: Fix a codegen crash on test/CodeGen/cast.c, reported by Keith. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a9e6372208ad77eb2cae639a8a17c86551ac1937;p=clang 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 9846d81d1e..5ef7496a66 100644 --- a/CodeGen/CGExprScalar.cpp +++ b/CodeGen/CGExprScalar.cpp @@ -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(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(E->getType().getCanonicalType())-> getReferenceeType() == diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index 789b272fa4..ed2ec876d3 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 0000000000..dfd9bb87c3 --- /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); } +