diff options
| author | Reid Kleckner <rnk@google.com> | 2017-08-04 01:39:23 +0000 |
|---|---|---|
| committer | Reid Kleckner <rnk@google.com> | 2017-08-04 01:39:23 +0000 |
| commit | 02aeadcf3d431f35941c628643e919c5aa2169a1 (patch) | |
| tree | 97e54bc66abbceab7bb2195eb22dff5ea3353977 | |
| parent | 696e3847dd5723d94335adf65435dc1de229a3b7 (diff) | |
| download | bcm5719-llvm-02aeadcf3d431f35941c628643e919c5aa2169a1.tar.gz bcm5719-llvm-02aeadcf3d431f35941c628643e919c5aa2169a1.zip | |
[Support] Update comments about stdout, raw_fd_ostream, and outs()
The full story is in the comments:
// Do not attempt to close stdout or stderr. We used to try to maintain the
// property that tools that support writing file to stdout should not also
// write informational output to stdout, but in practice we were never able to
// maintain this invariant. Many features have been added to LLVM and clang
// (-fdump-record-layouts, optimization remarks, etc) that print to stdout, so
// users must simply be aware that mixed output and remarks is a possibility.
NFC, I am just updating comments to reflect reality.
llvm-svn: 310016
| -rw-r--r-- | llvm/include/llvm/Support/raw_ostream.h | 9 | ||||
| -rw-r--r-- | llvm/lib/Support/raw_ostream.cpp | 17 |
2 files changed, 12 insertions, 14 deletions
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h index e644a5bda5e..f5db87b0607 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -388,15 +388,14 @@ public: /// \p Flags allows optional flags to control how the file will be opened. /// /// As a special case, if Filename is "-", then the stream will use - /// STDOUT_FILENO instead of opening a file. Note that it will still consider - /// itself to own the file descriptor. In particular, it will close the - /// file descriptor when it is done (this is necessary to detect - /// output errors). + /// STDOUT_FILENO instead of opening a file. This will not close the stdout + /// descriptor. raw_fd_ostream(StringRef Filename, std::error_code &EC, sys::fs::OpenFlags Flags); /// FD is the file descriptor that this writes to. If ShouldClose is true, - /// this closes the file when the stream is destroyed. + /// this closes the file when the stream is destroyed. If FD is for stdout or + /// stderr, it will not be closed. raw_fd_ostream(int fd, bool shouldClose, bool unbuffered=false); ~raw_fd_ostream() override; diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp index dd58eccee95..6a0f08690e7 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -513,11 +513,13 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered) ShouldClose = false; return; } - // We do not want to close STDOUT as there may have been several uses of it - // such as the case: llc %s -o=- -pass-remarks-output=- -filetype=asm - // which cause multiple closes of STDOUT_FILENO and/or use-after-close of it. - // Using dup() in getFD doesn't work as we end up with original STDOUT_FILENO - // open anyhow. + + // Do not attempt to close stdout or stderr. We used to try to maintain the + // property that tools that support writing file to stdout should not also + // write informational output to stdout, but in practice we were never able to + // maintain this invariant. Many features have been added to LLVM and clang + // (-fdump-record-layouts, optimization remarks, etc) that print to stdout, so + // users must simply be aware that mixed output and remarks is a possibility. if (FD <= STDERR_FILENO) ShouldClose = false; @@ -722,10 +724,7 @@ bool raw_fd_ostream::has_colors() const { /// outs() - This returns a reference to a raw_ostream for standard output. /// Use it like: outs() << "foo" << "bar"; raw_ostream &llvm::outs() { - // Set buffer settings to model stdout behavior. Delete the file descriptor - // when the program exits, forcing error detection. This means that if you - // ever call outs(), you can't open another raw_fd_ostream on stdout, as we'll - // close stdout twice and print an error the second time. + // Set buffer settings to model stdout behavior. std::error_code EC; static raw_fd_ostream S("-", EC, sys::fs::F_None); assert(!EC); |

