OSDN Git Service

[lib/LTO] Try harder to reduce code duplication. NFCI.
authorDavide Italiano <davide@freebsd.org>
Sat, 17 Sep 2016 22:32:42 +0000 (22:32 +0000)
committerDavide Italiano <davide@freebsd.org>
Sat, 17 Sep 2016 22:32:42 +0000 (22:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281843 91177308-0d34-0410-b5e6-96231b3b80d8

lib/LTO/LTOBackend.cpp

index 9e53972..d83b65d 100644 (file)
 using namespace llvm;
 using namespace lto;
 
+LLVM_ATTRIBUTE_NORETURN void reportOpenError(StringRef Path, Twine Msg) {
+  errs() << "failed to open " << Path << ": " << Msg << '\n';
+  errs().flush();
+  exit(1);
+}
+
 Error Config::addSaveTemps(std::string OutputFileName,
                            bool UseInputModulePath) {
   ShouldDiscardValueNames = false;
@@ -71,13 +77,10 @@ Error Config::addSaveTemps(std::string OutputFileName,
       std::string Path = PathPrefix + "." + PathSuffix + ".bc";
       std::error_code EC;
       raw_fd_ostream OS(Path, EC, sys::fs::OpenFlags::F_None);
-      if (EC) {
-        // Because -save-temps is a debugging feature, we report the error
-        // directly and exit.
-        llvm::errs() << "failed to open " << Path << ": " << EC.message()
-                     << '\n';
-        exit(1);
-      }
+      // Because -save-temps is a debugging feature, we report the error
+      // directly and exit.
+      if (EC)
+        reportOpenError(Path, EC.message());
       WriteBitcodeToFile(&M, OS, /*ShouldPreserveUseListOrder=*/false);
       return true;
     };
@@ -94,12 +97,10 @@ Error Config::addSaveTemps(std::string OutputFileName,
     std::string Path = OutputFileName + "index.bc";
     std::error_code EC;
     raw_fd_ostream OS(Path, EC, sys::fs::OpenFlags::F_None);
-    if (EC) {
-      // Because -save-temps is a debugging feature, we report the error
-      // directly and exit.
-      llvm::errs() << "failed to open " << Path << ": " << EC.message() << '\n';
-      exit(1);
-    }
+    // Because -save-temps is a debugging feature, we report the error
+    // directly and exit.
+    if (EC)
+      reportOpenError(Path, EC.message());
     WriteIndexToFile(Index, OS);
     return true;
   };