r193005 - Fix crash if a submodule @imports another submodule from the same module. The
Richard Smith
richard-llvm at metafoo.co.uk
Fri Oct 18 15:48:21 PDT 2013
Author: rsmith
Date: Fri Oct 18 17:48:20 2013
New Revision: 193005
URL: http://llvm.org/viewvc/llvm-project?rev=193005&view=rev
Log:
Fix crash if a submodule @imports another submodule from the same module. The
test also adds FIXMEs for a number of places where imports and includes of
submodules don't work very well.
Added:
cfe/trunk/test/Modules/Inputs/submodules/import-self-a.h
cfe/trunk/test/Modules/Inputs/submodules/import-self-b.h
cfe/trunk/test/Modules/Inputs/submodules/import-self-c.h
cfe/trunk/test/Modules/Inputs/submodules/import-self-d.h
Modified:
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/test/Modules/Inputs/submodules/module.map
cfe/trunk/test/Modules/submodules.cpp
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=193005&r1=193004&r2=193005&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Fri Oct 18 17:48:20 2013
@@ -1108,23 +1108,23 @@ CompilerInstance::loadModule(SourceLocat
ModuleIdPath Path,
Module::NameVisibilityKind Visibility,
bool IsInclusionDirective) {
+ // Determine what file we're searching from.
+ StringRef ModuleName = Path[0].first->getName();
+ SourceLocation ModuleNameLoc = Path[0].second;
+
// If we've already handled this import, just return the cached result.
// This one-element cache is important to eliminate redundant diagnostics
// when both the preprocessor and parser see the same import declaration.
if (!ImportLoc.isInvalid() && LastModuleImportLoc == ImportLoc) {
// Make the named module visible.
- if (LastModuleImportResult)
+ if (LastModuleImportResult && ModuleName != getLangOpts().CurrentModule)
ModuleManager->makeModuleVisible(LastModuleImportResult, Visibility,
ImportLoc, /*Complain=*/false);
return LastModuleImportResult;
}
-
- // Determine what file we're searching from.
- StringRef ModuleName = Path[0].first->getName();
- SourceLocation ModuleNameLoc = Path[0].second;
clang::Module *Module = 0;
-
+
// If we don't already have information on this module, load the module now.
llvm::DenseMap<const IdentifierInfo *, clang::Module *>::iterator Known
= KnownModules.find(Path[0].first);
Added: cfe/trunk/test/Modules/Inputs/submodules/import-self-a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules/import-self-a.h?rev=193005&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/submodules/import-self-a.h (added)
+++ cfe/trunk/test/Modules/Inputs/submodules/import-self-a.h Fri Oct 18 17:48:20 2013
@@ -0,0 +1 @@
+typedef int MyTypeA;
Added: cfe/trunk/test/Modules/Inputs/submodules/import-self-b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules/import-self-b.h?rev=193005&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/submodules/import-self-b.h (added)
+++ cfe/trunk/test/Modules/Inputs/submodules/import-self-b.h Fri Oct 18 17:48:20 2013
@@ -0,0 +1,10 @@
+ at import import_self.c;
+#include "import-self-d.h"
+
+// FIXME: This should not work; names from 'a' should not be visible here.
+MyTypeA import_self_test_a;
+
+// FIXME: This should work but does not; names from 'b' are not actually visible here.
+//MyTypeC import_self_test_c;
+
+MyTypeD import_self_test_d;
Added: cfe/trunk/test/Modules/Inputs/submodules/import-self-c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules/import-self-c.h?rev=193005&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/submodules/import-self-c.h (added)
+++ cfe/trunk/test/Modules/Inputs/submodules/import-self-c.h Fri Oct 18 17:48:20 2013
@@ -0,0 +1 @@
+typedef int MyTypeC;
Added: cfe/trunk/test/Modules/Inputs/submodules/import-self-d.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules/import-self-d.h?rev=193005&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/submodules/import-self-d.h (added)
+++ cfe/trunk/test/Modules/Inputs/submodules/import-self-d.h Fri Oct 18 17:48:20 2013
@@ -0,0 +1 @@
+typedef int MyTypeD;
Modified: cfe/trunk/test/Modules/Inputs/submodules/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules/module.map?rev=193005&r1=193004&r2=193005&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/submodules/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/submodules/module.map Fri Oct 18 17:48:20 2013
@@ -3,3 +3,10 @@ module std {
module type_traits { header "type_traits.h" }
explicit module hash_map { header "hash_map.h" }
}
+
+module import_self {
+ module a { header "import-self-a.h" }
+ module b { header "import-self-b.h" export * }
+ module c { header "import-self-c.h" }
+ module d { header "import-self-d.h" }
+}
Modified: cfe/trunk/test/Modules/submodules.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/submodules.cpp?rev=193005&r1=193004&r2=193005&view=diff
==============================================================================
--- cfe/trunk/test/Modules/submodules.cpp (original)
+++ cfe/trunk/test/Modules/submodules.cpp Fri Oct 18 17:48:20 2013
@@ -27,3 +27,10 @@ hash_map<int, float> ints_to_floats; //
hash_map<int, float> ints_to_floats2;
+ at import import_self.b;
+extern MyTypeA import_self_test_a; // expected-error {{must be imported from module 'import_self.a'}}
+// expected-note at import-self-a.h:1 {{here}}
+extern MyTypeC import_self_test_c;
+// FIXME: This should be valid; import_self.b re-exports import_self.d.
+extern MyTypeD import_self_test_d; // expected-error {{must be imported from module 'import_self.d'}}
+// expected-note at import-self-d.h:1 {{here}}
More information about the cfe-commits
mailing list