[PATCH] D51836: [bugpoint] Fix TempFile scoping bug

Don Hinton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 8 20:14:27 PDT 2018


hintonda created this revision.
hintonda added reviewers: MatzeB, pcc, Meinersbur.

Fix TempFile scoping bug introduced in r318459, by moving
temp file generation to the calling function.


Repository:
  rL LLVM

https://reviews.llvm.org/D51836

Files:
  tools/bugpoint/ExecutionDriver.cpp


Index: tools/bugpoint/ExecutionDriver.cpp
===================================================================
--- tools/bugpoint/ExecutionDriver.cpp
+++ tools/bugpoint/ExecutionDriver.cpp
@@ -296,29 +296,10 @@
                                                 std::string BitcodeFile,
                                                 const std::string &SharedObj,
                                                 AbstractInterpreter *AI) const {
+  assert(!BitcodeFile.empty() && "BitcodeFile is empty.");
   if (!AI)
     AI = Interpreter;
   assert(AI && "Interpreter should have been created already!");
-  if (BitcodeFile.empty()) {
-    // Emit the program to a bitcode file...
-    auto File =
-        sys::fs::TempFile::create(OutputPrefix + "-test-program-%%%%%%%.bc");
-    if (!File) {
-      errs() << ToolName
-             << ": Error making unique filename: " << toString(File.takeError())
-             << "!\n";
-      exit(1);
-    }
-    DiscardTemp Discard{*File};
-    BitcodeFile = File->TmpName;
-
-    if (writeProgramToFile(File->FD, Program)) {
-      errs() << ToolName << ": Error emitting bitcode to file '" << BitcodeFile
-             << "'!\n";
-      exit(1);
-    }
-  }
-
   if (OutputFile.empty())
     OutputFile = OutputPrefix + "-execution-output-%%%%%%%";
 
@@ -375,7 +356,23 @@
 Expected<std::string>
 BugDriver::executeProgramSafely(const Module &Program,
                                 const std::string &OutputFile) const {
-  return executeProgram(Program, OutputFile, "", "", SafeInterpreter);
+  Expected<sys::fs::TempFile> BitcodeFile =
+    sys::fs::TempFile::create(OutputPrefix + "-test-program-%%%%%%%.bc");
+  if (!BitcodeFile) {
+    errs() << ToolName << ": Error making unique filename: "
+           << toString(BitcodeFile.takeError()) << "!\n";
+    exit(1);
+  }
+  DiscardTemp Discard{*BitcodeFile};
+
+  if (writeProgramToFile(BitcodeFile->FD, Program)) {
+    errs() << ToolName << ": Error emitting bitcode to file '"
+           << BitcodeFile->TmpName << "'!\n";
+    exit(1);
+  }
+
+  return executeProgram(Program, OutputFile, BitcodeFile->TmpName, "",
+                        SafeInterpreter);
 }
 
 Expected<std::string>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51836.164581.patch
Type: text/x-patch
Size: 2194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180909/33480411/attachment.bin>


More information about the llvm-commits mailing list