Skip to content

Commit 14e89b0

Browse files
committed
[C++20] [Modules] Add exported modules as transitive imported modules
Close #144230 The root cause of the problem is, when we decide the transitive imports, we didn't deal with exported imports.
1 parent 8747736 commit 14e89b0

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

clang/lib/Sema/SemaModule.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ makeTransitiveImportsVisible(ASTContext &Ctx, VisibleModuleSet &VisibleModules,
136136
"modules only.");
137137

138138
llvm::SmallVector<Module *, 4> Worklist;
139+
llvm::SmallSet<Module *, 16> Visited;
139140
Worklist.push_back(Imported);
140141

141142
Module *FoundPrimaryModuleInterface =
@@ -144,18 +145,22 @@ makeTransitiveImportsVisible(ASTContext &Ctx, VisibleModuleSet &VisibleModules,
144145
while (!Worklist.empty()) {
145146
Module *Importing = Worklist.pop_back_val();
146147

147-
if (VisibleModules.isVisible(Importing))
148+
if (Visited.count(Importing))
148149
continue;
150+
Visited.insert(Importing);
149151

150152
// FIXME: The ImportLoc here is not meaningful. It may be problematic if we
151153
// use the sourcelocation loaded from the visible modules.
152154
VisibleModules.setVisible(Importing, ImportLoc);
153155

154156
if (isImportingModuleUnitFromSameModule(Ctx, Importing, CurrentModule,
155-
FoundPrimaryModuleInterface))
157+
FoundPrimaryModuleInterface)) {
156158
for (Module *TransImported : Importing->Imports)
157-
if (!VisibleModules.isVisible(TransImported))
158-
Worklist.push_back(TransImported);
159+
Worklist.push_back(TransImported);
160+
161+
for (auto [Exports, _] : Importing->Exports)
162+
Worklist.push_back(Exports);
163+
}
159164
}
160165
}
161166

clang/test/Modules/pr144230.cppm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
5+
// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
6+
// RUN: %clang_cc1 -std=c++20 %t/P.cppm -emit-module-interface -o %t/M-P.pcm -fprebuilt-module-path=%t
7+
// RUN: %clang_cc1 -std=c++20 %t/M.cppm -emit-module-interface -o %t/M.pcm -fprebuilt-module-path=%t
8+
// RUN: %clang_cc1 -std=c++20 %t/M.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
9+
10+
//--- A.cppm
11+
export module A;
12+
export using T = int;
13+
14+
//--- P.cppm
15+
export module M:P;
16+
import A;
17+
18+
//--- M.cppm
19+
export module M;
20+
export import :P;
21+
22+
//--- M.cpp
23+
// expected-no-diagnostics
24+
module M;
25+
26+
T x;

0 commit comments

Comments
 (0)