aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaModule.cpp
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2022-02-08 11:50:57 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2022-02-08 11:52:09 +0800
commit3504937dfb2b7d90b2c3b3c7b28c472d31489007 (patch)
treebd149b3e1d54394be7b0cf3c0a1428feaf882bba /clang/lib/Sema/SemaModule.cpp
parente39ba0461757339f7172f6bc3882f41116bb7c13 (diff)
downloadllvm-3504937dfb2b7d90b2c3b3c7b28c472d31489007.zip
llvm-3504937dfb2b7d90b2c3b3c7b28c472d31489007.tar.gz
llvm-3504937dfb2b7d90b2c3b3c7b28c472d31489007.tar.bz2
[C++20] [Modules] Don't create multiple global module fragment
Since the serialization code would recognize modules by names and the name of all global module fragment is <global>, so that the serialization code would complain for the same module. This patch fixes this by using a unique global module fragment in Sema. Before this patch, the compiler would fail on an assertion complaining the duplicated modules. Reviewed By: urnathan, rsmith Differential Revision: https://reviews.llvm.org/D115610
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r--clang/lib/Sema/SemaModule.cpp21
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() {