aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/ModuleMap.cpp
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2023-03-03 10:31:48 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2023-03-03 10:31:48 +0800
commitbf52ead24ca4fe1b73bceec7bba3abfe15541649 (patch)
tree356336638558c02b5ad2f31be9060cd1642c2985 /clang/lib/Lex/ModuleMap.cpp
parent87cf39aa349b83ae3b7d16c30ac7a8ffa0ad098c (diff)
downloadllvm-bf52ead24ca4fe1b73bceec7bba3abfe15541649.zip
llvm-bf52ead24ca4fe1b73bceec7bba3abfe15541649.tar.gz
llvm-bf52ead24ca4fe1b73bceec7bba3abfe15541649.tar.bz2
[C++20] [Modules] Support to export declarations in language linkage
Close https://github.com/llvm/llvm-project/issues/60405 See the discussion in the above link for the background. What the patch does: - Rename `Module::ModuleKind::GlobalModuleFragment` to `Module::ModuleKind::ExplicitGlobalModuleFragment`. - Add another module kind `ImplicitGlobalModuleFragment` to `ModuleKind`. - Create an implicit global module fragment for the language linkage declarations inside a module purview. - If the language linkage lives inside the scope of an export decl, the created modules is marked as exported to outer modules. - In fact, Sema will only create at most 2 implicit global module fragments to avoid creating a lot of unnecessary modules in the edging case. Reviewed By: iains Differential Revision: https://reviews.llvm.org/D144367
Diffstat (limited to 'clang/lib/Lex/ModuleMap.cpp')
-rw-r--r--clang/lib/Lex/ModuleMap.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 15f4377..5973b4a 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -855,7 +855,7 @@ Module *ModuleMap::createGlobalModuleFragmentForModuleUnit(SourceLocation Loc,
Module *Parent) {
auto *Result = new Module("<global>", Loc, Parent, /*IsFramework*/ false,
/*IsExplicit*/ true, NumCreatedModules++);
- Result->Kind = Module::GlobalModuleFragment;
+ Result->Kind = Module::ExplicitGlobalModuleFragment;
// If the created module isn't owned by a parent, send it to PendingSubmodules
// to wait for its parent.
if (!Result->Parent)
@@ -863,6 +863,21 @@ Module *ModuleMap::createGlobalModuleFragmentForModuleUnit(SourceLocation Loc,
return Result;
}
+Module *ModuleMap::createImplicitGlobalModuleFragmentForModuleUnit(
+ SourceLocation Loc, bool IsExported, Module *Parent) {
+ assert(Parent && "We should only create an implicit global module fragment "
+ "in a module purview");
+ // Note: Here the `IsExplicit` parameter refers to the semantics in clang
+ // modules. All the non-explicit submodules in clang modules will be exported
+ // too. Here we simplify the implementation by using the concept.
+ auto *Result = new Module(IsExported ? "<exported implicit global>"
+ : "<implicit global>",
+ Loc, Parent, /*IsFramework*/ false,
+ /*IsExplicit*/ !IsExported, NumCreatedModules++);
+ Result->Kind = Module::ImplicitGlobalModuleFragment;
+ return Result;
+}
+
Module *
ModuleMap::createPrivateModuleFragmentForInterfaceUnit(Module *Parent,
SourceLocation Loc) {