diff options
-rw-r--r-- | lib/Lex/ModuleMap.cpp | 21 | ||||
-rw-r--r-- | test/Modules/Inputs/def-include.h | 13 | ||||
-rw-r--r-- | test/Modules/Inputs/def.h | 5 |
3 files changed, 30 insertions, 9 deletions
diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp index 6c13938c20..55fa50809a 100644 --- a/lib/Lex/ModuleMap.cpp +++ b/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; } //----------------------------------------------------------------------------// diff --git a/test/Modules/Inputs/def-include.h b/test/Modules/Inputs/def-include.h new file mode 100644 index 0000000000..9e0e575e20 --- /dev/null +++ b/test/Modules/Inputs/def-include.h @@ -0,0 +1,13 @@ + + + + + + + + + + +struct B { + int b1; +}; diff --git a/test/Modules/Inputs/def.h b/test/Modules/Inputs/def.h index 7c1a99ef7e..6d06b08125 100644 --- a/test/Modules/Inputs/def.h +++ b/test/Modules/Inputs/def.h @@ -1,4 +1,4 @@ - +#include "def-include.h" @@ -8,7 +8,4 @@ } @end -struct B { - int b1; -}; |