[llvm] r340634 - [Support] Allow discarding a FileOutputBuffer without removing the memory mapping

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 24 11:36:22 PDT 2018


Author: mstorsjo
Date: Fri Aug 24 11:36:22 2018
New Revision: 340634

URL: http://llvm.org/viewvc/llvm-project?rev=340634&view=rev
Log:
[Support] Allow discarding a FileOutputBuffer without removing the memory mapping

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

Modified:
    llvm/trunk/include/llvm/Support/FileOutputBuffer.h
    llvm/trunk/lib/Support/FileOutputBuffer.cpp

Modified: llvm/trunk/include/llvm/Support/FileOutputBuffer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileOutputBuffer.h?rev=340634&r1=340633&r2=340634&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileOutputBuffer.h (original)
+++ llvm/trunk/include/llvm/Support/FileOutputBuffer.h Fri Aug 24 11:36:22 2018
@@ -76,6 +76,10 @@ public:
   /// deallocates the buffer and the target file is never written.
   virtual ~FileOutputBuffer() {}
 
+  /// This removes the temporary file (unless it already was committed)
+  /// but keeps the memory mapping alive.
+  virtual void discard() {}
+
 protected:
   FileOutputBuffer(StringRef Path) : FinalPath(Path) {}
 

Modified: llvm/trunk/lib/Support/FileOutputBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FileOutputBuffer.cpp?rev=340634&r1=340633&r2=340634&view=diff
==============================================================================
--- llvm/trunk/lib/Support/FileOutputBuffer.cpp (original)
+++ llvm/trunk/lib/Support/FileOutputBuffer.cpp Fri Aug 24 11:36:22 2018
@@ -61,6 +61,12 @@ public:
     consumeError(Temp.discard());
   }
 
+  void discard() override {
+    // Delete the temp file if it still was open, but keeping the mapping
+    // active.
+    consumeError(Temp.discard());
+  }
+
 private:
   std::unique_ptr<fs::mapped_file_region> Buffer;
   fs::TempFile Temp;




More information about the llvm-commits mailing list