diff options
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/bugpoint/OptimizerDriver.cpp | 32 | ||||
-rw-r--r-- | llvm/tools/lto/LTOCodeGenerator.cpp | 50 |
2 files changed, 42 insertions, 40 deletions
diff --git a/llvm/tools/bugpoint/OptimizerDriver.cpp b/llvm/tools/bugpoint/OptimizerDriver.cpp index 257647f08f9..ef41c43b5f1 100644 --- a/llvm/tools/bugpoint/OptimizerDriver.cpp +++ b/llvm/tools/bugpoint/OptimizerDriver.cpp @@ -51,10 +51,10 @@ namespace { /// bool BugDriver::writeProgramToFile(const std::string &Filename, Module *M) const { - std::ios::openmode io_mode = std::ios::out | std::ios::trunc | - std::ios::binary; - std::ofstream Out(Filename.c_str(), io_mode); - if (!Out.good()) return true; + std::string ErrInfo; + raw_fd_ostream Out(Filename.c_str(), ErrInfo, + raw_fd_ostream::F_Force|raw_fd_ostream::F_Binary); + if (!ErrInfo.empty()) return true; WriteBitcodeToFile(M ? M : Program, Out); return false; @@ -83,11 +83,10 @@ void BugDriver::EmitProgressBitcode(const std::string &ID, bool NoFlyer) { } int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) { - - std::ios::openmode io_mode = std::ios::out | std::ios::trunc | - std::ios::binary; - std::ofstream OutFile(ChildOutput.c_str(), io_mode); - if (!OutFile.good()) { + std::string ErrInfo; + raw_fd_ostream OutFile(ChildOutput.c_str(), ErrInfo, + raw_fd_ostream::F_Force|raw_fd_ostream::F_Binary); + if (!ErrInfo.empty()) { errs() << "Error opening bitcode file: " << ChildOutput << "\n"; return 1; } @@ -106,7 +105,7 @@ int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) { PM.add(createVerifierPass()); // Write bitcode out to disk as the last step... - PM.add(CreateBitcodeWriterPass(OutFile)); + PM.add(createBitcodeWriterPass(OutFile)); // Run all queued passes. PM.run(*Program); @@ -146,12 +145,15 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes, << ErrMsg << "\n"; return(1); } - std::ios::openmode io_mode = std::ios::out | std::ios::trunc | - std::ios::binary; - std::ofstream InFile(inputFilename.c_str(), io_mode); - if (!InFile.good()) { + + std::string ErrInfo; + raw_fd_ostream InFile(inputFilename.c_str(), ErrInfo, + raw_fd_ostream::F_Force|raw_fd_ostream::F_Binary); + + + if (!ErrInfo.empty()) { errs() << "Error opening bitcode file: " << inputFilename << "\n"; - return(1); + return 1; } WriteBitcodeToFile(Program, InFile); InFile.close(); diff --git a/llvm/tools/lto/LTOCodeGenerator.cpp b/llvm/tools/lto/LTOCodeGenerator.cpp index 36be5231815..f47eb49c398 100644 --- a/llvm/tools/lto/LTOCodeGenerator.cpp +++ b/llvm/tools/lto/LTOCodeGenerator.cpp @@ -47,10 +47,7 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Config/config.h" - - #include <cstdlib> -#include <fstream> #include <unistd.h> #include <fcntl.h> @@ -139,31 +136,34 @@ void LTOCodeGenerator::addMustPreserveSymbol(const char* sym) } -bool LTOCodeGenerator::writeMergedModules(const char* path, std::string& errMsg) -{ - if ( this->determineTarget(errMsg) ) - return true; +bool LTOCodeGenerator::writeMergedModules(const char *path, + std::string &errMsg) { + if (determineTarget(errMsg)) + return true; - // mark which symbols can not be internalized - this->applyScopeRestrictions(); + // mark which symbols can not be internalized + applyScopeRestrictions(); - // create output file - std::ofstream out(path, std::ios_base::out|std::ios::trunc|std::ios::binary); - if ( out.fail() ) { - errMsg = "could not open bitcode file for writing: "; - errMsg += path; - return true; - } - - // write bitcode to it - WriteBitcodeToFile(_linker.getModule(), out); - if ( out.fail() ) { - errMsg = "could not write bitcode file: "; - errMsg += path; - return true; - } + // create output file + std::string ErrInfo; + raw_fd_ostream Out(path, ErrInfo, + raw_fd_ostream::F_Force|raw_fd_ostream::F_Binary); + if (!ErrInfo.empty()) { + errMsg = "could not open bitcode file for writing: "; + errMsg += path; + return true; + } - return false; + // write bitcode to it + WriteBitcodeToFile(_linker.getModule(), Out); + + if (Out.has_error()) { + errMsg = "could not write bitcode file: "; + errMsg += path; + return true; + } + + return false; } |