[PATCH] D115610: [C++20] [Modules] Don't create multiple global module fragment
Chuanqi Xu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 7 19:53:03 PST 2022
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3504937dfb2b: [C++20] [Modules] Don't create multiple global module fragment (authored by ChuanqiXu).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115610/new/
https://reviews.llvm.org/D115610
Files:
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaModule.cpp
clang/test/CXX/module/module.unit/p7/Inputs/h8.h
clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
clang/test/CXX/module/module.unit/p7/t8.cpp
Index: clang/test/CXX/module/module.unit/p7/t8.cpp
===================================================================
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/t8.cpp
@@ -0,0 +1,7 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %S/Inputs/m8.cppm -I%S/Inputs -o %t/m8.pcm
+// RUN: %clang_cc1 -std=c++20 -I%S/Inputs/ -fprebuilt-module-path=%t %s -verify -fsyntax-only
+// expected-no-diagnostics
+export module t8;
+import m8;
Index: clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
===================================================================
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
@@ -0,0 +1,7 @@
+module;
+#include "h8.h"
+export module m8;
+
+extern "C++" {
+void bar();
+}
Index: clang/test/CXX/module/module.unit/p7/Inputs/h8.h
===================================================================
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/Inputs/h8.h
@@ -0,0 +1,4 @@
+#ifndef H8
+#define H8
+void foo();
+#endif
Index: clang/lib/Sema/SemaModule.cpp
===================================================================
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -720,19 +720,24 @@
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() {
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -2218,6 +2218,8 @@
};
/// The modules we're currently parsing.
llvm::SmallVector<ModuleScope, 16> ModuleScopes;
+ /// The global module fragment of the current translation unit.
+ clang::Module *GlobalModuleFragment = nullptr;
/// Namespace definitions that we will export when they finish.
llvm::SmallPtrSet<const NamespaceDecl*, 8> DeferredExportedNamespaces;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115610.406685.patch
Type: text/x-patch
Size: 3121 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220208/5dc0fe33/attachment.bin>
More information about the cfe-commits
mailing list