[Support] Allow discarding a FileOutputBuffer without removing the memory mapping
authorMartin Storsjo <martin@martin.st>
Fri, 24 Aug 2018 18:36:22 +0000 (18:36 +0000)
committerMartin Storsjo <martin@martin.st>
Fri, 24 Aug 2018 18:36:22 +0000 (18:36 +0000)
Differential Revision: https://reviews.llvm.org/D51095

llvm-svn: 340634

llvm/include/llvm/Support/FileOutputBuffer.h
llvm/lib/Support/FileOutputBuffer.cpp

index ee8cbb7..68226ca 100644 (file)
@@ -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) {}
 
index 1214b5a..b822312 100644 (file)
@@ -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;