From 73be1ac6c1ba766af280ddadedde0306a9decd79 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Tue, 7 May 2019 09:05:15 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360122 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Tooling/JSONCompilationDatabase.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Tooling/JSONCompilationDatabase.cpp b/lib/Tooling/JSONCompilationDatabase.cpp index 3414f7db58..0ee9d174b4 100644 --- a/lib/Tooling/JSONCompilationDatabase.cpp +++ b/lib/Tooling/JSONCompilationDatabase.cpp @@ -190,8 +190,11 @@ std::unique_ptr 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> 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; -- 2.50.1