[llvm-dwarfump] Don't rely on global state, part 3.
authorDavide Italiano <davide@freebsd.org>
Sun, 26 Jul 2015 05:35:59 +0000 (05:35 +0000)
committerDavide Italiano <davide@freebsd.org>
Sun, 26 Jul 2015 05:35:59 +0000 (05:35 +0000)
Some tools used to rely on a global static variable to keep track of the
return value for main(). I changed llvm-cxxdump to use exit(1)
and Rafael shortly after did the same with llvm-readobj. This is
(yet) another step towards the goal.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243240 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-dwarfdump/llvm-dwarfdump.cpp

index db3fcf6..cd48d81 100644 (file)
@@ -69,27 +69,22 @@ DumpType("debug-dump", cl::init(DIDT_All),
         clEnumValN(DIDT_StrOffsetsDwo, "str_offsets.dwo", ".debug_str_offsets.dwo"),
         clEnumValEnd));
 
-static int ReturnValue = EXIT_SUCCESS;
-
-static bool error(StringRef Filename, std::error_code EC) {
+static void error(StringRef Filename, std::error_code EC) {
   if (!EC)
-    return false;
+    return;
   errs() << Filename << ": " << EC.message() << "\n";
-  ReturnValue = EXIT_FAILURE;
-  return true;
+  exit(1);
 }
 
 static void DumpInput(StringRef Filename) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> BuffOrErr =
       MemoryBuffer::getFileOrSTDIN(Filename);
-  if (error(Filename, BuffOrErr.getError()))
-    return;
+  error(Filename, BuffOrErr.getError());
   std::unique_ptr<MemoryBuffer> Buff = std::move(BuffOrErr.get());
 
   ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
       ObjectFile::createObjectFile(Buff->getMemBufferRef());
-  if (error(Filename, ObjOrErr.getError()))
-    return;
+  error(Filename, ObjOrErr.getError());
   ObjectFile &Obj = *ObjOrErr.get();
 
   std::unique_ptr<DIContext> DICtx(new DWARFContextInMemory(Obj));
@@ -114,5 +109,5 @@ int main(int argc, char **argv) {
 
   std::for_each(InputFilenames.begin(), InputFilenames.end(), DumpInput);
 
-  return ReturnValue;
+  return EXIT_SUCCESS;
 }