diff options
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r-- | clang/lib/Sema/SemaModule.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 747734f..85e5864 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -720,19 +720,24 @@ Decl *Sema::ActOnFinishExportDecl(Scope *S, Decl *D, SourceLocation RBraceLoc) { Module *Sema::PushGlobalModuleFragment(SourceLocation BeginLoc, bool IsImplicit) { - ModuleMap &Map = PP.getHeaderSearchInfo().getModuleMap(); - Module *GlobalModule = - Map.createGlobalModuleFragmentForModuleUnit(BeginLoc, getCurrentModule()); - assert(GlobalModule && "module creation should not fail"); + // We shouldn't create new global module fragment if there is already + // one. + if (!GlobalModuleFragment) { + ModuleMap &Map = PP.getHeaderSearchInfo().getModuleMap(); + GlobalModuleFragment = Map.createGlobalModuleFragmentForModuleUnit( + BeginLoc, getCurrentModule()); + } + + assert(GlobalModuleFragment && "module creation should not fail"); // Enter the scope of the global module. - ModuleScopes.push_back({BeginLoc, GlobalModule, + ModuleScopes.push_back({BeginLoc, GlobalModuleFragment, /*ModuleInterface=*/false, /*ImplicitGlobalModuleFragment=*/IsImplicit, - /*VisibleModuleSet*/{}}); - VisibleModules.setVisible(GlobalModule, BeginLoc); + /*VisibleModuleSet*/ {}}); + VisibleModules.setVisible(GlobalModuleFragment, BeginLoc); - return GlobalModule; + return GlobalModuleFragment; } void Sema::PopGlobalModuleFragment() { |