[llvm] r299596 - [Bugpoint] Use `unique_ptr` correctly.
Bryant Wong via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 5 15:23:48 PDT 2017
Author: bryant
Date: Wed Apr 5 17:23:48 2017
New Revision: 299596
URL: http://llvm.org/viewvc/llvm-project?rev=299596&view=rev
Log:
[Bugpoint] Use `unique_ptr` correctly.
Moving Modules into `testMergedProgram` is incorrect (and causes segmentation
faults) since all callers expect to retain ownership. This is evidenced by the
later calls to `unique_ptr<Module>::get` in the same function.
Differential Revision: https://reviews.llvm.org/D31727
Modified:
llvm/trunk/tools/bugpoint/Miscompilation.cpp
Modified: llvm/trunk/tools/bugpoint/Miscompilation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/Miscompilation.cpp?rev=299596&r1=299595&r2=299596&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/Miscompilation.cpp (original)
+++ llvm/trunk/tools/bugpoint/Miscompilation.cpp Wed Apr 5 17:23:48 2017
@@ -225,19 +225,22 @@ public:
/// output is different. If the DeleteInputs argument is set to true then this
/// function deletes both input modules before it returns.
///
-static Expected<std::unique_ptr<Module>>
-testMergedProgram(const BugDriver &BD, std::unique_ptr<Module> M1,
- std::unique_ptr<Module> M2, bool &Broken) {
- if (Linker::linkModules(*M1, std::move(M2)))
+static Expected<std::unique_ptr<Module>> testMergedProgram(const BugDriver &BD,
+ const Module &M1,
+ const Module &M2,
+ bool &Broken) {
+ // Resulting merge of M1 and M2.
+ auto Merged = CloneModule(&M1);
+ if (Linker::linkModules(*Merged, CloneModule(&M2)))
// TODO: Shouldn't we thread the error up instead of exiting?
exit(1);
// Execute the program.
- Expected<bool> Diff = BD.diffProgram(M1.get(), "", "", false);
+ Expected<bool> Diff = BD.diffProgram(Merged.get(), "", "", false);
if (Error E = Diff.takeError())
return std::move(E);
Broken = *Diff;
- return std::move(M1);
+ return std::move(Merged);
}
/// TestFuncs - split functions in a Module into two groups: those that are
@@ -335,9 +338,8 @@ ExtractLoops(BugDriver &BD,
// extraction.
AbstractInterpreter *AI = BD.switchToSafeInterpreter();
bool Failure;
- Expected<std::unique_ptr<Module>> New =
- testMergedProgram(BD, std::move(ToOptimizeLoopExtracted),
- std::move(ToNotOptimize), Failure);
+ Expected<std::unique_ptr<Module>> New = testMergedProgram(
+ BD, *ToOptimizeLoopExtracted, *ToNotOptimize, Failure);
if (Error E = New.takeError())
return std::move(E);
if (!*New)
@@ -726,8 +728,7 @@ static Expected<bool> TestOptimizer(BugD
outs() << " Checking to see if the merged program executes correctly: ";
bool Broken;
- auto Result =
- testMergedProgram(BD, std::move(Optimized), std::move(Safe), Broken);
+ auto Result = testMergedProgram(BD, *Optimized, *Safe, Broken);
if (Error E = Result.takeError())
return std::move(E);
if (auto New = std::move(*Result)) {
More information about the llvm-commits
mailing list