From 1e786d52fd3187a3f27de9b1206d3a408e2c1864 Mon Sep 17 00:00:00 2001
From: Benjamin Kramer <benny.kra@googlemail.com>
Date: Fri, 30 Jun 2017 20:24:32 +0000
Subject: [PATCH] [clang-rename] Just return instead of calling exit(3) from
 main.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306873 91177308-0d34-0410-b5e6-96231b3b80d8
---
 tools/clang-rename/ClangRename.cpp | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/tools/clang-rename/ClangRename.cpp b/tools/clang-rename/ClangRename.cpp
index 0fdf9a39809..cc18a05bcdb 100644
--- a/tools/clang-rename/ClangRename.cpp
+++ b/tools/clang-rename/ClangRename.cpp
@@ -33,7 +33,6 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
-#include <cstdlib>
 #include <string>
 #include <system_error>
 
@@ -127,13 +126,13 @@ int main(int argc, const char **argv) {
   // Check the arguments for correctness.
   if (NewNames.empty()) {
     errs() << "clang-rename: -new-name must be specified.\n\n";
-    exit(1);
+    return 1;
   }
 
   if (SymbolOffsets.empty() == QualifiedNames.empty()) {
     errs() << "clang-rename: -offset and -qualified-name can't be present at "
               "the same time.\n";
-    exit(1);
+    return 1;
   }
 
   // Check if NewNames is a valid identifier in C++17.
@@ -145,7 +144,7 @@ int main(int argc, const char **argv) {
     auto NewNameTokKind = Table.get(NewName).getTokenID();
     if (!tok::isAnyIdentifier(NewNameTokKind)) {
       errs() << "ERROR: new name is not a valid identifier in C++17.\n\n";
-      exit(1);
+      return 1;
     }
   }
 
@@ -155,7 +154,7 @@ int main(int argc, const char **argv) {
            << ") must be equal to number of new names(" << NewNames.size()
            << ").\n\n";
     cl::PrintHelpMessage();
-    exit(1);
+    return 1;
   }
 
   auto Files = OP.getSourcePathList();
@@ -173,13 +172,13 @@ int main(int argc, const char **argv) {
 
   if (FindingAction.errorOccurred()) {
     // Diagnostics are already issued at this point.
-    exit(1);
+    return 1;
   }
 
   if (Force && PrevNames.size() < NewNames.size()) {
     // No matching PrevName for all NewNames. Without Force this is an error
     // above already.
-    exit(0);
+    return 0;
   }
 
   // Perform the renaming.
@@ -199,7 +198,7 @@ int main(int argc, const char **argv) {
       llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None);
       if (EC) {
         llvm::errs() << "Error opening output file: " << EC.message() << '\n';
-        exit(1);
+        return 1;
       }
 
       // Export replacements.
@@ -212,7 +211,7 @@ int main(int argc, const char **argv) {
       yaml::Output YAML(OS);
       YAML << TUR;
       OS.close();
-      exit(0);
+      return 0;
     }
 
     // Write every file to stdout. Right now we just barf the files without any
@@ -236,5 +235,5 @@ int main(int argc, const char **argv) {
     }
   }
 
-  exit(ExitCode);
+  return ExitCode;
 }
-- 
GitLab