OSDN Git Service

Update aosp/master LLVM for rebase to r239765
[android-x86/external-llvm.git] / include / llvm / Support / raw_ostream.h
index 338f0f4..b593171 100644 (file)
@@ -317,10 +317,21 @@ private:
 /// pwrite operation. This is usefull for code that can mostly stream out data,
 /// but needs to patch in a header that needs to know the output size.
 class raw_pwrite_stream : public raw_ostream {
+  virtual void pwrite_impl(const char *Ptr, size_t Size, uint64_t Offset) = 0;
+
 public:
   explicit raw_pwrite_stream(bool Unbuffered = false)
       : raw_ostream(Unbuffered) {}
-  virtual void pwrite(const char *Ptr, size_t Size, uint64_t Offset) = 0;
+  void pwrite(const char *Ptr, size_t Size, uint64_t Offset) {
+#ifndef NDBEBUG
+    uint64_t Pos = tell();
+    // /dev/null always reports a pos of 0, so we cannot perform this check
+    // in that case.
+    if (Pos)
+      assert(Size + Offset <= Pos && "We don't support extending the stream");
+#endif
+    pwrite_impl(Ptr, Size, Offset);
+  }
 };
 
 //===----------------------------------------------------------------------===//
@@ -348,6 +359,8 @@ class raw_fd_ostream : public raw_pwrite_stream {
   /// See raw_ostream::write_impl.
   void write_impl(const char *Ptr, size_t Size) override;
 
+  void pwrite_impl(const char *Ptr, size_t Size, uint64_t Offset) override;
+
   /// Return the current position within the stream, not counting the bytes
   /// currently in the buffer.
   uint64_t current_pos() const override { return pos; }
@@ -388,8 +401,6 @@ public:
   /// to the offset specified from the beginning of the file.
   uint64_t seek(uint64_t off);
 
-  void pwrite(const char *Ptr, size_t Size, uint64_t Offset) override;
-
   /// Set the stream to attempt to use atomic writes for individual output
   /// routines where possible.
   ///
@@ -478,6 +489,8 @@ class raw_svector_ostream : public raw_pwrite_stream {
   /// See raw_ostream::write_impl.
   void write_impl(const char *Ptr, size_t Size) override;
 
+  void pwrite_impl(const char *Ptr, size_t Size, uint64_t Offset) override;
+
   /// Return the current position within the stream, not counting the bytes
   /// currently in the buffer.
   uint64_t current_pos() const override;
@@ -495,7 +508,6 @@ public:
   explicit raw_svector_ostream(SmallVectorImpl<char> &O);
   ~raw_svector_ostream() override;
 
-  void pwrite(const char *Ptr, size_t Size, uint64_t Offset) override;
 
   /// This is called when the SmallVector we're appending to is changed outside
   /// of the raw_svector_ostream's control.  It is only safe to do this if the
@@ -511,6 +523,7 @@ public:
 class raw_null_ostream : public raw_pwrite_stream {
   /// See raw_ostream::write_impl.
   void write_impl(const char *Ptr, size_t size) override;
+  void pwrite_impl(const char *Ptr, size_t Size, uint64_t Offset) override;
 
   /// Return the current position within the stream, not counting the bytes
   /// currently in the buffer.
@@ -519,7 +532,6 @@ class raw_null_ostream : public raw_pwrite_stream {
 public:
   explicit raw_null_ostream() {}
   ~raw_null_ostream() override;
-  void pwrite(const char *Ptr, size_t Size, uint64_t Offset) override;
 };
 
 class buffer_ostream : public raw_svector_ostream {