Convert the last use of sys::fs::createUniqueFile in bugpoint.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 16 Nov 2017 21:53:51 +0000 (21:53 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 16 Nov 2017 21:53:51 +0000 (21:53 +0000)
llvm-svn: 318459

llvm/tools/bugpoint/ExecutionDriver.cpp

index 912eeb0..7562aa6 100644 (file)
@@ -302,32 +302,26 @@ Expected<std::string> BugDriver::executeProgram(const Module *Program,
   if (!AI)
     AI = Interpreter;
   assert(AI && "Interpreter should have been created already!");
-  bool CreatedBitcode = false;
   if (BitcodeFile.empty()) {
     // Emit the program to a bitcode file...
-    SmallString<128> UniqueFilename;
-    int UniqueFD;
-    std::error_code EC = sys::fs::createUniqueFile(
-        OutputPrefix + "-test-program-%%%%%%%.bc", UniqueFD, UniqueFilename);
-    if (EC) {
-      errs() << ToolName << ": Error making unique filename: " << EC.message()
+    auto File =
+        sys::fs::TempFile::create(OutputPrefix + "-test-program-%%%%%%%.bc");
+    if (!File) {
+      errs() << ToolName
+             << ": Error making unique filename: " << toString(File.takeError())
              << "!\n";
       exit(1);
     }
-    BitcodeFile = UniqueFilename.str();
+    DiscardTemp Discard{*File};
+    BitcodeFile = File->TmpName;
 
-    if (writeProgramToFile(BitcodeFile, UniqueFD, Program)) {
+    if (writeProgramToFile(File->FD, Program)) {
       errs() << ToolName << ": Error emitting bitcode to file '" << BitcodeFile
              << "'!\n";
       exit(1);
     }
-    CreatedBitcode = true;
   }
 
-  // Remove the temporary bitcode file when we are done.
-  std::string BitcodePath(BitcodeFile);
-  FileRemover BitcodeFileRemover(BitcodePath, CreatedBitcode && !SaveTemps);
-
   if (OutputFile.empty())
     OutputFile = OutputPrefix + "-execution-output-%%%%%%%";