From 67c32a98315f785a9ec9d531c1f571a0196c7463 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 18 Jan 2015 16:17:27 +0000 Subject: Vendor import of llvm RELEASE_360/rc1 tag r226102 (effectively, 3.6.0 RC1): https://llvm.org/svn/llvm-project/llvm/tags/RELEASE_360/rc1@226102 --- tools/bugpoint/OptimizerDriver.cpp | 50 +++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'tools/bugpoint/OptimizerDriver.cpp') diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index d452fd94c06a8..f197cc53926a2 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -66,15 +66,15 @@ static bool writeProgramToFileAux(tool_output_file &Out, const Module *M) { bool BugDriver::writeProgramToFile(const std::string &Filename, int FD, const Module *M) const { - tool_output_file Out(Filename.c_str(), FD); + tool_output_file Out(Filename, FD); return writeProgramToFileAux(Out, M); } bool BugDriver::writeProgramToFile(const std::string &Filename, const Module *M) const { - std::string ErrInfo; - tool_output_file Out(Filename.c_str(), ErrInfo, sys::fs::F_None); - if (ErrInfo.empty()) + std::error_code EC; + tool_output_file Out(Filename, EC, sys::fs::F_None); + if (!EC) return writeProgramToFileAux(Out, M); return true; } @@ -149,7 +149,7 @@ bool BugDriver::runPasses(Module *Program, return 1; } - tool_output_file InFile(InputFilename.c_str(), InputFD); + tool_output_file InFile(InputFilename, InputFD); WriteBitcodeToFile(Program, InFile.os()); InFile.os().close(); @@ -159,12 +159,31 @@ bool BugDriver::runPasses(Module *Program, return 1; } - std::string tool = OptCmd.empty()? sys::FindProgramByName("opt") : OptCmd; + std::string tool = OptCmd; + if (OptCmd.empty()) { + if (ErrorOr Path = sys::findProgramByName("opt")) + tool = *Path; + else + errs() << Path.getError().message() << "\n"; + } if (tool.empty()) { errs() << "Cannot find `opt' in PATH!\n"; return 1; } + std::string Prog; + if (UseValgrind) { + if (ErrorOr Path = sys::findProgramByName("valgrind")) + Prog = *Path; + else + errs() << Path.getError().message() << "\n"; + } else + Prog = tool; + if (Prog.empty()) { + errs() << "Cannot find `valgrind' in PATH!\n"; + return 1; + } + // Ok, everything that could go wrong before running opt is done. InFile.keep(); @@ -204,12 +223,6 @@ bool BugDriver::runPasses(Module *Program, errs() << "\n"; ); - std::string Prog; - if (UseValgrind) - Prog = sys::FindProgramByName("valgrind"); - else - Prog = tool; - // Redirect stdout and stderr to nowhere if SilencePasses is given StringRef Nowhere; const StringRef *Redirects[3] = {nullptr, &Nowhere, &Nowhere}; @@ -247,13 +260,10 @@ bool BugDriver::runPasses(Module *Program, } -/// runPassesOn - Carefully run the specified set of pass on the specified -/// module, returning the transformed module on success, or a null pointer on -/// failure. -Module *BugDriver::runPassesOn(Module *M, - const std::vector &Passes, - bool AutoDebugCrashes, unsigned NumExtraArgs, - const char * const *ExtraArgs) { +std::unique_ptr +BugDriver::runPassesOn(Module *M, const std::vector &Passes, + bool AutoDebugCrashes, unsigned NumExtraArgs, + const char *const *ExtraArgs) { std::string BitcodeResult; if (runPasses(M, Passes, BitcodeResult, false/*delete*/, true/*quiet*/, NumExtraArgs, ExtraArgs)) { @@ -267,7 +277,7 @@ Module *BugDriver::runPassesOn(Module *M, return nullptr; } - Module *Ret = ParseInputFile(BitcodeResult, Context); + std::unique_ptr Ret = parseInputFile(BitcodeResult, Context); if (!Ret) { errs() << getToolName() << ": Error reading bitcode file '" << BitcodeResult << "'!\n"; -- cgit v1.2.3