8 changes: 2 additions & 6 deletions llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -533,9 +531,7 @@ static void dumpInput(StringRef File) {
}

int main(int argc, const char *argv[]) {
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y;
InitLLVM X(argc, argv);

// Initialize targets.
llvm::InitializeAllTargetInfos();
Expand Down
6 changes: 2 additions & 4 deletions llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
#include <iostream>
Expand Down Expand Up @@ -81,8 +80,7 @@ static void demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
}

int main(int argc, char **argv) {
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
InitLLVM X(argc, argv);

cl::ParseCommandLineOptions(argc, argv, "llvm symbol undecoration tool\n");

Expand Down
11 changes: 3 additions & 8 deletions llvm/tools/llvm-dis/llvm-dis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@
//
//===----------------------------------------------------------------------===//

#include "llvm/IR/LLVMContext.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/IR/AssemblyAnnotationWriter.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/ToolOutputFile.h"
#include <system_error>
using namespace llvm;
Expand Down Expand Up @@ -162,14 +160,11 @@ static std::unique_ptr<Module> openInputFile(LLVMContext &Context) {
}

int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
InitLLVM X(argc, argv);

ExitOnErr.setBanner(std::string(argv[0]) + ": error: ");

LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
Context.setDiagnosticHandler(
llvm::make_unique<LLVMDisDiagnosticHandler>(argv[0]));
cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
Expand Down
9 changes: 2 additions & 7 deletions llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -510,10 +508,7 @@ static std::vector<std::string> expandBundle(const std::string &InputPath) {
}

int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
InitLLVM X(argc, argv);

llvm::InitializeAllTargetInfos();
llvm::InitializeAllTargetMCs();
Expand Down
9 changes: 2 additions & 7 deletions llvm/tools/llvm-extract/llvm-extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/ToolOutputFile.h"
Expand Down Expand Up @@ -113,12 +111,9 @@ static cl::opt<bool> PreserveAssemblyUseListOrder(
cl::init(false), cl::Hidden);

int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
InitLLVM X(argc, argv);

LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");

// Use lazy loading, since we only care about selected global values.
Expand Down
12 changes: 2 additions & 10 deletions llvm/tools/llvm-jitlistener/llvm-jitlistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -178,16 +176,10 @@ InputFilename(cl::Positional, cl::desc("<input IR file>"),
cl::Required);

int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.

InitLLVM X(argc, argv);
cl::ParseCommandLineOptions(argc, argv, "llvm jit event listener test utility\n");

JitEventListenerTest Test;

Test.ProcessInput(InputFilename);

return 0;
}
10 changes: 2 additions & 8 deletions llvm/tools/llvm-link/llvm-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
#include "llvm/Linker/Linker.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/ToolOutputFile.h"
Expand Down Expand Up @@ -345,16 +343,12 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
}

int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);

InitLLVM X(argc, argv);
ExitOnErr.setBanner(std::string(argv[0]) + ": ");

LLVMContext Context;
Context.setDiagnosticHandler(
llvm::make_unique<LLVMLinkDiagnosticHandler>(), true);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");

if (!DisableDITypeMap)
Expand Down
10 changes: 2 additions & 8 deletions llvm/tools/llvm-lto/llvm-lto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
Expand Down Expand Up @@ -799,11 +797,7 @@ class ThinLTOProcessing {
} // end namespace thinlto

int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);

llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
InitLLVM X(argc, argv);
cl::ParseCommandLineOptions(argc, argv, "llvm LTO linker\n");

if (OptLevel < '0' || OptLevel > '3')
Expand Down
9 changes: 2 additions & 7 deletions llvm/tools/llvm-mc/llvm-mc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
Expand Down Expand Up @@ -294,10 +292,7 @@ static int AssembleInput(const char *ProgName, const Target *TheTarget,
}

int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
InitLLVM X(argc, argv);

// Initialize targets and assembly printers/parsers.
llvm::InitializeAllTargetInfos();
Expand Down
7 changes: 2 additions & 5 deletions llvm/tools/llvm-mca/llvm-mca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
Expand Down Expand Up @@ -276,9 +275,7 @@ class MCStreamerWrapper final : public MCStreamer {
} // end of anonymous namespace

int main(int argc, char **argv) {
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
InitLLVM X(argc, argv);

// Initialize targets and assembly parsers.
llvm::InitializeAllTargetInfos();
Expand Down
18 changes: 4 additions & 14 deletions llvm/tools/llvm-mt/llvm-mt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/Option/Option.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
Expand Down Expand Up @@ -61,8 +62,6 @@ class CvtResOptTable : public opt::OptTable {
public:
CvtResOptTable() : OptTable(InfoTable, true) {}
};

static ExitOnError ExitOnErr;
} // namespace

LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) {
Expand All @@ -86,21 +85,12 @@ void error(Error EC) {
});
}

int main(int argc, const char **argv) {
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);

ExitOnErr.setBanner("llvm-mt: ");

