From add25ee3712645a4584b14d031e4cb73531d634d Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 27 Mar 2019 08:19:36 +0000 Subject: [PATCH] [llvm-dwarfdump] Simplify -o handling ToolOutputFile handles '-' so no need to specialize here. Also, we neither reassign the variable nor pass it around, thus no need to use std::unique_ptr. exit(1) -> return 1; to call the destructor of raw_fd_stream git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357051 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 4580688811b..22535e8a3d1 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -159,7 +159,7 @@ static opt Lookup("lookup", "available file, function, block and line table details."), value_desc("address"), cat(DwarfDumpCategory)); static opt - OutputFilename("out-file", cl::init(""), + OutputFilename("out-file", cl::init("-"), cl::desc("Redirect output to the specified file."), cl::value_desc("filename")); static alias OutputFilenameAlias("o", desc("Alias for -out-file."), @@ -586,17 +586,12 @@ int main(int argc, char **argv) { return 0; } - std::unique_ptr OutputFile; - if (!OutputFilename.empty()) { - std::error_code EC; - OutputFile = llvm::make_unique(OutputFilename, EC, - sys::fs::F_None); - error("Unable to open output file" + OutputFilename, EC); - // Don't remove output file if we exit with an error. - OutputFile->keep(); - } + std::error_code EC; + ToolOutputFile OutputFile(OutputFilename, EC, sys::fs::OF_None); + error("Unable to open output file" + OutputFilename, EC); + // Don't remove output file if we exit with an error. + OutputFile.keep(); - raw_ostream &OS = OutputFile ? OutputFile->os() : outs(); bool OffsetRequested = false; // Defaults to dumping all sections, unless brief mode is specified in which @@ -640,15 +635,15 @@ int main(int argc, char **argv) { if (Verify) { // If we encountered errors during verify, exit with a non-zero exit status. if (!all_of(Objects, [&](std::string Object) { - return handleFile(Object, verifyObjectFile, OS); + return handleFile(Object, verifyObjectFile, OutputFile.os()); })) - exit(1); + return 1; } else if (Statistics) for (auto Object : Objects) - handleFile(Object, collectStatsForObjectFile, OS); + handleFile(Object, collectStatsForObjectFile, OutputFile.os()); else for (auto Object : Objects) - handleFile(Object, dumpObjectFile, OS); + handleFile(Object, dumpObjectFile, OutputFile.os()); return EXIT_SUCCESS; } -- 2.11.0