[PATCH] D116098: [C++20] [Coroutines] Mark imported module as imported if not exported

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 21 03:27:41 PST 2021

ChuanqiXu created this revision.
ChuanqiXu added reviewers: rsmith, aaron.ballman, urnathan, iains.
ChuanqiXu added a project: clang.
ChuanqiXu requested review of this revision.
Herald added a subscriber: cfe-commits.

The intention of this patch is described in the title. I met the problem in the original test. The original behavior of the test is clearly incorrect.

And I found this patch could solve the problem. And the original behavior looks odd. It only maintain the `Exports` field but not `Imports` field. So I am not sure if the behavior was intended or it is just an oversight. I did simple test but I am not sure if this change is good.

  rG LLVM Github Monorepo



Index: clang/test/Modules/module-transtive-instantiation.cpp
--- clang/test/Modules/module-transtive-instantiation.cpp
+++ clang/test/Modules/module-transtive-instantiation.cpp
@@ -3,11 +3,9 @@
 // RUN: %clang -std=c++20 %S/Inputs/module-transtive-instantiation/Templ.cppm --precompile -o %t/Templ.pcm
 // RUN: %clang -std=c++20 %S/Inputs/module-transtive-instantiation/bar.cppm  --precompile -fprebuilt-module-path=%t -o %t/bar.pcm
 // RUN: %clang -std=c++20 -fprebuilt-module-path=%t %s -c -Xclang -verify
+// expected-no-diagnostics
 import bar;
 int foo() {
-    // FIXME: It shouldn't be an error. Since the `G` is already imported in bar.
-    return bar<int>(); // expected-error at Inputs/module-transtive-instantiation/bar.cppm:5 {{definition of 'G' must be imported from module 'Templ' before it is required}}
-                       // expected-note at -1 {{in instantiation of function template specialization 'bar<int>' requested here}}
-                       // expected-note at Inputs/module-transtive-instantiation/Templ.cppm:3 {{definition here is not reachable}}
+    return bar<int>();
Index: clang/lib/Sema/SemaModule.cpp
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -387,6 +387,8 @@
   if (!ModuleScopes.empty() && ModuleScopes.back().ModuleInterface) {
     if (ExportLoc.isValid() || getEnclosingExportDecl(Import))
       getCurrentModule()->Exports.emplace_back(Mod, false);
+    else
+      getCurrentModule()->Imports.insert(Mod);
   } else if (ExportLoc.isValid()) {
     Diag(ExportLoc, diag::err_export_not_in_module_interface);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116098.395634.patch
Type: text/x-patch
Size: 1723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211221/9d7cf825/attachment-0001.bin>

More information about the cfe-commits mailing list