Index: include/llvm/Support/circular_raw_ostream.h =================================================================== --- include/llvm/Support/circular_raw_ostream.h +++ include/llvm/Support/circular_raw_ostream.h @@ -108,7 +108,7 @@ /// circular_raw_ostream(raw_ostream &Stream, const char *Header, size_t BuffSize = 0, bool Owns = REFERENCE_ONLY) - : raw_ostream(/*unbuffered*/ true), TheStream(nullptr), + : raw_ostream(StreamMode::Unbuffered), TheStream(nullptr), OwnsStream(Owns), BufferSize(BuffSize), BufferArray(nullptr), Filled(false), Banner(Header) { if (BufferSize != 0) Index: include/llvm/Support/raw_ostream.h =================================================================== --- include/llvm/Support/raw_ostream.h +++ include/llvm/Support/raw_ostream.h @@ -31,6 +31,8 @@ } } +enum class StreamMode : bool { Buffered, Unbuffered }; + /// This class implements an extremely fast bulk output stream that can *only* /// output to a stream. It does not support seeking, reopening, rewinding, line /// buffered disciplines etc. It is a simple buffer that outputs @@ -60,11 +62,8 @@ /// this buffer. char *OutBufStart, *OutBufEnd, *OutBufCur; - enum BufferKind { - Unbuffered = 0, - InternalBuffer, - ExternalBuffer - } BufferMode; + /// Specify the current state of the stream. + enum BufferKind { Unbuffered, InternalBuffer, ExternalBuffer } BufferMode; public: // color order matches ANSI escape sequence, don't change @@ -80,8 +79,8 @@ SAVEDCOLOR }; - explicit raw_ostream(bool unbuffered = false) - : BufferMode(unbuffered ? Unbuffered : InternalBuffer) { + explicit raw_ostream(StreamMode Mode = StreamMode::Buffered) + : BufferMode(Mode == StreamMode::Buffered ? InternalBuffer : Unbuffered) { // Start out ready to flush. OutBufStart = OutBufEnd = OutBufCur = nullptr; } @@ -320,8 +319,8 @@ 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) {} + explicit raw_pwrite_stream(StreamMode Mode = StreamMode::Buffered) + : raw_ostream(Mode) {} void pwrite(const char *Ptr, size_t Size, uint64_t Offset) { #ifndef NDBEBUG uint64_t Pos = tell(); @@ -387,7 +386,8 @@ /// FD is the file descriptor that this writes to. If ShouldClose is true, /// this closes the file when the stream is destroyed. - raw_fd_ostream(int fd, bool shouldClose, bool unbuffered=false); + raw_fd_ostream(int fd, bool shouldClose, + StreamMode Mode = StreamMode::Buffered); ~raw_fd_ostream() override; Index: lib/Bitcode/Writer/BitWriter.cpp =================================================================== --- lib/Bitcode/Writer/BitWriter.cpp +++ lib/Bitcode/Writer/BitWriter.cpp @@ -30,7 +30,8 @@ int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose, int Unbuffered) { - raw_fd_ostream OS(FD, ShouldClose, Unbuffered); + StreamMode Mode = Unbuffered ? StreamMode::Unbuffered : StreamMode::Buffered; + raw_fd_ostream OS(FD, ShouldClose, Mode); WriteBitcodeToFile(unwrap(M), OS); return 0; Index: lib/Support/raw_ostream.cpp =================================================================== --- lib/Support/raw_ostream.cpp +++ lib/Support/raw_ostream.cpp @@ -515,9 +515,9 @@ /// FD is the file descriptor that this writes to. If ShouldClose is true, this /// closes the file when the stream is destroyed. -raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered) - : raw_pwrite_stream(unbuffered), FD(fd), ShouldClose(shouldClose), - Error(false), UseAtomicWrites(false) { +raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, StreamMode Mode) + : raw_pwrite_stream(Mode), FD(fd), ShouldClose(shouldClose), Error(false), + UseAtomicWrites(false) { if (FD < 0 ) { ShouldClose = false; return; @@ -728,7 +728,7 @@ /// Use it like: errs() << "foo" << "bar"; raw_ostream &llvm::errs() { // Set standard error to be unbuffered by default. - static raw_fd_ostream S(STDERR_FILENO, false, true); + static raw_fd_ostream S(STDERR_FILENO, false, StreamMode::Unbuffered); return S; } Index: unittests/Support/MemoryBufferTest.cpp =================================================================== --- unittests/Support/MemoryBufferTest.cpp +++ unittests/Support/MemoryBufferTest.cpp @@ -71,7 +71,7 @@ SmallString<64> TestPath; sys::fs::createTemporaryFile("MemoryBufferTest_NullTerminator4K", "temp", TestFD, TestPath); - raw_fd_ostream OF(TestFD, true, /*unbuffered=*/true); + raw_fd_ostream OF(TestFD, true, StreamMode::Unbuffered); for (unsigned i = 0; i < 4096 / 16; ++i) { OF << "0123456789abcdef"; } @@ -136,7 +136,8 @@ // OF is responsible for closing the file; If the file is not // reopened, it will be unbuffered so that the results are // immediately visible through the fd. - raw_fd_ostream OF(TestFD, true, !Reopen); + raw_fd_ostream OF(TestFD, true, + Reopen ? StreamMode::Buffered : StreamMode::Unbuffered); for (int i = 0; i < 60000; ++i) { OF << "0123456789"; } @@ -175,7 +176,7 @@ int FD; SmallString<64> TestPath; sys::fs::createTemporaryFile("MemoryBufferTest_Slice", "temp", FD, TestPath); - raw_fd_ostream OF(FD, true, /*unbuffered=*/true); + raw_fd_ostream OF(FD, true, StreamMode::Unbuffered); for (unsigned i = 0; i < 0x2000 / 8; ++i) { OF << "12345678"; } Index: unittests/Support/SpecialCaseListTest.cpp =================================================================== --- unittests/Support/SpecialCaseListTest.cpp +++ unittests/Support/SpecialCaseListTest.cpp @@ -36,7 +36,7 @@ int FD; SmallString<64> Path; sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path); - raw_fd_ostream OF(FD, true, true); + raw_fd_ostream OF(FD, true, StreamMode::Unbuffered); OF << Contents; OF.close(); return Path.str();