summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2018-06-29 20:13:13 +0000
committerVedant Kumar <vsk@apple.com>2018-06-29 20:13:13 +0000
commit69ee62cef82eef7d23d2c71fb133ba80cac18339 (patch)
treee67b3d77738954588a9db7aa532f453a85b119e5
parent4bbb820e2229191abe9a06d254a51e7583a5d699 (diff)
downloadbcm5719-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.cpp8
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)
OpenPOWER on IntegriCloud