[cfe-commits] r44511 - in /cfe/trunk: CodeGen/CodeGenModule.cpp test/CodeGen/globalinit.c
Chris Lattner
sabre at nondot.org
Sat Dec 1 23:30:13 PST 2007
Author: lattner
Date: Sun Dec 2 01:30:13 2007
New Revision: 44511
URL: http://llvm.org/viewvc/llvm-project?rev=44511&view=rev
Log:
add codegen support for global inits that require array decay.
Modified:
cfe/trunk/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/globalinit.c
Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=44511&r1=44510&r2=44511&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Sun Dec 2 01:30:13 2007
@@ -368,6 +368,27 @@
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);
}
Modified: cfe/trunk/test/CodeGen/globalinit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/globalinit.c?rev=44511&r1=44510&r2=44511&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/globalinit.c (original)
+++ cfe/trunk/test/CodeGen/globalinit.c Sun Dec 2 01:30:13 2007
@@ -8,3 +8,7 @@
int x[10];
void bar() { x[0] = 1; }
+
+extern int x[];
+void *g = x;
+
More information about the cfe-commits
mailing list