When indexing a module file, for the ppIncludedFile callback give
an invalid location if the location points to the synthetic buffer
for the module input.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165592 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp
index 6ea87eb..d2b0ab3 100644
--- a/tools/libclang/Indexing.cpp
+++ b/tools/libclang/Indexing.cpp
@@ -450,14 +450,21 @@
PreprocessingRecord::iterator I, E;
llvm::tie(I, E) = Unit.getLocalPreprocessingEntities();
+ bool isModuleFile = Unit.isModuleFile();
for (; I != E; ++I) {
PreprocessedEntity *PPE = *I;
if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) {
- if (!ID->importedModule())
- IdxCtx.ppIncludedFile(ID->getSourceRange().getBegin(),ID->getFileName(),
+ if (!ID->importedModule()) {
+ SourceLocation Loc = ID->getSourceRange().getBegin();
+ // Modules have synthetic main files as input, give an invalid location
+ // if the location points to such a file.
+ if (isModuleFile && Unit.isInMainFileID(Loc))
+ Loc = SourceLocation();
+ IdxCtx.ppIncludedFile(Loc, ID->getFileName(),
ID->getFile(), ID->getKind() == InclusionDirective::Import,
!ID->wasInQuotes());
+ }
}
}
}