Fix a use after free error caught by the valgrind builders.
authorNick Lewycky <nicholas@mxc.ca>
Mon, 9 Aug 2010 21:03:28 +0000 (21:03 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Mon, 9 Aug 2010 21:03:28 +0000 (21:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110601 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/MergeFunctions.cpp

index 0b36204fc57cb641bfe642153d0bba88f7c6a046..d7075b9277de0e2f8581358e8e4ddc849c423650 100644 (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);