[PATCH] D31406: [clang-tidy] Reuse FileID in getLocation
Chih-Hung Hsieh via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 27 14:43:55 PDT 2017
chh created this revision.
http://bugs.llvm.org/show_bug.cgi?id=32402
One FileID per warning will increase and overflow NextLocalOffset
when input file is large with many warnings.
Reusing FileID avoids this problem.
Repository:
rL LLVM
https://reviews.llvm.org/D31406
Files:
clang-tidy/ClangTidy.cpp
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 <algorithm>
+#include <string>
+#include <unordered_map>
#include <utility>
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<std::string, FileID> Path2FileID;
FileManager Files;
LangOptions LangOpts; // FIXME: use langopts from each original file
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31406.93179.patch
Type: text/x-patch
Size: 1266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170327/c31facf0/attachment.bin>
More information about the llvm-commits
mailing list