[Tooling] Don't mmap the JSONCompilationDatabase, it's not correct for long-lived...
authorSam McCall <sam.mccall@gmail.com>
Tue, 7 May 2019 09:05:15 +0000 (09:05 +0000)
committerSam McCall <sam.mccall@gmail.com>
Tue, 7 May 2019 09:05:15 +0000 (09:05 +0000)
Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 360122

clang/lib/Tooling/JSONCompilationDatabase.cpp

index 3414f7d..0ee9d17 100644 (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;