diff options
Diffstat (limited to 'lib/Lex')
-rw-r--r-- | lib/Lex/HeaderSearch.cpp | 18 | ||||
-rw-r--r-- | lib/Lex/PPDirectives.cpp | 26 |
2 files changed, 24 insertions, 20 deletions
diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index 9a7230c24e..b0668c53a4 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -197,7 +197,6 @@ const FileEntry *DirectoryLookup::LookupFile( HeaderSearch &HS, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, - StringRef BuildingModule, Module **SuggestedModule) const { llvm::SmallString<1024> TmpDir; if (isNormalDir()) { @@ -224,10 +223,7 @@ const FileEntry *DirectoryLookup::LookupFile( // If there is a module that corresponds to this header, // suggest it. - Module *Module = HS.findModuleForHeader(File); - if (Module && Module->getTopLevelModuleName() != BuildingModule) - *SuggestedModule = Module; - + *SuggestedModule = HS.findModuleForHeader(File); return File; } @@ -236,7 +232,7 @@ const FileEntry *DirectoryLookup::LookupFile( if (isFramework()) return DoFrameworkLookup(Filename, HS, SearchPath, RelativePath, - BuildingModule, SuggestedModule); + SuggestedModule); assert(isHeaderMap() && "Unknown directory lookup"); const FileEntry * const Result = getHeaderMap()->LookupFile( @@ -263,7 +259,6 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup( HeaderSearch &HS, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, - StringRef BuildingModule, Module **SuggestedModule) const { FileManager &FileMgr = HS.getFileMgr(); @@ -322,11 +317,8 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup( Module *Module = 0; if (SuggestedModule) { if (const DirectoryEntry *FrameworkDir - = FileMgr.getDirectory(FrameworkName)) { - if ((Module = HS.getFrameworkModule(ModuleName, FrameworkDir)) && - Module->Name == BuildingModule) - Module = 0; - } + = FileMgr.getDirectory(FrameworkName)) + Module = HS.getFrameworkModule(ModuleName, FrameworkDir); } // Check "/System/Library/Frameworks/Cocoa.framework/Headers/file.h" @@ -475,7 +467,7 @@ const FileEntry *HeaderSearch::LookupFile( for (; i != SearchDirs.size(); ++i) { const FileEntry *FE = SearchDirs[i].LookupFile(Filename, *this, SearchPath, RelativePath, - BuildingModule, SuggestedModule); + SuggestedModule); if (!FE) continue; CurDir = &SearchDirs[i]; diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index b44a0a2934..ba65c29e69 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -1352,12 +1352,21 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, break; } - CharSourceRange ReplaceRange(SourceRange(HashLoc, CharEnd), - /*IsTokenRange=*/false); - Diag(HashLoc, diag::warn_auto_module_import) - << IncludeKind << PathString - << FixItHint::CreateReplacement(ReplaceRange, - "__import_module__ " + PathString.str().str() + ";"); + // Determine whether we are actually building the module that this + // include directive maps to. + bool BuildingImportedModule + = Path[0].first->getName() == getLangOptions().CurrentModule; + + if (!BuildingImportedModule) { + // If we're not building the imported module, warn that we're going + // to automatically turn this inclusion directive into a module import. + CharSourceRange ReplaceRange(SourceRange(HashLoc, CharEnd), + /*IsTokenRange=*/false); + Diag(HashLoc, diag::warn_auto_module_import) + << IncludeKind << PathString + << FixItHint::CreateReplacement(ReplaceRange, + "__import_module__ " + PathString.str().str() + ";"); + } // Load the module. // If this was an #__include_macros directive, only make macros visible. @@ -1365,7 +1374,10 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, = (IncludeKind == 3)? Module::MacrosVisible : Module::AllVisible; TheModuleLoader.loadModule(IncludeTok.getLocation(), Path, Visibility, /*IsIncludeDirective=*/true); - return; + + // If this header isn't part of the module we're building, we're done. + if (!BuildingImportedModule) + return; } // The #included file will be considered to be a system header if either it is |