From 3221834f8a6216d01a7e1d1201bd14eafd79cff3 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Mon, 9 Aug 2010 21:03:28 +0000 Subject: [PATCH] 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 --- lib/Transforms/IPO/MergeFunctions.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index 0b36204fc57..d7075b9277d 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -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 &FnVec, unsigned i, unsigned j) const { Function *F = FnVec[i]; @@ -580,10 +580,12 @@ void MergeFunctions::MergeTwoFunctions(std::vector &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); -- 2.11.0