[Tooling] Don't mmap the JSONCompilationDatabase, it's not correct for long-lived processes.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61631

llvm-svn: 360122
This commit is contained in:
Sam McCall 2019-05-07 09:05:15 +00:00
parent b9ec3e9370
commit fdbb61856e
1 changed files with 4 additions and 1 deletions

View File

@ -190,8 +190,11 @@ std::unique_ptr<JSONCompilationDatabase>
JSONCompilationDatabase::loadFromFile(StringRef FilePath,
std::string &ErrorMessage,
JSONCommandLineSyntax Syntax) {
// Don't mmap: if we're a long-lived process, the build system may overwrite.
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> DatabaseBuffer =
llvm::MemoryBuffer::getFile(FilePath);
llvm::MemoryBuffer::getFile(FilePath, /*FileSize=*/-1,
/*RequiresNullTerminator=*/true,
/*IsVolatile=*/true);
if (std::error_code Result = DatabaseBuffer.getError()) {
ErrorMessage = "Error while opening JSON database: " + Result.message();
return nullptr;