[all-commits] [llvm/llvm-project] 48cd9d: [Support] Use outs() in ToolOutputFile

Pavel Labath via All-commits all-commits at lists.llvm.org
Thu Jun 4 05:56:57 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 48cd9d9dd86c2c37e6c47cbb23c06d36a1870b83
      https://github.com/llvm/llvm-project/commit/48cd9d9dd86c2c37e6c47cbb23c06d36a1870b83
  Author: Pavel Labath <pavel at labath.sk>
  Date:   2020-06-04 (Thu, 04 Jun 2020)

  Changed paths:
    M llvm/include/llvm/Support/ToolOutputFile.h
    M llvm/include/llvm/Support/raw_ostream.h
    M llvm/lib/Support/ToolOutputFile.cpp
    M llvm/lib/Support/raw_ostream.cpp
    M llvm/unittests/Support/CMakeLists.txt
    A llvm/unittests/Support/ToolOutputFileTest.cpp
    M mlir/include/mlir/Pass/PassManager.h

  Log Message:
  -----------
  [Support] Use outs() in ToolOutputFile

Summary:
If the output filename was specified as "-", the ToolOutputFile class
would create a brand new raw_ostream object referring to the stdout.
This patch changes it to reuse the llvm::outs() singleton.

At the moment, this change should be "NFC", but it does enable other
enhancements, like the automatic stdout/stderr synchronization as
discussed on D80803.

I've checked the history, and I did not find any indication that this
class *has* to use a brand new stream object instead of outs() --
indeed, it is special-casing "-" in a number of places already, so this
change fits the pattern pretty well. I suspect the main reason for the
current state of affairs is that the class was originally introduced
(r111595, in 2010) as a raw_fd_ostream subclass, which made any other
solution impossible.

Another potential benefit of this patch is that it makes it possible to
move the raw_ostream class out of the business of special-casing "-" for
stdout handling. That state of affairs does not seem appropriate because
"-" is a valid filename (albeit hard to access with a lot of command
line tools) on most systems. Handling "-" in ToolOutputFile seems more
appropriate.

To make this possible, this patch changes the return type of
llvm::outs() and errs() to raw_fd_ostream&. Previously the functions
were constructing objects of that type, but returning a generic
raw_ostream reference. This makes it possible for new ToolOutputFile and
other code to use raw_fd_ostream methods like error() on the outs()
object. This does not seem like a bad thing (since stdout is a file
descriptor which can be redirected to anywhere, it makes sense to ask it
whether the writing was successful or if it supports seeking), and
indeed a lot of code was already depending on this fact via the
ToolOutputFile "back door".

Reviewers: dblaikie, JDevlieghere, MaskRay, jhenderson

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D81078




More information about the All-commits mailing list