From: Davide Italiano Date: Sat, 17 Sep 2016 22:32:42 +0000 (+0000) Subject: [lib/LTO] Try harder to reduce code duplication. NFCI. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a64fbcff2ddbed2a767fdbed8bfbd8e98f3f4555;p=llvm [lib/LTO] Try harder to reduce code duplication. NFCI. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281843 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/LTO/LTOBackend.cpp b/lib/LTO/LTOBackend.cpp index 9e53972a9d4..d83b65de4cc 100644 --- a/lib/LTO/LTOBackend.cpp +++ b/lib/LTO/LTOBackend.cpp @@ -41,6 +41,12 @@ 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; };