Author: benlangmuir
Date: Mon May 5 00:31:33 2014
New Revision: 207948
URL: http://llvm.org/viewvc/llvm-project?rev=207948&view=rev
Log:
Make module self-import an error
Ideally, importing Foo.a from Foo.b would "do the right thing", but
until it does, this patch makes it an error rather than allow it to
silently be ignored.
Added:
cfe/trunk/test/Modules/import-self.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Modules/submodules.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=207948&r1=207947&r2=207948&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon May 5 00:31:33
2014
@@ -6990,6 +6990,8 @@ def note_module_import_in_extern_c : Not
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 {
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=207948&r1=207947&r2=207948&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Mon May 5 00:31:33 2014
@@ -1164,7 +1164,7 @@ CompilerInstance::loadModule(SourceLocat
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.
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=207948&r1=207947&r2=207948&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon May 5 00:31:33 2014
@@ -13142,6 +13142,13 @@ DeclResult Sema::ActOnModuleImport(Sourc
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) {
Added: cfe/trunk/test/Modules/import-self.m
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/import-self.m?rev=207948&view=auto
==============================================================================
--- cfe/trunk/test/Modules/import-self.m (added)
+++ cfe/trunk/test/Modules/import-self.m Mon May 5 00:31:33 2014
@@ -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;
Modified: cfe/trunk/test/Modules/submodules.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/submodules.cpp?rev=207948&r1=207947&r2=207948&view=diff
==============================================================================
--- cfe/trunk/test/Modules/submodules.cpp (original)
+++ cfe/trunk/test/Modules/submodules.cpp Mon May 5 00:31:33 2014
@@ -26,9 +26,3 @@ hash_map<int, float> ints_to_floats; //
@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'}}
-// [email protected]:1 {{here}}
-extern MyTypeC import_self_test_c;
-extern MyTypeD import_self_test_d;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits