From b934d248d001d1536e074e3e8da8f47db63d719f Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 18 Oct 2013 22:48:20 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193005 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/CompilerInstance.cpp | 12 ++++++------ test/Modules/Inputs/submodules/import-self-a.h | 1 + test/Modules/Inputs/submodules/import-self-b.h | 10 ++++++++++ test/Modules/Inputs/submodules/import-self-c.h | 1 + test/Modules/Inputs/submodules/import-self-d.h | 1 + test/Modules/Inputs/submodules/module.map | 7 +++++++ test/Modules/submodules.cpp | 7 +++++++ 7 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 test/Modules/Inputs/submodules/import-self-a.h create mode 100644 test/Modules/Inputs/submodules/import-self-b.h create mode 100644 test/Modules/Inputs/submodules/import-self-c.h create mode 100644 test/Modules/Inputs/submodules/import-self-d.h diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 7c5ca01272..9f0ca3b31e 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -1108,23 +1108,23 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, 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::iterator Known = KnownModules.find(Path[0].first); diff --git a/test/Modules/Inputs/submodules/import-self-a.h b/test/Modules/Inputs/submodules/import-self-a.h new file mode 100644 index 0000000000..adb070abf3 --- /dev/null +++ b/test/Modules/Inputs/submodules/import-self-a.h @@ -0,0 +1 @@ +typedef int MyTypeA; diff --git a/test/Modules/Inputs/submodules/import-self-b.h b/test/Modules/Inputs/submodules/import-self-b.h new file mode 100644 index 0000000000..f88b56d5f0 --- /dev/null +++ b/test/Modules/Inputs/submodules/import-self-b.h @@ -0,0 +1,10 @@ +@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; diff --git a/test/Modules/Inputs/submodules/import-self-c.h b/test/Modules/Inputs/submodules/import-self-c.h new file mode 100644 index 0000000000..f4b86c5656 --- /dev/null +++ b/test/Modules/Inputs/submodules/import-self-c.h @@ -0,0 +1 @@ +typedef int MyTypeC; diff --git a/test/Modules/Inputs/submodules/import-self-d.h b/test/Modules/Inputs/submodules/import-self-d.h new file mode 100644 index 0000000000..e32a6f5195 --- /dev/null +++ b/test/Modules/Inputs/submodules/import-self-d.h @@ -0,0 +1 @@ +typedef int MyTypeD; diff --git a/test/Modules/Inputs/submodules/module.map b/test/Modules/Inputs/submodules/module.map index 16cedac231..c91e94f47d 100644 --- a/test/Modules/Inputs/submodules/module.map +++ b/test/Modules/Inputs/submodules/module.map @@ -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" } +} diff --git a/test/Modules/submodules.cpp b/test/Modules/submodules.cpp index c653dddbbb..9c62389ead 100644 --- a/test/Modules/submodules.cpp +++ b/test/Modules/submodules.cpp @@ -27,3 +27,10 @@ hash_map ints_to_floats; // expected-error{{declaration of 'hash_map hash_map 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; +// 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@import-self-d.h:1 {{here}} -- 2.40.0