Index: bugpoint/BugDriver.h =================================================================== --- bugpoint/BugDriver.h +++ bugpoint/BugDriver.h @@ -210,7 +210,7 @@ /// MayModifySemantics argument is true, then the cleanups is allowed to /// modify how the code behaves. /// - std::unique_ptr performFinalCleanups(Module *M, + std::unique_ptr performFinalCleanups(std::unique_ptr M, bool MayModifySemantics = false); /// Given a module, extract up to one loop from it into a new function. This Index: bugpoint/CrashDebugger.cpp =================================================================== --- bugpoint/CrashDebugger.cpp +++ bugpoint/CrashDebugger.cpp @@ -1180,14 +1180,12 @@ // Try to clean up the testcase by running funcresolve and globaldce... if (!BugpointIsInterrupted) { outs() << "\n*** Attempting to perform final cleanups: "; - Module *M = CloneModule(BD.getProgram()).release(); - M = BD.performFinalCleanups(M, true).release(); + std::unique_ptr M = CloneModule(BD.getProgram()); + M = BD.performFinalCleanups(std::move(M), true); // Find out if the pass still crashes on the cleaned up program... - if (TestFn(BD, M)) { - BD.setNewProgram(M); // Yup, it does, keep the reduced version... - } else { - delete M; + if (TestFn(BD, M.get())) { + BD.setNewProgram(M.get()); // Yup, it does, keep the reduced version... } } Index: bugpoint/ExtractFunction.cpp =================================================================== --- bugpoint/ExtractFunction.cpp +++ bugpoint/ExtractFunction.cpp @@ -128,7 +128,7 @@ } std::unique_ptr -BugDriver::performFinalCleanups(Module *M, bool MayModifySemantics) { +BugDriver::performFinalCleanups(std::unique_ptr M, bool MayModifySemantics) { // Make all functions external, so GlobalDCE doesn't delete them... for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) I->setLinkage(GlobalValue::ExternalLinkage); @@ -141,12 +141,11 @@ else CleanupPasses.push_back("deadargelim"); - std::unique_ptr New = runPassesOn(M, CleanupPasses); + std::unique_ptr New = runPassesOn(M.get(), CleanupPasses); if (!New) { errs() << "Final cleanups failed. Sorry. :( Please report a bug!\n"; return nullptr; } - delete M; return New; } Index: bugpoint/Miscompilation.cpp =================================================================== --- bugpoint/Miscompilation.cpp +++ bugpoint/Miscompilation.cpp @@ -788,15 +788,15 @@ /// Get the specified modules ready for code generator testing. /// -static void CleanupAndPrepareModules(BugDriver &BD, - std::unique_ptr &Test, - Module *Safe) { +static std::unique_ptr +CleanupAndPrepareModules(BugDriver &BD, std::unique_ptr Test, + Module *Safe) { // Clean up the modules, removing extra cruft that we don't need anymore... - Test = BD.performFinalCleanups(Test.get()); + Test = BD.performFinalCleanups(std::move(Test)); // If we are executing the JIT, we have several nasty issues to take care of. if (!BD.isExecutingJIT()) - return; + return Test; // First, if the main function is in the Safe module, we must add a stub to // the Test module to call into it. Thus, we create a new function `main' @@ -942,6 +942,8 @@ errs() << "Bugpoint has a bug, which corrupted a module!!\n"; abort(); } + + return Test; } /// This is the predicate function used to check to see if the "Test" portion of @@ -951,7 +953,7 @@ static Expected TestCodeGenerator(BugDriver &BD, std::unique_ptr Test, std::unique_ptr Safe) { - CleanupAndPrepareModules(BD, Test, Safe.get()); + Test = CleanupAndPrepareModules(BD, std::move(Test), Safe.get()); SmallString<128> TestModuleBC; int TestModuleFD; @@ -1042,7 +1044,7 @@ SplitFunctionsOutOfModule(ToNotCodeGen.get(), *Funcs, VMap); // Condition the modules - CleanupAndPrepareModules(*this, ToCodeGen, ToNotCodeGen.get()); + ToCodeGen = CleanupAndPrepareModules(*this, std::move(ToCodeGen), ToNotCodeGen.get()); SmallString<128> TestModuleBC; int TestModuleFD;