Simplify memory management a bit. NFC.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 9 Dec 2015 00:08:22 +0000 (00:08 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 9 Dec 2015 00:08:22 +0000 (00:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255079 91177308-0d34-0410-b5e6-96231b3b80d8

tools/bugpoint/Miscompilation.cpp

index db6dd54..d511d39 100644 (file)
@@ -321,7 +321,8 @@ static bool ExtractLoops(BugDriver &BD,
     Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
                                                    MiscompiledFunctions,
                                                    VMap);
-    Module *ToOptimizeLoopExtracted = BD.extractLoop(ToOptimize).release();
+    std::unique_ptr<Module> ToOptimizeLoopExtracted =
+        BD.extractLoop(ToOptimize);
     if (!ToOptimizeLoopExtracted) {
       // If the loop extractor crashed or if there were no extractible loops,
       // then this chapter of our odyssey is over with.
@@ -339,7 +340,7 @@ static bool ExtractLoops(BugDriver &BD,
     // extraction.
     AbstractInterpreter *AI = BD.switchToSafeInterpreter();
     bool Failure;
-    Module *New = TestMergedProgram(BD, ToOptimizeLoopExtracted,
+    Module *New = TestMergedProgram(BD, ToOptimizeLoopExtracted.get(),
                                     ToNotOptimize, false, Error, Failure);
     if (!New)
       return false;
@@ -363,7 +364,7 @@ static bool ExtractLoops(BugDriver &BD,
       BD.writeProgramToFile(OutputPrefix + "-loop-extract-fail-to.bc",
                             ToOptimize);
       BD.writeProgramToFile(OutputPrefix + "-loop-extract-fail-to-le.bc",
-                            ToOptimizeLoopExtracted);
+                            ToOptimizeLoopExtracted.get());
 
       errs() << "Please submit the "
              << OutputPrefix << "-loop-extract-fail-*.bc files.\n";
@@ -376,17 +377,18 @@ static bool ExtractLoops(BugDriver &BD,
 
     outs() << "  Testing after loop extraction:\n";
     // Clone modules, the tester function will free them.
-    Module *TOLEBackup = CloneModule(ToOptimizeLoopExtracted, VMap).release();
+    std::unique_ptr<Module> TOLEBackup =
+        CloneModule(ToOptimizeLoopExtracted.get(), VMap);
     Module *TNOBackup = CloneModule(ToNotOptimize, VMap).release();
 
     for (unsigned i = 0, e = MiscompiledFunctions.size(); i != e; ++i)
       MiscompiledFunctions[i] = cast<Function>(VMap[MiscompiledFunctions[i]]);
 
-    Failure = TestFn(BD, ToOptimizeLoopExtracted, ToNotOptimize, Error);
+    Failure = TestFn(BD, ToOptimizeLoopExtracted.get(), ToNotOptimize, Error);
     if (!Error.empty())
       return false;
 
-    ToOptimizeLoopExtracted = TOLEBackup;
+    ToOptimizeLoopExtracted = std::move(TOLEBackup);
     ToNotOptimize = TNOBackup;
 
     if (!Failure) {
@@ -411,7 +413,6 @@ static bool ExtractLoops(BugDriver &BD,
         MiscompiledFunctions.push_back(NewF);
       }
 
-      delete ToOptimizeLoopExtracted;
       BD.setNewProgram(ToNotOptimize);
       return MadeChange;
     }
@@ -432,8 +433,6 @@ static bool ExtractLoops(BugDriver &BD,
                             diagnosticHandler))
       exit(1);
 
-    delete ToOptimizeLoopExtracted;
-
     // All of the Function*'s in the MiscompiledFunctions list are in the old
     // module.  Update this list to include all of the functions in the
     // optimized and loop extracted module.