aboutsummaryrefslogtreecommitdiff
path: root/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
commit74d644abe56809d9bcea7311f37aa9063ab9e064 (patch)
tree235bd644018667d05cd5bdc62c1bfee76ec333da /lib/CodeGen/CodeGenModule.cpp
parenta3f36ab6dd9567ae4d1f1703a8413df911b91863 (diff)
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83559 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--lib/CodeGen/CodeGenModule.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 246beaa403..800600f4b7 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/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;
}