SmallVector<const char *, 256> argv_buf;
SpecificBumpPtrAllocator<char> ArgAllocator;
ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
argv_buf, makeArrayRef(argv, argc), ArgAllocator)));
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
int main(int Argc, const char **Argv) {
InitLLVM X(Argc, Argv);

CvtResOptTable T;
unsigned MAI, MAC;
ArrayRef<const char *> ArgsArr = makeArrayRef(argv + 1, argc);
ArrayRef<const char *> ArgsArr = makeArrayRef(Argv + 1, Argc - 1);
opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);

for (auto *Arg : InputArgs.filtered(OPT_INPUT)) {
Expand Down
9 changes: 2 additions & 7 deletions llvm/tools/llvm-nm/llvm-nm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
Expand Down Expand Up @@ -2016,11 +2015,7 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
}

int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);

llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
InitLLVM X(argc, argv);
cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n");

// llvm-nm only reads binary files.
Expand Down
9 changes: 2 additions & 7 deletions llvm/tools/llvm-objcopy/llvm-objcopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -327,10 +325,7 @@ std::unique_ptr<Reader> CreateReader() {
}

int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
InitLLVM X(argc, argv);
cl::ParseCommandLineOptions(argc, argv, "llvm objcopy utility\n");
ToolName = argv[0];
if (InputFilename.empty()) {
Expand Down
9 changes: 2 additions & 7 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/GraphWriter.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
Expand Down Expand Up @@ -2179,10 +2177,7 @@ static void DumpInput(StringRef file) {
}

int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
InitLLVM X(argc, argv);

// Initialize targets and assembly printers/parsers.
llvm::InitializeAllTargetInfos();
Expand Down
9 changes: 4 additions & 5 deletions llvm/tools/llvm-opt-report/OptReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@
///
//===----------------------------------------------------------------------===//

#include "llvm/Support/CommandLine.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
#include <map>
#include <set>
Expand Down Expand Up @@ -506,7 +505,7 @@ static bool writeReport(LocationInfoTy &LocationInfo) {
}

int main(int argc, const char **argv) {
sys::PrintStackTraceOnErrorSignal(argv[0]);
InitLLVM X(argc, argv);

cl::HideUnrelatedOptions(OptReportCategory);
cl::ParseCommandLineOptions(
Expand Down
18 changes: 4 additions & 14 deletions llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
Expand All @@ -84,7 +85,6 @@
#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"


using namespace llvm;
using namespace llvm::codeview;
using namespace llvm::msf;
Expand Down Expand Up @@ -1205,21 +1205,11 @@ static void simplifyChunkList(llvm::cl::list<opts::ModuleSubsection> &Chunks) {
Chunks.push_back(opts::ModuleSubsection::All);
}

int main(int argc_, const char *argv_[]) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv_[0]);
PrettyStackTraceProgram X(argc_, argv_);

int main(int Argc, const char **Argv) {
InitLLVM X(Argc, Argv);
ExitOnErr.setBanner("llvm-pdbutil: ");

SmallVector<const char *, 256> argv;
SpecificBumpPtrAllocator<char> ArgAllocator;
ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
argv, makeArrayRef(argv_, argc_), ArgAllocator)));

llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.

cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
cl::ParseCommandLineOptions(Argc, Argv, "LLVM PDB Dumper\n");

if (opts::BytesSubcommand) {
if (!parseRange(opts::bytes::DumpBlockRangeOpt,
Expand Down
9 changes: 2 additions & 7 deletions llvm/tools/llvm-profdata/llvm-profdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/ThreadPool.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
Expand Down Expand Up @@ -802,10 +800,7 @@ static int show_main(int argc, const char *argv[]) {
}

int main(int argc, const char *argv[]) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
InitLLVM X(argc, argv);

StringRef ProgName(sys::path::filename(argv[0]));
if (argc > 1) {
Expand Down
16 changes: 4 additions & 12 deletions llvm/tools/llvm-rc/llvm-rc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "llvm/Option/ArgList.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
Expand Down Expand Up @@ -76,22 +77,13 @@ LLVM_ATTRIBUTE_NORETURN static void fatalError(const Twine &Message) {

} // anonymous namespace

int main(int argc_, const char *argv_[]) {
sys::PrintStackTraceOnErrorSignal(argv_[0]);
PrettyStackTraceProgram X(argc_, argv_);

int main(int Argc, const char **Argv) {
InitLLVM X(Argc, Argv);
ExitOnErr.setBanner("llvm-rc: ");

SmallVector<const char *, 256> argv;
SpecificBumpPtrAllocator<char> ArgAllocator;
ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
argv, makeArrayRef(argv_, argc_), ArgAllocator)));

llvm_shutdown_obj Y;

RcOptTable T;
unsigned MAI, MAC;
ArrayRef<const char *> ArgsArr = makeArrayRef(argv_ + 1, argc_);
ArrayRef<const char *> ArgsArr = makeArrayRef(Argv + 1, Argc - 1);
opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);

// The tool prints nothing when invoked with no command-line arguments.
Expand Down
11 changes: 3 additions & 8 deletions llvm/tools/llvm-readobj/llvm-readobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetRegistry.h"

using namespace llvm;
Expand Down Expand Up @@ -556,17 +554,14 @@ static void dumpInput(StringRef File) {
}

int main(int argc, const char *argv[]) {
StringRef ToolName = argv[0];
sys::PrintStackTraceOnErrorSignal(ToolName);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y;
InitLLVM X(argc, argv);

// Register the target printer for --version.
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);

opts::WideOutput.setHiddenFlag(cl::Hidden);

if (sys::path::stem(ToolName).find("readelf") != StringRef::npos)
if (sys::path::stem(argv[0]).find("readelf") != StringRef::npos)
opts::Output = opts::GNU;

cl::ParseCommandLineOptions(argc, argv, "LLVM Object Reader\n");
Expand Down
9 changes: 2 additions & 7 deletions llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
#include "llvm/Object/SymbolSize.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Memory.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -736,11 +734,8 @@ static int linkAndVerify() {
}

int main(int argc, char **argv) {
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);

InitLLVM X(argc, argv);
ProgramName = argv[0];
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.

llvm::InitializeAllTargetInfos();
llvm::InitializeAllTargetMCs();
Expand Down
10 changes: 2 additions & 8 deletions llvm/tools/llvm-size/llvm-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <string>
Expand Down Expand Up @@ -854,11 +852,7 @@ static void printBerkelyTotals() {
}

int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);

llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
InitLLVM X(argc, argv);
cl::ParseCommandLineOptions(argc, argv, "llvm object size dumper\n");

ToolName = argv[0];
Expand Down
6 changes: 2 additions & 4 deletions llvm/tools/llvm-strings/llvm-strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
#include <cctype>
#include <string>

Expand Down Expand Up @@ -94,8 +93,7 @@ static void strings(raw_ostream &OS, StringRef FileName, StringRef Contents) {
}

int main(int argc, char **argv) {
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
InitLLVM X(argc, argv);

cl::ParseCommandLineOptions(argc, argv, "llvm string dumper\n");
if (MinLength == 0) {
Expand Down
9 changes: 2 additions & 7 deletions llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdio>
#include <cstring>
Expand Down Expand Up @@ -145,10 +143,7 @@ static bool parseCommand(StringRef InputString, bool &IsData,
}

int main(int argc, char **argv) {
// Print stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
InitLLVM X(argc, argv);

llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);

Expand Down
10 changes: 3 additions & 7 deletions llvm/tools/obj2yaml/obj2yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
//
//===----------------------------------------------------------------------===//

#include "Error.h"
#include "obj2yaml.h"
#include "Error.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/InitLLVM.h"

using namespace llvm;
using namespace llvm::object;
Expand Down Expand Up @@ -62,10 +60,8 @@ cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"),
cl::init("-"));

int main(int argc, char *argv[]) {
InitLLVM X(argc, argv);
cl::ParseCommandLineOptions(argc, argv);
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.

if (Error Err = dumpInput(InputFilename)) {
reportError(InputFilename, std::move(Err));
Expand Down
8 changes: 2 additions & 6 deletions llvm/tools/opt/opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/TargetRegistry.h"
Expand Down Expand Up @@ -367,13 +365,11 @@ void initializePollyPasses(llvm::PassRegistry &Registry);
// main for opt
//
int main(int argc, char **argv) {
sys::PrintStackTraceOnErrorSignal(argv[0]);
llvm::PrettyStackTraceProgram X(argc, argv);
InitLLVM X(argc, argv);

// Enable debug stream buffering.
EnableDebugBuffering = true;

llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
LLVMContext Context;

InitializeAllTargets();
Expand Down
8 changes: 2 additions & 6 deletions llvm/tools/verify-uselistorder/verify-uselistorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -527,13 +525,11 @@ static void reverseUseLists(Module &M) {
}

int main(int argc, char **argv) {
sys::PrintStackTraceOnErrorSignal(argv[0]);
llvm::PrettyStackTraceProgram X(argc, argv);
InitLLVM X(argc, argv);

// Enable debug stream buffering.
EnableDebugBuffering = true;

llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
LLVMContext Context;

cl::ParseCommandLineOptions(argc, argv,
Expand Down
8 changes: 2 additions & 6 deletions llvm/tools/yaml2obj/yaml2obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
#include "llvm/ObjectYAML/ObjectYAML.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -70,10 +68,8 @@ static int convertYAML(yaml::Input &YIn, raw_ostream &Out) {
}

int main(int argc, char **argv) {
InitLLVM X(argc, argv);
cl::ParseCommandLineOptions(argc, argv);
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.

if (OutputFilename.empty())
OutputFilename = "-";
Expand Down
6 changes: 2 additions & 4 deletions llvm/utils/FileCheck/FileCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
Expand Down Expand Up @@ -1360,8 +1359,7 @@ bool CheckInput(SourceMgr &SM, StringRef Buffer,
}

int main(int argc, char **argv) {
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
InitLLVM X(argc, argv);
cl::ParseCommandLineOptions(argc, argv);

if (!ValidateCheckPrefixes()) {
Expand Down