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
This commit is contained in:
Jeffrey Yasskin
2010-03-05 05:47:09 +00:00
parent b5c4239606
commit c8cfa30ca5
3 changed files with 26 additions and 22 deletions

View File

@@ -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.