summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/ModuleMap.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-01-06 17:19:32 +0000
committerDouglas Gregor <dgregor@apple.com>2012-01-06 17:19:32 +0000
commit224d8a74ae4087519f07479bb23de4a3ae53e24f (patch)
treef52f7d1f1c63d7f756f2920948ee6fc8090cb688 /clang/lib/Lex/ModuleMap.cpp
parentdc90f07b902fe9c71f4c72e8efe951d32f5c0d6d (diff)
downloadbcm5719-llvm-224d8a74ae4087519f07479bb23de4a3ae53e24f.tar.gz
bcm5719-llvm-224d8a74ae4087519f07479bb23de4a3ae53e24f.zip
When inferring a submodule ID during module creation, look up the
include stack to find the first file that is known to be part of the module. This copes with situations where the module map doesn't completely specify all of the headers that are involved in the module, which can come up when there are very strange #include_next chains (e.g., with weird compiler/stdlib headers like stdarg.h or float.h). llvm-svn: 147662
Diffstat (limited to 'clang/lib/Lex/ModuleMap.cpp')
-rw-r--r--clang/lib/Lex/ModuleMap.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 6c13938c209..55fa50809a1 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -426,12 +426,23 @@ Module *ModuleMap::inferModuleFromLocation(FullSourceLoc Loc) {
const SourceManager &SrcMgr = Loc.getManager();
FileID ExpansionFileID = ExpansionLoc.getFileID();
- const FileEntry *ExpansionFile = SrcMgr.getFileEntryForID(ExpansionFileID);
- if (!ExpansionFile)
- return 0;
- // Find the module that owns this header.
- return findModuleForHeader(ExpansionFile);
+ while (const FileEntry *ExpansionFile
+ = SrcMgr.getFileEntryForID(ExpansionFileID)) {
+ // Find the module that owns this header (if any).
+ if (Module *Mod = findModuleForHeader(ExpansionFile))
+ return Mod;
+
+ // No module owns this header, so look up the inclusion chain to see if
+ // any included header has an associated module.
+ SourceLocation IncludeLoc = SrcMgr.getIncludeLoc(ExpansionFileID);
+ if (IncludeLoc.isInvalid())
+ return 0;
+
+ ExpansionFileID = SrcMgr.getFileID(IncludeLoc);
+ }
+
+ return 0;
}
//----------------------------------------------------------------------------//
OpenPOWER on IntegriCloud