Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[LLVMContext] Detecting leaked instructions with metadata
Browse files Browse the repository at this point in the history
When instructions with metadata are accidentally leaked, the result is a
difficult-to-find memory corruption in ~LLVMContextImpl that leads to
random crashes.

Patch by Arvīds Kokins!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336010 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vedantk committed Jun 29, 2018
1 parent 459351c commit c55ef47
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/IR/LLVMContextImpl.cpp
Expand Up @@ -48,6 +48,14 @@ LLVMContextImpl::~LLVMContextImpl() {
while (!OwnedModules.empty())
delete *OwnedModules.begin();

#ifndef NDEBUG
// Check for metadata references from leaked Instructions.
for (auto &Pair : InstructionMetadata)
Pair.first->dump();
assert(InstructionMetadata.empty() &&
"Instructions with metadata have been leaked");
#endif

// Drop references for MDNodes. Do this before Values get deleted to avoid
// unnecessary RAUW when nodes are still unresolved.
for (auto *I : DistinctMDNodes)
Expand Down

0 comments on commit c55ef47

Please sign in to comment.