r360122 - [Tooling] Don't mmap the JSONCompilationDatabase, it's not correct for long-lived processes.
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Tue May 7 02:05:15 PDT 2019
Author: sammccall
Date: Tue May 7 02:05:15 2019
New Revision: 360122
URL: http://llvm.org/viewvc/llvm-project?rev=360122&view=rev
Log:
[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
Modified:
cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
Modified: cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp?rev=360122&r1=360121&r2=360122&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp Tue May 7 02:05:15 2019
@@ -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;
More information about the cfe-commits
mailing list