From d8d18d561e464a2ef70aaff5bd17897dd6d51ae3 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 2 Dec 2007 07:30:13 +0000 Subject: add codegen support for global inits that require array decay. llvm-svn: 44511 --- clang/CodeGen/CodeGenModule.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'clang/CodeGen/CodeGenModule.cpp') diff --git a/clang/CodeGen/CodeGenModule.cpp b/clang/CodeGen/CodeGenModule.cpp index 6ef62065442..97ff705a39f 100644 --- a/clang/CodeGen/CodeGenModule.cpp +++ b/clang/CodeGen/CodeGenModule.cpp @@ -368,6 +368,27 @@ static llvm::Constant *GenerateConstantExpr(const Expr *Expression, case Stmt::ImplicitCastExprClass: { const ImplicitCastExpr *ICExpr = cast(Expression); + + // If this is due to array->pointer conversion, emit the array expression as + // an l-value. + if (ICExpr->getSubExpr()->getType()->isArrayType()) { + // FIXME: For now we assume that all source arrays map to LLVM arrays. + // This will not true when we add support for VLAs. + // The only thing that can have array type like this is a + // DeclRefExpr(FileVarDecl)? + const DeclRefExpr *DRE = cast(ICExpr->getSubExpr()); + const FileVarDecl *FVD = cast(DRE->getDecl()); + llvm::Constant *C = CGM.GetAddrOfFileVarDecl(FVD, false); + assert(isa(C->getType()) && + isa(cast(C->getType()) + ->getElementType()) && + "Doesn't support VLAs yet!"); + llvm::Constant *Idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); + + llvm::Constant *Ops[] = {Idx0, Idx0}; + return llvm::ConstantExpr::getGetElementPtr(C, Ops, 2); + } + return GenerateConstantCast(ICExpr->getSubExpr(), type, CGM); } -- cgit v1.2.3