From c8cfa30ca5e6ce80e3e6e1dbff5d24d266d43d27 Mon Sep 17 00:00:00 2001 From: Jeffrey Yasskin Date: Fri, 5 Mar 2010 05:47:09 +0000 Subject: Free MDNodes when the LLVMContext is destroyed. Leak found by Valgrind. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97788 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Metadata.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/VMCore/Metadata.cpp') diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index a08c454..faf83e6 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -110,8 +110,10 @@ MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals, MDNode::~MDNode() { assert((getSubclassDataFromValue() & DestroyFlag) != 0 && "Not being destroyed through destroy()?"); - if (!isNotUniqued()) { - LLVMContextImpl *pImpl = getType()->getContext().pImpl; + LLVMContextImpl *pImpl = getType()->getContext().pImpl; + if (isNotUniqued()) { + pImpl->NonUniquedMDNodes.erase(this); + } else { pImpl->MDNodeSet.RemoveNode(this); } @@ -257,12 +259,10 @@ void MDNode::Profile(FoldingSetNodeID &ID) const { ID.AddPointer(getOperand(i)); } -// replaceAllOperandsWithNull - This is used while destroying llvm context to -// gracefully delete all nodes. This method replaces all operands with null. -void MDNode::replaceAllOperandsWithNull() { - for (MDNodeOperand *Op = getOperandPtr(this, 0), *E = Op+NumOperands; - Op != E; ++Op) - replaceOperand(Op, 0); +void MDNode::setIsNotUniqued() { + setValueSubclassData(getSubclassDataFromValue() | NotUniquedBit); + LLVMContextImpl *pImpl = getType()->getContext().pImpl; + pImpl->NonUniquedMDNodes.insert(this); } // Replace value from this node's operand list. -- cgit v1.1