diff options
| author | 2018-04-06 14:26:03 +0000 | |
|---|---|---|
| committer | 2018-04-06 14:26:03 +0000 | |
| commit | bdabc2f19ffb9e20600dad6e8a300842a7bda50e (patch) | |
| tree | c50e7b2e5449b074651bb82a58517a8ebc4a8cf7 /gnu/llvm/tools/bugpoint/OptimizerDriver.cpp | |
| parent | Print a 'p' flag for file descriptors that were opened after pledge(2). (diff) | |
| download | wireguard-openbsd-bdabc2f19ffb9e20600dad6e8a300842a7bda50e.tar.xz wireguard-openbsd-bdabc2f19ffb9e20600dad6e8a300842a7bda50e.zip | |
Import LLVM 6.0.1 release including clang, lld and lldb.
"where is the kaboom?" deraadt@
Diffstat (limited to 'gnu/llvm/tools/bugpoint/OptimizerDriver.cpp')
| -rw-r--r-- | gnu/llvm/tools/bugpoint/OptimizerDriver.cpp | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/gnu/llvm/tools/bugpoint/OptimizerDriver.cpp b/gnu/llvm/tools/bugpoint/OptimizerDriver.cpp index 489e50b8810..ee3f2f0174d 100644 --- a/gnu/llvm/tools/bugpoint/OptimizerDriver.cpp +++ b/gnu/llvm/tools/bugpoint/OptimizerDriver.cpp @@ -18,21 +18,17 @@ #include "BugDriver.h" #include "llvm/Bitcode/BitcodeWriter.h" #include "llvm/IR/DataLayout.h" -#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" -#include "llvm/IR/Verifier.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" -#include "llvm/Support/SystemUtils.h" #include "llvm/Support/ToolOutputFile.h" #define DONT_GET_PLUGIN_LOADER_OPTION #include "llvm/Support/PluginLoader.h" -#include <fstream> using namespace llvm; @@ -58,7 +54,7 @@ static cl::opt<std::string> /// writeProgramToFile - This writes the current "Program" to the named bitcode /// file. If an error occurs, true is returned. /// -static bool writeProgramToFileAux(tool_output_file &Out, const Module *M) { +static bool writeProgramToFileAux(ToolOutputFile &Out, const Module *M) { WriteBitcodeToFile(M, Out.os(), PreserveBitcodeUseListOrder); Out.os().close(); if (!Out.os().has_error()) { @@ -70,14 +66,24 @@ 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, FD); + ToolOutputFile Out(Filename, FD); return writeProgramToFileAux(Out, M); } +bool BugDriver::writeProgramToFile(int FD, const Module *M) const { + raw_fd_ostream OS(FD, /*shouldClose*/ false); + WriteBitcodeToFile(M, OS, PreserveBitcodeUseListOrder); + OS.flush(); + if (!OS.has_error()) + return false; + OS.clear_error(); + return true; +} + bool BugDriver::writeProgramToFile(const std::string &Filename, const Module *M) const { std::error_code EC; - tool_output_file Out(Filename, EC, sys::fs::F_None); + ToolOutputFile Out(Filename, EC, sys::fs::F_None); if (!EC) return writeProgramToFileAux(Out, M); return true; @@ -144,23 +150,22 @@ bool BugDriver::runPasses(Module *Program, OutputFilename = UniqueFilename.str(); // set up the input file name - SmallString<128> InputFilename; - int InputFD; - EC = sys::fs::createUniqueFile(OutputPrefix + "-input-%%%%%%%.bc", InputFD, - InputFilename); - if (EC) { + Expected<sys::fs::TempFile> Temp = + sys::fs::TempFile::create(OutputPrefix + "-input-%%%%%%%.bc"); + if (!Temp) { errs() << getToolName() - << ": Error making unique filename: " << EC.message() << "\n"; + << ": Error making unique filename: " << toString(Temp.takeError()) + << "\n"; return 1; } - - tool_output_file InFile(InputFilename, InputFD); - - WriteBitcodeToFile(Program, InFile.os(), PreserveBitcodeUseListOrder); - InFile.os().close(); - if (InFile.os().has_error()) { - errs() << "Error writing bitcode file: " << InputFilename << "\n"; - InFile.os().clear_error(); + DiscardTemp Discard{*Temp}; + raw_fd_ostream OS(Temp->FD, /*shouldClose*/ false); + + WriteBitcodeToFile(Program, OS, PreserveBitcodeUseListOrder); + OS.flush(); + if (OS.has_error()) { + errs() << "Error writing bitcode file: " << Temp->TmpName << "\n"; + OS.clear_error(); return 1; } @@ -189,9 +194,6 @@ bool BugDriver::runPasses(Module *Program, return 1; } - // Ok, everything that could go wrong before running opt is done. - InFile.keep(); - // setup the child process' arguments SmallVector<const char *, 8> Args; if (UseValgrind) { @@ -220,7 +222,7 @@ bool BugDriver::runPasses(Module *Program, E = pass_args.end(); I != E; ++I) Args.push_back(I->c_str()); - Args.push_back(InputFilename.c_str()); + Args.push_back(Temp->TmpName.c_str()); for (unsigned i = 0; i < NumExtraArgs; ++i) Args.push_back(*ExtraArgs); Args.push_back(nullptr); @@ -230,13 +232,15 @@ bool BugDriver::runPasses(Module *Program, << " " << Args[i]; errs() << "\n";); - // Redirect stdout and stderr to nowhere if SilencePasses is given - StringRef Nowhere; - const StringRef *Redirects[3] = {nullptr, &Nowhere, &Nowhere}; + Optional<StringRef> Redirects[3] = {None, None, None}; + // Redirect stdout and stderr to nowhere if SilencePasses is given. + if (SilencePasses) { + Redirects[1] = ""; + Redirects[2] = ""; + } std::string ErrMsg; - int result = sys::ExecuteAndWait(Prog, Args.data(), nullptr, - (SilencePasses ? Redirects : nullptr), + int result = sys::ExecuteAndWait(Prog, Args.data(), nullptr, Redirects, Timeout, MemoryLimit, &ErrMsg); // If we are supposed to delete the bitcode file or if the passes crashed, @@ -244,9 +248,6 @@ bool BugDriver::runPasses(Module *Program, if (DeleteOutput || result != 0) sys::fs::remove(OutputFilename); - // Remove the temporary input file as well - sys::fs::remove(InputFilename.c_str()); - if (!Quiet) { if (result == 0) outs() << "Success!\n"; |
