From 3b5dbf23a4025fc2c66fcb9dc662b148fa56a12e Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Fri, 14 Oct 2016 18:55:44 +0000 Subject: Module: emit initializers in submodules when importing the parent module. When importing the parent module, module initializers in submodules should be emitted. rdar://28740482 llvm-svn: 284263 --- clang/lib/CodeGen/CodeGenModule.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index f4628fc0d33..21849590b11 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3951,9 +3951,33 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { DI->EmitImportDecl(*Import); } - // Emit the module initializers. - for (auto *D : Context.getModuleInitializers(Import->getImportedModule())) - EmitTopLevelDecl(D); + // Find all of the submodules and emit the module initializers. + llvm::SmallPtrSet Visited; + SmallVector Stack; + Visited.insert(Import->getImportedModule()); + Stack.push_back(Import->getImportedModule()); + + while (!Stack.empty()) { + clang::Module *Mod = Stack.pop_back_val(); + if (!EmittedModuleInitializers.insert(Mod).second) + continue; + + for (auto *D : Context.getModuleInitializers(Mod)) + EmitTopLevelDecl(D); + + // Visit the submodules of this module. + for (clang::Module::submodule_iterator Sub = Mod->submodule_begin(), + SubEnd = Mod->submodule_end(); + Sub != SubEnd; ++Sub) { + // Skip explicit children; they need to be explicitly imported to emit + // the initializers. + if ((*Sub)->IsExplicit) + continue; + + if (Visited.insert(*Sub).second) + Stack.push_back(*Sub); + } + } break; } -- cgit v1.2.3