summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-10-08 17:28:59 +0000
committerAnders Carlsson <andersca@mac.com>2009-10-08 17:28:59 +0000
commita18ed9b11310391004867b7d0bc50551d2024efd (patch)
treeaea5e1e97f5444939d9b7c89f0dbbe783a2748a2 /clang/lib/CodeGen/CodeGenModule.cpp
parent9776bd61bcdfe2ec6245f42d364725356e9d1d71 (diff)
downloadbcm5719-llvm-a18ed9b11310391004867b7d0bc50551d2024efd.tar.gz
bcm5719-llvm-a18ed9b11310391004867b7d0bc50551d2024efd.zip
If a global initializer has a non-trivial constructor or destructor, we never want to defer generation of it, even if it is declared static.
With this change we're finally able to compile and run the (infamous) #include <string> #include <iostream> int main(int argc, char **argv) { std::cout << "Hello, World" << std::endl; } $ clang hello.cpp -lstdc++ -o hello $ ./hello Hello, World llvm-svn: 83559
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 246beaa4034..800600f4b78 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -531,6 +531,17 @@ bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) {
const VarDecl *VD = cast<VarDecl>(Global);
assert(VD->isFileVarDecl() && "Invalid decl");
+ // We never want to defer structs that have non-trivial constructors or
+ // destructors.
+
+ // FIXME: Handle references.
+ if (const RecordType *RT = VD->getType()->getAs<RecordType>()) {
+ if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
+ if (!RD->hasTrivialConstructor() || !RD->hasTrivialDestructor())
+ return false;
+ }
+ }
+
return VD->getStorageClass() == VarDecl::Static;
}
OpenPOWER on IntegriCloud