diff options
author | Vedant Kumar <vsk@apple.com> | 2018-06-29 20:13:13 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2018-06-29 20:13:13 +0000 |
commit | 69ee62cef82eef7d23d2c71fb133ba80cac18339 (patch) | |
tree | e67b3d77738954588a9db7aa532f453a85b119e5 | |
parent | 4bbb820e2229191abe9a06d254a51e7583a5d699 (diff) | |
download | bcm5719-llvm-69ee62cef82eef7d23d2c71fb133ba80cac18339.tar.gz bcm5719-llvm-69ee62cef82eef7d23d2c71fb133ba80cac18339.zip |
[LLVMContext] Detecting leaked instructions with metadata
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!
llvm-svn: 336010
-rw-r--r-- | llvm/lib/IR/LLVMContextImpl.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp index f0ac4583dea..3c34ca55c22 100644 --- a/llvm/lib/IR/LLVMContextImpl.cpp +++ b/llvm/lib/IR/LLVMContextImpl.cpp @@ -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) |