Index: clang-tidy/ClangTidy.cpp =================================================================== --- clang-tidy/ClangTidy.cpp +++ clang-tidy/ClangTidy.cpp @@ -42,6 +42,8 @@ #include "llvm/Support/Process.h" #include "llvm/Support/Signals.h" #include +#include +#include #include using namespace clang::ast_matchers; @@ -237,8 +239,13 @@ if (FilePath.empty()) return SourceLocation(); - const FileEntry *File = SourceMgr.getFileManager().getFile(FilePath); - FileID ID = SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User); + std::string Path = FilePath.str(); + if (Path2FileID.find(Path) == Path2FileID.end()) { + const FileEntry *File = SourceMgr.getFileManager().getFile(FilePath); + Path2FileID[Path] = + SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User); + } + FileID ID = Path2FileID[Path]; return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset); } @@ -248,6 +255,7 @@ << Message.Message; } + std::unordered_map Path2FileID; FileManager Files; LangOptions LangOpts; // FIXME: use langopts from each original file IntrusiveRefCntPtr DiagOpts;