[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

Ivan Donchevskii via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 28 00:28:24 PST 2018


yvvan created this revision.
yvvan added reviewers: ilya-biryukov, Dmitry.Kozhevnikov.

There are reported cases of non-system files being locked by libclang on Windows (and likely by other clients as well). I tried to solve that with https://reviews.llvm.org/D47460 but it might be not the only issue.
IsVolatile flag is there only for performance reasons so this change should not break any code


https://reviews.llvm.org/D54995

Files:
  include/llvm/Support/MemoryBuffer.h
  tools/clang/include/clang/Basic/FileManager.h
  tools/clang/include/clang/Basic/VirtualFileSystem.h
  tools/clang/lib/Basic/VirtualFileSystem.cpp


Index: tools/clang/lib/Basic/VirtualFileSystem.cpp
===================================================================
--- tools/clang/lib/Basic/VirtualFileSystem.cpp
+++ tools/clang/lib/Basic/VirtualFileSystem.cpp
@@ -193,7 +193,7 @@
   ErrorOr<std::unique_ptr<MemoryBuffer>> getBuffer(const Twine &Name,
                                                    int64_t FileSize,
                                                    bool RequiresNullTerminator,
-                                                   bool IsVolatile) override;
+                                                   bool IsVolatile = true) override;
   std::error_code close() override;
 };
 
Index: tools/clang/include/clang/Basic/VirtualFileSystem.h
===================================================================
--- tools/clang/include/clang/Basic/VirtualFileSystem.h
+++ tools/clang/include/clang/Basic/VirtualFileSystem.h
@@ -120,7 +120,7 @@
   /// Get the contents of the file as a \p MemoryBuffer.
   virtual llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
   getBuffer(const Twine &Name, int64_t FileSize = -1,
-            bool RequiresNullTerminator = true, bool IsVolatile = false) = 0;
+            bool RequiresNullTerminator = true, bool IsVolatile = true) = 0;
 
   /// Closes the file.
   virtual std::error_code close() = 0;
@@ -234,7 +234,7 @@
   /// closes the file.
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
   getBufferForFile(const Twine &Name, int64_t FileSize = -1,
-                   bool RequiresNullTerminator = true, bool IsVolatile = false);
+                   bool RequiresNullTerminator = true, bool IsVolatile = true);
 
   /// Get a directory_iterator for \p Dir.
   /// \note The 'end' iterator is directory_iterator().
Index: tools/clang/include/clang/Basic/FileManager.h
===================================================================
--- tools/clang/include/clang/Basic/FileManager.h
+++ tools/clang/include/clang/Basic/FileManager.h
@@ -236,10 +236,10 @@
   /// Open the specified file as a MemoryBuffer, returning a new
   /// MemoryBuffer if successful, otherwise returning null.
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
-  getBufferForFile(const FileEntry *Entry, bool isVolatile = false,
+  getBufferForFile(const FileEntry *Entry, bool isVolatile = true,
                    bool ShouldCloseOpenFile = true);
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
-  getBufferForFile(StringRef Filename, bool isVolatile = false);
+  getBufferForFile(StringRef Filename, bool isVolatile = true);
 
   /// Get the 'stat' information for the given \p Path.
   ///
Index: include/llvm/Support/MemoryBuffer.h
===================================================================
--- include/llvm/Support/MemoryBuffer.h
+++ include/llvm/Support/MemoryBuffer.h
@@ -79,7 +79,7 @@
   /// while the user is editing/updating the file or if the file is on an NFS.
   static ErrorOr<std::unique_ptr<MemoryBuffer>>
   getFile(const Twine &Filename, int64_t FileSize = -1,
-          bool RequiresNullTerminator = true, bool IsVolatile = false);
+          bool RequiresNullTerminator = true, bool IsVolatile = true);
 
   /// Read all of the specified file into a MemoryBuffer as a stream
   /// (i.e. until EOF reached). This is useful for special files that
@@ -92,7 +92,7 @@
   /// Since this is in the middle of a file, the buffer is not null terminated.
   static ErrorOr<std::unique_ptr<MemoryBuffer>>
   getOpenFileSlice(int FD, const Twine &Filename, uint64_t MapSize,
-                   int64_t Offset, bool IsVolatile = false);
+                   int64_t Offset, bool IsVolatile = true);
 
   /// Given an already-open file descriptor, read the file and return a
   /// MemoryBuffer.
@@ -102,7 +102,7 @@
   /// while the user is editing/updating the file or if the file is on an NFS.
   static ErrorOr<std::unique_ptr<MemoryBuffer>>
   getOpenFile(int FD, const Twine &Filename, uint64_t FileSize,
-              bool RequiresNullTerminator = true, bool IsVolatile = false);
+              bool RequiresNullTerminator = true, bool IsVolatile = true);
 
   /// Open the specified memory range as a MemoryBuffer. Note that InputData
   /// must be null terminated if RequiresNullTerminator is true.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54995.175633.patch
Type: text/x-patch
Size: 4246 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181128/45129dce/attachment.bin>


More information about the cfe-commits mailing list