[lib/LTO] Try harder to reduce code duplication. NFCI.

llvm-svn: 281843
This commit is contained in:
Davide Italiano 2016-09-17 22:32:42 +00:00
parent aeb764a7b7
commit a416d11357
1 changed files with 14 additions and 13 deletions

View File

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