From: Douglas Gregor Date: Tue, 6 Dec 2011 17:31:28 +0000 (+0000) Subject: When suggesting a module import for a #include or #import, suggest the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=09833925a3ac68065565e9556d06e9576ec6eaa9;p=clang When suggesting a module import for a #include or #import, suggest the most specific (sub)module based on the actual file we find, rather than always importing the top-level module. This means that #include'ing should give us the submodule Foo.Blah. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145942 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index 1d560fca02..f090e03174 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -341,15 +341,12 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup( } // Determine whether this is the module we're building or not. - // FIXME: Do we still need the ".." hack? - bool AutomaticImport = Module && - !Filename.substr(SlashPos + 1).startswith(".."); - + bool AutomaticImport = Module; FrameworkName.append(Filename.begin()+SlashPos+1, Filename.end()); if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str(), /*openFile=*/!AutomaticImport)) { if (AutomaticImport) - *SuggestedModule = Module; + *SuggestedModule = HS.findModuleForHeader(FE); return FE; } @@ -364,7 +361,7 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup( const FileEntry *FE = FileMgr.getFile(FrameworkName.str(), /*openFile=*/!AutomaticImport); if (FE && AutomaticImport) - *SuggestedModule = Module; + *SuggestedModule = HS.findModuleForHeader(FE); return FE; } diff --git a/test/Modules/auto-module-import.c b/test/Modules/auto-module-import.c index 51e9ee2d03..783b53d068 100644 --- a/test/Modules/auto-module-import.c +++ b/test/Modules/auto-module-import.c @@ -18,3 +18,14 @@ Module *mod; // expected-error{{unknown type name 'Module'}} Module *mod2; int getDependsOther() { return depends_on_module_other; } + +void testSubframeworkOther() { + double *sfo1 = sub_framework_other; // expected-error{{use of undeclared identifier 'sub_framework_other'}} +} + +// Test header cross-subframework include pattern. +#include // expected-warning{{treating #include as an import of module 'DependsOnModule.SubFramework'}} + +void testSubframeworkOtherAgain() { + double *sfo1 = sub_framework_other; +}