Add support for global initializers.

llvm-svn: 78515
This commit is contained in:
Anders Carlsson
2009-08-08 23:24:23 +00:00
parent cfed3005e5
commit b8be93fc92
7 changed files with 71 additions and 4 deletions

View File

@@ -62,6 +62,9 @@ CodeGenModule::~CodeGenModule() {
}
void CodeGenModule::Release() {
// We need to call this first because it can add deferred declarations.
EmitCXXGlobalInitFunc();
EmitDeferred();
if (Runtime)
if (llvm::Function *ObjCInitFunction = Runtime->ModuleInitFunction())
@@ -854,10 +857,16 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
Init = EmitNullConstant(D->getType());
} else {
Init = EmitConstantExpr(D->getInit(), D->getType());
if (!Init) {
ErrorUnsupported(D, "static initializer");
QualType T = D->getInit()->getType();
Init = llvm::UndefValue::get(getTypes().ConvertType(T));
if (getLangOptions().CPlusPlus) {
CXXGlobalInits.push_back(D);
Init = EmitNullConstant(T);
} else {
ErrorUnsupported(D, "static initializer");
Init = llvm::UndefValue::get(getTypes().ConvertType(T));
}
}
}