From bf52ead24ca4fe1b73bceec7bba3abfe15541649 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Fri, 3 Mar 2023 10:31:48 +0800 Subject: [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 --- clang/lib/Lex/ModuleMap.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'clang/lib/Lex/ModuleMap.cpp') 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("", 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 ? "" + : "", + Loc, Parent, /*IsFramework*/ false, + /*IsExplicit*/ !IsExported, NumCreatedModules++); + Result->Kind = Module::ImplicitGlobalModuleFragment; + return Result; +} + Module * ModuleMap::createPrivateModuleFragmentForInterfaceUnit(Module *Parent, SourceLocation Loc) { -- cgit v1.1