aboutsummaryrefslogtreecommitdiff
path: root/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-12-02 07:30:13 +0000
committerChris Lattner <sabre@nondot.org>2007-12-02 07:30:13 +0000
commit9615bf855ade12ca49e1a8767349d00ecf943b63 (patch)
tree23e81d71638441dc4a11549135c8006c30caeeb7 /CodeGen/CodeGenModule.cpp
parent2c8569d5f43f7de1fb993e84c95ea571dd9ac55e (diff)
add codegen support for global inits that require array decay.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44511 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen/CodeGenModule.cpp')
-rw-r--r--CodeGen/CodeGenModule.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp
index 6ef6206544..97ff705a39 100644
--- a/CodeGen/CodeGenModule.cpp
+++ b/CodeGen/CodeGenModule.cpp
@@ -368,6 +368,27 @@ static llvm::Constant *GenerateConstantExpr(const Expr *Expression,
case Stmt::ImplicitCastExprClass: {
const ImplicitCastExpr *ICExpr = cast<ImplicitCastExpr>(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<DeclRefExpr>(ICExpr->getSubExpr());
+ const FileVarDecl *FVD = cast<FileVarDecl>(DRE->getDecl());
+ llvm::Constant *C = CGM.GetAddrOfFileVarDecl(FVD, false);
+ assert(isa<llvm::PointerType>(C->getType()) &&
+ isa<llvm::ArrayType>(cast<llvm::PointerType>(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);
}