From f99a02005970cdcb0aad0de80fa4e5b546c6546b Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Fri, 17 Nov 2023 17:52:24 +0000 Subject: Reapply "[DebugInfo] Make DIArgList inherit from Metadata and always unique" This reverts commit 0fd5dc94380d5fe666dc6c603b4bb782cef743e7. The original commit removed DIArgLists from being in an MDNode map, but did not insert a new `delete` in the LLVMContextImpl destructor. This reapply adds that call to delete, preventing a memory leak. --- llvm/lib/IR/LLVMContextImpl.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'llvm/lib/IR/LLVMContextImpl.cpp') diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp index 406850b..15c90a4 100644 --- a/llvm/lib/IR/LLVMContextImpl.cpp +++ b/llvm/lib/IR/LLVMContextImpl.cpp @@ -68,15 +68,8 @@ LLVMContextImpl::~LLVMContextImpl() { // Drop references for MDNodes. Do this before Values get deleted to avoid // unnecessary RAUW when nodes are still unresolved. - for (auto *I : DistinctMDNodes) { - // We may have DIArgList that were uniqued, and as it has a custom - // implementation of dropAllReferences, it needs to be explicitly invoked. - if (auto *AL = dyn_cast(I)) { - AL->dropAllReferences(); - continue; - } + for (auto *I : DistinctMDNodes) I->dropAllReferences(); - } #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \ for (auto *I : CLASS##s) \ I->dropAllReferences(); @@ -87,6 +80,13 @@ LLVMContextImpl::~LLVMContextImpl() { Pair.second->dropUsers(); for (auto &Pair : MetadataAsValues) Pair.second->dropUse(); + // Do not untrack ValueAsMetadata references for DIArgLists, as they have + // already been more efficiently untracked above. + for (DIArgList *AL : DIArgLists) { + AL->dropAllReferences(/* Untrack */ false); + delete AL; + } + DIArgLists.clear(); // Destroy MDNodes. for (MDNode *I : DistinctMDNodes) -- cgit v1.1