summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-07-15 23:40:35 +0000
committerJohn McCall <rjmccall@apple.com>2010-07-15 23:40:35 +0000
commit70013b640f175f5e6992e3193be3ae3c862416d6 (patch)
tree42a5e2f79975485b0b2bd1b3b5b2e5cd118890b5 /clang/lib/CodeGen/CodeGenModule.cpp
parentfbbdfcaea78dd354cad7bbf2d98de6d201307c69 (diff)
downloadbcm5719-llvm-70013b640f175f5e6992e3193be3ae3c862416d6.tar.gz
bcm5719-llvm-70013b640f175f5e6992e3193be3ae3c862416d6.zip
When deferring the emission of declarations with initializers in C++, remember
the order they appeared in the translation unit. If they get emitted, put them in their proper order. Fixes rdar://problem/7458115 llvm-svn: 108477
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 834f981a528..ed954223002 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -792,6 +792,14 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
EmitGlobalDefinition(GD);
return;
}
+
+ // If we're deferring emission of a C++ variable with an
+ // initializer, remember the order in which it appeared in the file.
+ if (getLangOptions().CPlusPlus && isa<VarDecl>(Global) &&
+ cast<VarDecl>(Global)->hasInit()) {
+ DelayedCXXInitPosition[Global] = CXXGlobalInits.size();
+ CXXGlobalInits.push_back(0);
+ }
// If the value has already been used, add it directly to the
// DeferredDeclsToEmit list.
@@ -1175,6 +1183,11 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
ErrorUnsupported(D, "static initializer");
Init = llvm::UndefValue::get(getTypes().ConvertType(T));
}
+ } else {
+ // We don't need an initializer, so remove the entry for the delayed
+ // initializer position (just in case this entry was delayed).
+ if (getLangOptions().CPlusPlus)
+ DelayedCXXInitPosition.erase(D);
}
}
OpenPOWER on IntegriCloud