diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -172,11 +172,6 @@ } }; - /// If the output doesn't support seeking (terminal, pipe). we switch - /// the stream to a buffer_ostream. These are the buffer and the original - /// stream. - std::unique_ptr NonSeekStream; - /// The list of active output files. std::list OutputFiles; diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -678,7 +678,6 @@ llvm::sys::fs::remove(Module.second); BuiltModules.clear(); } - NonSeekStream.reset(); } std::unique_ptr @@ -816,10 +815,7 @@ if (!Binary || OS->supportsSeeking()) return std::move(OS); - auto B = std::make_unique(*OS); - assert(!NonSeekStream); - NonSeekStream = std::move(OS); - return std::move(B); + return std::make_unique(std::move(OS)); } // Initialization Utilities diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -687,6 +687,18 @@ ~buffer_ostream() override { OS << str(); } }; +class buffer_unique_ostream : public raw_svector_ostream { + std::unique_ptr OS; + SmallVector Buffer; + + virtual void anchor() override; + +public: + buffer_unique_ostream(std::unique_ptr OS) + : raw_svector_ostream(Buffer), OS(std::move(OS)) {} + ~buffer_unique_ostream() override { *OS << str(); } +}; + } // end namespace llvm #endif // LLVM_SUPPORT_RAW_OSTREAM_H diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -987,3 +987,5 @@ void raw_pwrite_stream::anchor() {} void buffer_ostream::anchor() {} + +void buffer_unique_ostream::anchor() {}