Author: Chuanqi Xu
Date: 2025-06-20T17:03:29+08:00
New Revision: 14e89b061fdecedcec4bb035060a56588610cb5c

URL: 
https://github.com/llvm/llvm-project/commit/14e89b061fdecedcec4bb035060a56588610cb5c
DIFF: 
https://github.com/llvm/llvm-project/commit/14e89b061fdecedcec4bb035060a56588610cb5c.diff

LOG: [C++20] [Modules] Add exported modules as transitive imported modules

Close https://github.com/llvm/llvm-project/issues/144230

The root cause of the problem is, when we decide the transitive imports,
we didn't deal with exported imports.

Added: 
    clang/test/Modules/pr144230.cppm

Modified: 
    clang/lib/Sema/SemaModule.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 9fcaad48d3058..54ee0486763b1 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -136,6 +136,7 @@ makeTransitiveImportsVisible(ASTContext &Ctx, 
VisibleModuleSet &VisibleModules,
          "modules only.");
 
   llvm::SmallVector<Module *, 4> Worklist;
+  llvm::SmallSet<Module *, 16> Visited;
   Worklist.push_back(Imported);
 
   Module *FoundPrimaryModuleInterface =
@@ -144,18 +145,22 @@ makeTransitiveImportsVisible(ASTContext &Ctx, 
VisibleModuleSet &VisibleModules,
   while (!Worklist.empty()) {
     Module *Importing = Worklist.pop_back_val();
 
-    if (VisibleModules.isVisible(Importing))
+    if (Visited.count(Importing))
       continue;
+    Visited.insert(Importing);
 
     // FIXME: The ImportLoc here is not meaningful. It may be problematic if we
     // use the sourcelocation loaded from the visible modules.
     VisibleModules.setVisible(Importing, ImportLoc);
 
     if (isImportingModuleUnitFromSameModule(Ctx, Importing, CurrentModule,
-                                            FoundPrimaryModuleInterface))
+                                            FoundPrimaryModuleInterface)) {
       for (Module *TransImported : Importing->Imports)
-        if (!VisibleModules.isVisible(TransImported))
-          Worklist.push_back(TransImported);
+        Worklist.push_back(TransImported);
+
+      for (auto [Exports, _] : Importing->Exports)
+        Worklist.push_back(Exports);
+    }
   }
 }
 

diff  --git a/clang/test/Modules/pr144230.cppm 
b/clang/test/Modules/pr144230.cppm
new file mode 100644
index 0000000000000..7de9fc6461ab1
--- /dev/null
+++ b/clang/test/Modules/pr144230.cppm
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/P.cppm -emit-module-interface -o %t/M-P.pcm 
-fprebuilt-module-path=%t
+// RUN: %clang_cc1 -std=c++20 %t/M.cppm -emit-module-interface -o %t/M.pcm 
-fprebuilt-module-path=%t
+// RUN: %clang_cc1 -std=c++20 %t/M.cpp -fprebuilt-module-path=%t -fsyntax-only 
-verify
+
+//--- A.cppm
+export module A;
+export using T = int;
+
+//--- P.cppm
+export module M:P;
+import A;
+
+//--- M.cppm
+export module M;
+export import :P;
+
+//--- M.cpp
+// expected-no-diagnostics
+module M;
+
+T x;


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to