diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-07-20 19:10:16 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-07-20 19:10:16 +0000 |
commit | 3b75c09ec6e3dbf1722c6aa551b51202f2e8c22d (patch) | |
tree | 90c143c4a3f71bec5ddb9bcf59be381ab77dc2af /lib/CodeGen/CodeGenModule.cpp | |
parent | bb573cbb0fcc4e8e0049132504502e48f59c12f4 (diff) | |
download | clang-3b75c09ec6e3dbf1722c6aa551b51202f2e8c22d.tar.gz |
[modules] Don't emit initializers for VarDecls within a module eagerly whenever
we first touch any part of that module. Instead, defer them until the first
time that module is (transitively) imported. The initializer step for a module
then recursively initializes modules that its own headers imported.
For example, this avoids running the <iostream> global initializer in programs
that don't actually use iostreams, but do use other parts of the standard
library.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276159 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 0ef5b74124..f73e85dd42 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -3910,13 +3910,19 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { case Decl::Import: { auto *Import = cast<ImportDecl>(D); - // Ignore import declarations that come from imported modules. - if (Import->getImportedOwningModule()) + // If we've already imported this module, we're done. + if (!ImportedModules.insert(Import->getImportedModule())) break; - if (CGDebugInfo *DI = getModuleDebugInfo()) - DI->EmitImportDecl(*Import); - ImportedModules.insert(Import->getImportedModule()); + // Emit debug information for direct imports. + if (!Import->getImportedOwningModule()) { + if (CGDebugInfo *DI = getModuleDebugInfo()) + DI->EmitImportDecl(*Import); + } + + // Emit the module initializers. + for (auto *D : Context.getModuleInitializers(Import->getImportedModule())) + EmitTopLevelDecl(D); break; } |