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

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 7 01:27:55 PDT 2019


sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D61631

Files:
  lib/Tooling/JSONCompilationDatabase.cpp


Index: lib/Tooling/JSONCompilationDatabase.cpp
===================================================================
--- lib/Tooling/JSONCompilationDatabase.cpp
+++ lib/Tooling/JSONCompilationDatabase.cpp
@@ -190,8 +190,11 @@
 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61631.198408.patch
Type: text/x-patch
Size: 965 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190507/89283be8/attachment.bin>


More information about the cfe-commits mailing list