[llvm] r336010 - [LLVMContext] Detecting leaked instructions with metadata
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 29 13:13:13 PDT 2018
Author: vedantk
Date: Fri Jun 29 13:13:13 2018
New Revision: 336010
URL: http://llvm.org/viewvc/llvm-project?rev=336010&view=rev
Log:
[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!
Modified:
llvm/trunk/lib/IR/LLVMContextImpl.cpp
Modified: llvm/trunk/lib/IR/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.cpp?rev=336010&r1=336009&r2=336010&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/IR/LLVMContextImpl.cpp Fri Jun 29 13:13:13 2018
@@ -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)
More information about the llvm-commits
mailing list