Fix a use after free error caught by the valgrind builders.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110601 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky 2010-08-09 21:03:28 +00:00
parent 8bd11de33e
commit 3221834f8a

View File

@ -559,7 +559,7 @@ void MergeFunctions::WriteThunk(Function *F, Function *G) const {
}
/// MergeTwoFunctions - Merge two equivalent functions. Upon completion,
/// FnVec[j] should never be visited again.
/// FnVec[j] is deleted but not removed from the vector.
void MergeFunctions::MergeTwoFunctions(std::vector<Function *> &FnVec,
unsigned i, unsigned j) const {
Function *F = FnVec[i];
@ -580,10 +580,12 @@ void MergeFunctions::MergeTwoFunctions(std::vector<Function *> &FnVec,
H->takeName(F);
F->replaceAllUsesWith(H);
unsigned MaxAlignment = std::max(G->getAlignment(), H->getAlignment());
WriteThunk(F, G);
WriteThunk(F, H);
F->setAlignment(std::max(G->getAlignment(), H->getAlignment()));
F->setAlignment(MaxAlignment);
F->setLinkage(GlobalValue::InternalLinkage);
} else {
WriteThunk(F, G);