Author: Haojian Wu Date: 2023-07-18T13:21:23+02:00 New Revision: be861b64d94198230d8f9889b17280e3cd215a0a
URL: https://github.com/llvm/llvm-project/commit/be861b64d94198230d8f9889b17280e3cd215a0a DIFF: https://github.com/llvm/llvm-project/commit/be861b64d94198230d8f9889b17280e3cd215a0a.diff LOG: [include-cleaner] Avoid a caching issue when running --edit mode on multiple files. Snapshot all analysing files before running the tool, this makes sure that we analyse all files statelessly and avoid the FileManager caching issue when running `-edit` on multiple files. Differential Revision: https://reviews.llvm.org/D155195 Added: Modified: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp index ae4d1e97414415..193fdaeeb5e4c8 100644 --- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp +++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Regex.h" #include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" @@ -270,12 +271,24 @@ int main(int argc, const char **argv) { } } } + + clang::tooling::ClangTool Tool(OptionsParser->getCompilations(), + OptionsParser->getSourcePathList()); + std::vector<std::unique_ptr<llvm::MemoryBuffer>> Buffers; + for (const auto &File : OptionsParser->getSourcePathList()) { + auto Content = llvm::MemoryBuffer::getFile(File); + if (!Content) { + llvm::errs() << "Error: can't read file '" << File + << "': " << Content.getError().message() << "\n"; + return 1; + } + Buffers.push_back(std::move(Content.get())); + Tool.mapVirtualFile(File, Buffers.back()->getBuffer()); + } + auto HeaderFilter = headerFilter(); if (!HeaderFilter) return 1; // error already reported. ActionFactory Factory(HeaderFilter); - return clang::tooling::ClangTool(OptionsParser->getCompilations(), - OptionsParser->getSourcePathList()) - .run(&Factory) || - Errors != 0; + return Tool.run(&Factory) || Errors != 0; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits