[llvm] r318427 - Convert another use of createUniqueFile to TempFile::create.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 16 09:35:50 PST 2017
Author: rafael
Date: Thu Nov 16 09:35:50 2017
New Revision: 318427
URL: http://llvm.org/viewvc/llvm-project?rev=318427&view=rev
Log:
Convert another use of createUniqueFile to TempFile::create.
Modified:
llvm/trunk/tools/bugpoint/BugDriver.cpp
llvm/trunk/tools/bugpoint/BugDriver.h
llvm/trunk/tools/bugpoint/ExtractFunction.cpp
llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
Modified: llvm/trunk/tools/bugpoint/BugDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/BugDriver.cpp?rev=318427&r1=318426&r2=318427&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/BugDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/BugDriver.cpp Thu Nov 16 09:35:50 2017
@@ -32,6 +32,11 @@ namespace llvm {
Triple TargetTriple;
}
+DiscardTemp::~DiscardTemp() {
+ if (Error E = File.discard())
+ errs() << "Failed to delete temp file " << toString(std::move(E)) << '\n';
+}
+
// Anonymous namespace to define command line options for debugging.
//
namespace {
Modified: llvm/trunk/tools/bugpoint/BugDriver.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/BugDriver.h?rev=318427&r1=318426&r2=318427&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/BugDriver.h (original)
+++ llvm/trunk/tools/bugpoint/BugDriver.h Thu Nov 16 09:35:50 2017
@@ -18,6 +18,7 @@
#include "llvm/IR/ValueMap.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <memory>
#include <string>
@@ -278,6 +279,11 @@ private:
Error initializeExecutionEnvironment();
};
+struct DiscardTemp {
+ sys::fs::TempFile &File;
+ ~DiscardTemp();
+};
+
/// Given a bitcode or assembly input filename, parse and return it, or return
/// null if not possible.
///
Modified: llvm/trunk/tools/bugpoint/ExtractFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ExtractFunction.cpp?rev=318427&r1=318426&r2=318427&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/ExtractFunction.cpp (original)
+++ llvm/trunk/tools/bugpoint/ExtractFunction.cpp Thu Nov 16 09:35:50 2017
@@ -373,19 +373,17 @@ llvm::SplitFunctionsOutOfModule(Module *
std::unique_ptr<Module>
BugDriver::extractMappedBlocksFromModule(const std::vector<BasicBlock *> &BBs,
Module *M) {
- SmallString<128> Filename;
- int FD;
- std::error_code EC = sys::fs::createUniqueFile(
- OutputPrefix + "-extractblocks%%%%%%%", FD, Filename);
- if (EC) {
+ auto Temp = sys::fs::TempFile::create(OutputPrefix + "-extractblocks%%%%%%%");
+ if (!Temp) {
outs() << "*** Basic Block extraction failed!\n";
- errs() << "Error creating temporary file: " << EC.message() << "\n";
+ errs() << "Error creating temporary file: " << toString(Temp.takeError())
+ << "\n";
EmitProgressBitcode(M, "basicblockextractfail", true);
return nullptr;
}
- sys::RemoveFileOnSignal(Filename);
+ DiscardTemp Discard{*Temp};
- ToolOutputFile BlocksToNotExtractFile(Filename.c_str(), FD);
+ raw_fd_ostream OS(Temp->FD, /*shouldClose*/ false);
for (std::vector<BasicBlock *>::const_iterator I = BBs.begin(), E = BBs.end();
I != E; ++I) {
BasicBlock *BB = *I;
@@ -393,28 +391,24 @@ BugDriver::extractMappedBlocksFromModule
// off of.
if (!BB->hasName())
BB->setName("tmpbb");
- BlocksToNotExtractFile.os() << BB->getParent()->getName() << " "
- << BB->getName() << "\n";
+ OS << BB->getParent()->getName() << " " << BB->getName() << "\n";
}
- BlocksToNotExtractFile.os().close();
- if (BlocksToNotExtractFile.os().has_error()) {
+ OS.flush();
+ if (OS.has_error()) {
errs() << "Error writing list of blocks to not extract\n";
EmitProgressBitcode(M, "basicblockextractfail", true);
- BlocksToNotExtractFile.os().clear_error();
+ OS.clear_error();
return nullptr;
}
- BlocksToNotExtractFile.keep();
std::string uniqueFN = "--extract-blocks-file=";
- uniqueFN += Filename.str();
+ uniqueFN += Temp->TmpName;
const char *ExtraArg = uniqueFN.c_str();
std::vector<std::string> PI;
PI.push_back("extract-blocks");
std::unique_ptr<Module> Ret = runPassesOn(M, PI, 1, &ExtraArg);
- sys::fs::remove(Filename.c_str());
-
if (!Ret) {
outs() << "*** Basic Block extraction failed, please report a bug!\n";
EmitProgressBitcode(M, "basicblockextractfail", true);
Modified: llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/OptimizerDriver.cpp?rev=318427&r1=318426&r2=318427&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/OptimizerDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/OptimizerDriver.cpp Thu Nov 16 09:35:50 2017
@@ -118,11 +118,6 @@ static cl::list<std::string> OptArgs("op
cl::desc("<opt arguments>..."),
cl::ZeroOrMore, cl::PositionalEatsArgs);
-struct DiscardTemp {
- sys::fs::TempFile &File;
- ~DiscardTemp() { consumeError(File.discard()); }
-};
-
/// runPasses - Run the specified passes on Program, outputting a bitcode file
/// and writing the filename into OutputFile if successful. If the
/// optimizations fail for some reason (optimizer crashes), return true,
More information about the llvm-commits
mailing list