Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 6b41ce0

Browse files
[modules-ts] Omit submodule semantics for TS modules
If a TS module name has more than one component (e.g., foo.bar) then we erroneously activated the submodule semantics when encountering a module declaration in the module implementation unit (e.g., 'module foo.bar;'). Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D35678 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312007 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9159422 commit 6b41ce0

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

lib/Frontend/CompilerInstance.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,22 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
16011601
Module::NameVisibilityKind Visibility,
16021602
bool IsInclusionDirective) {
16031603
// Determine what file we're searching from.
1604-
StringRef ModuleName = Path[0].first->getName();
1604+
// FIXME: Should we be deciding whether this is a submodule (here and
1605+
// below) based on -fmodules-ts or should we pass a flag and make the
1606+
// caller decide?
1607+
std::string ModuleName;
1608+
if (getLangOpts().ModulesTS) {
1609+
// FIXME: Same code as Sema::ActOnModuleDecl() so there is probably a
1610+
// better place/way to do this.
1611+
for (auto &Piece : Path) {
1612+
if (!ModuleName.empty())
1613+
ModuleName += ".";
1614+
ModuleName += Piece.first->getName();
1615+
}
1616+
}
1617+
else
1618+
ModuleName = Path[0].first->getName();
1619+
16051620
SourceLocation ModuleNameLoc = Path[0].second;
16061621

16071622
// If we've already handled this import, just return the cached result.
@@ -1816,7 +1831,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
18161831

18171832
// Verify that the rest of the module path actually corresponds to
18181833
// a submodule.
1819-
if (Path.size() > 1) {
1834+
if (!getLangOpts().ModulesTS && Path.size() > 1) {
18201835
for (unsigned I = 1, N = Path.size(); I != N; ++I) {
18211836
StringRef Name = Path[I].first->getName();
18221837
clang::Module *Sub = Module->findSubmodule(Name);

test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.import/p1.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
// RUN: mkdir -p %t
33
// RUN: echo 'export module x; export int a, b;' > %t/x.cppm
44
// RUN: echo 'export module x.y; export int c;' > %t/x.y.cppm
5+
// RUN: echo 'export module a.b; export int d;' > %t/a.b.cppm
56
//
67
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %t/x.cppm -o %t/x.pcm
78
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface -fmodule-file=%t/x.pcm %t/x.y.cppm -o %t/x.y.pcm
9+
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %t/a.b.cppm -o %t/a.b.pcm
810
//
9-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
11+
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -fmodule-file=%t/a.b.pcm -verify %s \
1012
// RUN: -DMODULE_NAME=z
11-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
13+
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -fmodule-file=%t/a.b.pcm -verify %s \
14+
// RUN: -DMODULE_NAME=a.b
15+
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -fmodule-file=%t/a.b.pcm -verify %s \
1216
// RUN: -DMODULE_X -DMODULE_NAME=x
1317

1418
module MODULE_NAME;
@@ -33,6 +37,7 @@ import x [[noreturn]]; // expected-error {{'noreturn' attribute cannot be applie
3337
import x [[blarg::noreturn]]; // expected-warning {{unknown attribute 'noreturn' ignored}}
3438

3539
import x.y;
40+
import a.b; // Does not imply existence of module a.
3641
import x.; // expected-error {{expected a module name after 'import'}}
3742
import .x; // expected-error {{expected a module name after 'import'}}
3843

0 commit comments

Comments
 (0)