aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-07-20 19:10:16 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-07-20 19:10:16 +0000
commitdc1f042171d93709952aeaa1c83bf91c0cf8a1be (patch)
treea504aefcca00d128754cdcfb479bf7cabd423e87 /clang/lib/CodeGen/CodeGenModule.cpp
parent62ae568bbb9c4d22d341a71d12ab0bc74506476c (diff)
downloadllvm-dc1f042171d93709952aeaa1c83bf91c0cf8a1be.zip
llvm-dc1f042171d93709952aeaa1c83bf91c0cf8a1be.tar.gz
llvm-dc1f042171d93709952aeaa1c83bf91c0cf8a1be.tar.bz2
[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. llvm-svn: 276159
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0ef5b74..f73e85d 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/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;
}