diff options
| author | Daniel Jasper <djasper@google.com> | 2013-12-11 12:13:00 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-12-11 12:13:00 +0000 |
| commit | 2d905f783e156936de2a19ba4b0c17aab3b3c3c6 (patch) | |
| tree | f17b86e34031d46addcfd72d177db66e969be09a /lib/Lex/ModuleMap.cpp | |
| parent | c9dd46748e1ca90f11414a8cf5fbdfa9e3d0a8b4 (diff) | |
| download | clang-2d905f783e156936de2a19ba4b0c17aab3b3c3c6.tar.gz clang-2d905f783e156936de2a19ba4b0c17aab3b3c3c6.tar.bz2 clang-2d905f783e156936de2a19ba4b0c17aab3b3c3c6.tar.xz | |
Modules: Let -fmodules-decluse ignore headers that aren't in a module
Includes might always pull in arbitrary header or data files outside of
modules. Among others, this includes builtin includes, which do not have
a module (story) yet.
Also cleanup implementation of ModuleMap::findModuleForHeader() to be
non-recursive.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197034 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/ModuleMap.cpp')
| -rw-r--r-- | lib/Lex/ModuleMap.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp index 3ce0def1d1..8a1fcaa69e 100644 --- a/lib/Lex/ModuleMap.cpp +++ b/lib/Lex/ModuleMap.cpp @@ -168,8 +168,19 @@ static bool isBuiltinHeader(StringRef FileName) { ModuleMap::KnownHeader ModuleMap::findModuleForHeader(const FileEntry *File, - Module *RequestingModule) { + Module *RequestingModule, + bool *FoundInModule) { HeadersMap::iterator Known = Headers.find(File); + + // If we've found a builtin header within Clang's builtin include directory, + // load all of the module maps to see if it will get associated with a + // specific module (e.g., in /usr/include). + if (Known == Headers.end() && File->getDir() == BuiltinIncludeDir && + isBuiltinHeader(llvm::sys::path::filename(File->getName()))) { + HeaderInfo.loadTopLevelSystemModules(); + Known = Headers.find(File); + } + if (Known != Headers.end()) { ModuleMap::KnownHeader Result = KnownHeader(); @@ -177,9 +188,15 @@ ModuleMap::findModuleForHeader(const FileEntry *File, for (SmallVectorImpl<KnownHeader>::iterator I = Known->second.begin(), E = Known->second.end(); I != E; ++I) { - // Cannot use a module if the header is excluded or unavailable in it. - if (I->getRole() == ModuleMap::ExcludedHeader || - !I->getModule()->isAvailable()) + // Cannot use a module if the header is excluded in it. + if (I->getRole() == ModuleMap::ExcludedHeader) + continue; + + if (FoundInModule) + *FoundInModule = true; + + // Cannot use a module if it is unavailable. + if (!I->getModule()->isAvailable()) continue; // If 'File' is part of 'RequestingModule', 'RequestingModule' is the @@ -194,6 +211,7 @@ ModuleMap::findModuleForHeader(const FileEntry *File, RequestingModule->DirectUses.end(), I->getModule()) == RequestingModule->DirectUses.end()) continue; + Result = *I; // If 'File' is a public header of this module, this is as good as we // are going to get. @@ -203,18 +221,6 @@ ModuleMap::findModuleForHeader(const FileEntry *File, return Result; } - // If we've found a builtin header within Clang's builtin include directory, - // load all of the module maps to see if it will get associated with a - // specific module (e.g., in /usr/include). - if (File->getDir() == BuiltinIncludeDir && - isBuiltinHeader(llvm::sys::path::filename(File->getName()))) { - HeaderInfo.loadTopLevelSystemModules(); - - // Check again. - if (Headers.find(File) != Headers.end()) - return findModuleForHeader(File, RequestingModule); - } - const DirectoryEntry *Dir = File->getDir(); SmallVector<const DirectoryEntry *, 2> SkippedDirs; |
