From e587372f85105b85ae790fbe129b5d609d6dfb76 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Wed, 8 Dec 2021 11:34:18 +0800 Subject: [C++20] [Module] Support extern C/C++ semantics According to [module.unit]p7.2.3, a declaration within a linkage-specification should be attached to the global module. This let user to forward declare types across modules. Reviewed by: rsmith, aaron.ballman Differential Revision: https://reviews.llvm.org/D110215 --- clang/lib/Lex/ModuleMap.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'clang/lib/Lex/ModuleMap.cpp') diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 9fa1704..0b136ae 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -832,12 +832,16 @@ std::pair ModuleMap::findOrCreateModule(StringRef Name, return std::make_pair(Result, true); } -Module *ModuleMap::createGlobalModuleFragmentForModuleUnit(SourceLocation Loc) { - PendingSubmodules.emplace_back( - new Module("", Loc, nullptr, /*IsFramework*/ false, - /*IsExplicit*/ true, NumCreatedModules++)); - PendingSubmodules.back()->Kind = Module::GlobalModuleFragment; - return PendingSubmodules.back().get(); +Module *ModuleMap::createGlobalModuleFragmentForModuleUnit(SourceLocation Loc, + Module *Parent) { + auto *Result = new Module("", Loc, Parent, /*IsFramework*/ false, + /*IsExplicit*/ true, NumCreatedModules++); + Result->Kind = Module::GlobalModuleFragment; + // If the created module isn't owned by a parent, send it to PendingSubmodules + // to wait for its parent. + if (!Result->Parent) + PendingSubmodules.emplace_back(Result); + return Result; } Module * -- cgit v1.1