summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Support/FileSystem.h3
-rw-r--r--llvm/lib/Support/Path.cpp16
-rw-r--r--llvm/tools/bugpoint/BugDriver.cpp5
-rw-r--r--llvm/tools/bugpoint/BugDriver.h1
-rw-r--r--llvm/tools/bugpoint/ExecutionDriver.cpp21
-rw-r--r--llvm/tools/bugpoint/OptimizerDriver.cpp10
6 files changed, 44 insertions, 12 deletions
diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h
index 30664984efc..a7874abf481 100644
--- a/llvm/include/llvm/Support/FileSystem.h
+++ b/llvm/include/llvm/Support/FileSystem.h
@@ -723,6 +723,9 @@ public:
// Keep this with the given name.
Error keep(const Twine &Name);
+ // Keep this with the temporary name.
+ Error keep();
+
// Delete the file.
Error discard();
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index 5f0adb337b9..b96396a3846 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -805,6 +805,22 @@ Error TempFile::keep(const Twine &Name) {
return errorCodeToError(RenameEC);
}
+Error TempFile::keep() {
+ assert(!Done);
+ Done = true;
+
+ sys::DontRemoveFileOnSignal(TmpName);
+ TmpName = "";
+
+ if (close(FD) == -1) {
+ std::error_code EC(errno, std::generic_category());
+ return errorCodeToError(EC);
+ }
+ FD = -1;
+
+ return Error::success();
+}
+
Expected<TempFile> TempFile::create(const Twine &Model, unsigned Mode) {
int FD;
SmallString<128> ResultPath;
diff --git a/llvm/tools/bugpoint/BugDriver.cpp b/llvm/tools/bugpoint/BugDriver.cpp
index 3c2af2d17ee..37bdb7bc96b 100644
--- a/llvm/tools/bugpoint/BugDriver.cpp
+++ b/llvm/tools/bugpoint/BugDriver.cpp
@@ -33,6 +33,11 @@ Triple TargetTriple;
}
DiscardTemp::~DiscardTemp() {
+ if (SaveTemps) {
+ if (Error E = File.keep())
+ errs() << "Failed to keep temp file " << toString(std::move(E)) << '\n';
+ return;
+ }
if (Error E = File.discard())
errs() << "Failed to delete temp file " << toString(std::move(E)) << '\n';
}
diff --git a/llvm/tools/bugpoint/BugDriver.h b/llvm/tools/bugpoint/BugDriver.h
index 5eaad34927e..0e6a9b4f2f3 100644
--- a/llvm/tools/bugpoint/BugDriver.h
+++ b/llvm/tools/bugpoint/BugDriver.h
@@ -271,6 +271,7 @@ public:
bool writeProgramToFile(const std::string &Filename, const Module *M) const;
bool writeProgramToFile(const std::string &Filename, int FD,
const Module *M) const;
+ bool writeProgramToFile(int FD, const Module *M) const;
private:
/// initializeExecutionEnvironment - This method is used to set up the
diff --git a/llvm/tools/bugpoint/ExecutionDriver.cpp b/llvm/tools/bugpoint/ExecutionDriver.cpp
index b26ba93cd61..912eeb006c2 100644
--- a/llvm/tools/bugpoint/ExecutionDriver.cpp
+++ b/llvm/tools/bugpoint/ExecutionDriver.cpp
@@ -271,26 +271,23 @@ Error BugDriver::initializeExecutionEnvironment() {
///
Error BugDriver::compileProgram(Module *M) const {
// Emit the program to a bitcode file...
- SmallString<128> BitcodeFile;
- int BitcodeFD;
- std::error_code EC = sys::fs::createUniqueFile(
- OutputPrefix + "-test-program-%%%%%%%.bc", BitcodeFD, BitcodeFile);
- if (EC) {
- errs() << ToolName << ": Error making unique filename: " << EC.message()
+ auto Temp =
+ sys::fs::TempFile::create(OutputPrefix + "-test-program-%%%%%%%.bc");
+ if (!Temp) {
+ errs() << ToolName
+ << ": Error making unique filename: " << toString(Temp.takeError())
<< "\n";
exit(1);
}
- if (writeProgramToFile(BitcodeFile.str(), BitcodeFD, M)) {
- errs() << ToolName << ": Error emitting bitcode to file '" << BitcodeFile
+ DiscardTemp Discard{*Temp};
+ if (writeProgramToFile(Temp->FD, M)) {
+ errs() << ToolName << ": Error emitting bitcode to file '" << Temp->TmpName
<< "'!\n";
exit(1);
}
- // Remove the temporary bitcode file when we are done.
- FileRemover BitcodeFileRemover(BitcodeFile.str(), !SaveTemps);
-
// Actually compile the program!
- return Interpreter->compileProgram(BitcodeFile.str(), Timeout, MemoryLimit);
+ return Interpreter->compileProgram(Temp->TmpName, Timeout, MemoryLimit);
}
/// executeProgram - This method runs "Program", capturing the output of the
diff --git a/llvm/tools/bugpoint/OptimizerDriver.cpp b/llvm/tools/bugpoint/OptimizerDriver.cpp
index d4e353dd994..6e0b086d48e 100644
--- a/llvm/tools/bugpoint/OptimizerDriver.cpp
+++ b/llvm/tools/bugpoint/OptimizerDriver.cpp
@@ -74,6 +74,16 @@ bool BugDriver::writeProgramToFile(const std::string &Filename, int 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;
OpenPOWER on IntegriCloud