diff options
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 7 | ||||
-rw-r--r-- | clang/test/Modules/import-self.m | 11 | ||||
-rw-r--r-- | clang/test/Modules/submodules.cpp | 6 |
5 files changed, 21 insertions, 7 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index f46e08340cb..7c4f9883538 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6990,6 +6990,8 @@ def note_module_import_in_extern_c : Note< def err_module_import_not_at_top_level : Error< "import of module '%0' appears within %1">; def note_module_import_not_at_top_level : Note<"%0 begins here">; +def err_module_self_import : Error< + "import of module '%0' appears within same top-level module '%1'">; } let CategoryName = "Documentation Issue" in { diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 76301f2a44e..d7b526b2da2 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1164,7 +1164,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, Module = Known->second; } else if (ModuleName == getLangOpts().CurrentModule) { // This is the module we're building. - Module = PP->getHeaderSearchInfo().getModuleMap().findModule(ModuleName); + Module = PP->getHeaderSearchInfo().lookupModule(ModuleName); Known = KnownModules.insert(std::make_pair(Path[0].first, Module)).first; } else { // Search for a module with the given name. diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 743a8f29439..3ee1577b0ba 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -13142,6 +13142,13 @@ DeclResult Sema::ActOnModuleImport(SourceLocation AtLoc, checkModuleImportContext(*this, Mod, ImportLoc, CurContext); + // FIXME: we should support importing a submodule within a different submodule + // of the same top-level module. Until we do, make it an error rather than + // silently ignoring the import. + if (Mod->getTopLevelModuleName() == getLangOpts().CurrentModule) + Diag(ImportLoc, diag::err_module_self_import) + << Mod->getFullModuleName() << getLangOpts().CurrentModule; + SmallVector<SourceLocation, 2> IdentifierLocs; Module *ModCheck = Mod; for (unsigned I = 0, N = Path.size(); I != N; ++I) { diff --git a/clang/test/Modules/import-self.m b/clang/test/Modules/import-self.m new file mode 100644 index 00000000000..68be565eaf4 --- /dev/null +++ b/clang/test/Modules/import-self.m @@ -0,0 +1,11 @@ +// RUN: rm -rf %t +// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t \ +// RUN: -I %S/Inputs/submodules %s 2>&1 | FileCheck %s +// CHECK: import of module 'import_self.c' appears within same top-level module 'import_self' + +// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t \ +// RUN: -I %S/Inputs/submodules -fmodule-name=import_self %s \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-fmodule-name %s +// CHECK-fmodule-name: import of module 'import_self.b' appears within same top-level module 'import_self' + +@import import_self.b; diff --git a/clang/test/Modules/submodules.cpp b/clang/test/Modules/submodules.cpp index 7ef785c936c..c3b2623016a 100644 --- a/clang/test/Modules/submodules.cpp +++ b/clang/test/Modules/submodules.cpp @@ -26,9 +26,3 @@ hash_map<int, float> ints_to_floats; // expected-error{{declaration of 'hash_map @import std.hash_map; hash_map<int, float> ints_to_floats2; - -@import import_self.b; -extern MyTypeA import_self_test_a; // expected-error {{must be imported from module 'import_self.a'}} -// expected-note@import-self-a.h:1 {{here}} -extern MyTypeC import_self_test_c; -extern MyTypeD import_self_test_d; |