[PATCH] D93260: Frontend: Simplify handling of non-seeking streams in CompilerInstance, NFC
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG2f721476d10c: Frontend: Simplify handling of non-seeking streams in CompilerInstance, NFC (authored by dexonsmith). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93260/new/ https://reviews.llvm.org/D93260 Files: clang/include/clang/Frontend/CompilerInstance.h clang/lib/Frontend/CompilerInstance.cpp llvm/include/llvm/Support/raw_ostream.h llvm/lib/Support/raw_ostream.cpp Index: llvm/lib/Support/raw_ostream.cpp === --- llvm/lib/Support/raw_ostream.cpp +++ llvm/lib/Support/raw_ostream.cpp @@ -987,3 +987,5 @@ void raw_pwrite_stream::anchor() {} void buffer_ostream::anchor() {} + +void buffer_unique_ostream::anchor() {} Index: llvm/include/llvm/Support/raw_ostream.h === --- llvm/include/llvm/Support/raw_ostream.h +++ 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 Index: clang/lib/Frontend/CompilerInstance.cpp === --- clang/lib/Frontend/CompilerInstance.cpp +++ 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 Index: clang/include/clang/Frontend/CompilerInstance.h === --- clang/include/clang/Frontend/CompilerInstance.h +++ 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; Index: llvm/lib/Support/raw_ostream.cpp === --- llvm/lib/Support/raw_ostream.cpp +++ llvm/lib/Support/raw_ostream.cpp @@ -987,3 +987,5 @@ void raw_pwrite_stream::anchor() {} void buffer_ostream::anchor() {} + +void buffer_unique_ostream::anchor() {} Index: llvm/include/llvm/Support/raw_ostream.h === --- llvm/include/llvm/Support/raw_ostream.h +++ 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 Index: clang/lib/Frontend/CompilerInstance.cpp === --- clang/lib/Frontend/CompilerInstance.cpp +++ 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 Index: clang/include/clang/Frontend/CompilerInstance.h === --- clang/include/clang/Frontend/CompilerInstance.h +++ 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; ___ cfe-commits mailing list cfe-commits@lists.llvm.org
[PATCH] D93260: Frontend: Simplify handling of non-seeking streams in CompilerInstance, NFC
erik.pilkington accepted this revision. erik.pilkington added a comment. This revision is now accepted and ready to land. LGTM Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93260/new/ https://reviews.llvm.org/D93260 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D93260: Frontend: Simplify handling of non-seeking streams in CompilerInstance, NFC
dexonsmith added a comment. Ping! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93260/new/ https://reviews.llvm.org/D93260 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D93260: Frontend: Simplify handling of non-seeking streams in CompilerInstance, NFC
dexonsmith created this revision. dexonsmith added a reviewer: erik.pilkington. Herald added subscribers: ributzka, hiraditya. dexonsmith requested review of this revision. Herald added projects: clang, LLVM. Herald added a subscriber: llvm-commits. Add a new `raw_pwrite_ostream` variant, `buffer_unique_ostream`, which is like `buffer_ostream` but with unique ownership of the stream it's wrapping. Use this in CompilerInstance to simplify the ownership of non-seeking output streams, avoiding logic sprawled around to deal with them specially. This also simplifies future work to encapsulate output files in a different class. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D93260 Files: clang/include/clang/Frontend/CompilerInstance.h clang/lib/Frontend/CompilerInstance.cpp llvm/include/llvm/Support/raw_ostream.h llvm/lib/Support/raw_ostream.cpp Index: llvm/lib/Support/raw_ostream.cpp === --- llvm/lib/Support/raw_ostream.cpp +++ llvm/lib/Support/raw_ostream.cpp @@ -987,3 +987,5 @@ void raw_pwrite_stream::anchor() {} void buffer_ostream::anchor() {} + +void buffer_unique_ostream::anchor() {} Index: llvm/include/llvm/Support/raw_ostream.h === --- llvm/include/llvm/Support/raw_ostream.h +++ 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 Index: clang/lib/Frontend/CompilerInstance.cpp === --- clang/lib/Frontend/CompilerInstance.cpp +++ clang/lib/Frontend/CompilerInstance.cpp @@ -672,7 +672,6 @@ llvm::sys::fs::remove(Module.second); BuiltModules.clear(); } - NonSeekStream.reset(); } std::unique_ptr @@ -803,10 +802,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 Index: clang/include/clang/Frontend/CompilerInstance.h === --- clang/include/clang/Frontend/CompilerInstance.h +++ clang/include/clang/Frontend/CompilerInstance.h @@ -171,11 +171,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; Index: llvm/lib/Support/raw_ostream.cpp === --- llvm/lib/Support/raw_ostream.cpp +++ llvm/lib/Support/raw_ostream.cpp @@ -987,3 +987,5 @@ void raw_pwrite_stream::anchor() {} void buffer_ostream::anchor() {} + +void buffer_unique_ostream::anchor() {} Index: llvm/include/llvm/Support/raw_ostream.h === --- llvm/include/llvm/Support/raw_ostream.h +++ 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 Index: clang/lib/Frontend/CompilerInstance.cpp === --- clang/lib/Frontend/CompilerInstance.cpp +++ clang/lib/Frontend/CompilerInstance.cpp @@ -672,7 +672,6 @@ llvm::sys::fs::remove(Module.second); BuiltModules.clear(); } - NonSeekStream.reset(); } std::unique_ptr @@ -803,10 +802,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 Index: clang/include/clang/Frontend/CompilerInstance.h === --- clang/include/clang/Frontend/CompilerInstance.h +++ clang/include/clang/Frontend/CompilerInstance.h @@ -171,11 +171,6 @@ } }; - /// If the output doesn't support seeking (terminal, pipe). we switch - /// the