From a18ed9b11310391004867b7d0bc50551d2024efd Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Thu, 8 Oct 2009 17:28:59 +0000 Subject: 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 #include int main(int argc, char **argv) { std::cout << "Hello, World" << std::endl; } $ clang hello.cpp -lstdc++ -o hello $ ./hello Hello, World llvm-svn: 83559 --- clang/lib/CodeGen/CodeGenModule.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 246beaa..800600f 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(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()) { + if (const CXXRecordDecl *RD = dyn_cast(RT->getDecl())) { + if (!RD->hasTrivialConstructor() || !RD->hasTrivialDestructor()) + return false; + } + } + return VD->getStorageClass() == VarDecl::Static; } -- cgit v1.1