summaryrefslogtreecommitdiff
path: root/lib/VMCore/LLVMContextImpl.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VMCore/LLVMContextImpl.h')
-rw-r--r--lib/VMCore/LLVMContextImpl.h25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h
index 9887f28821..9978f40ed0 100644
--- a/lib/VMCore/LLVMContextImpl.h
+++ b/lib/VMCore/LLVMContextImpl.h
@@ -105,6 +105,11 @@ public:
StringMap<MDString*> MDStringCache;
FoldingSet<MDNode> MDNodeSet;
+ // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
+ // aren't in the MDNodeSet, but they're still shared between objects, so no
+ // one object can destroy them. This set allows us to at least destroy them
+ // on Context destruction.
+ SmallPtrSet<MDNode*, 1> NonUniquedMDNodes;
ConstantUniqueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
@@ -235,17 +240,21 @@ public:
(*I)->AbstractTypeUsers.clear();
delete *I;
}
- // Destroy MDNode operands first.
+ // Destroy MDNodes. ~MDNode can move and remove nodes between the MDNodeSet
+ // and the NonUniquedMDNodes sets, so copy the values out first.
+ SmallVector<MDNode*, 8> MDNodes;
+ MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size());
for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end();
- I != E;) {
- MDNode *N = &(*I);
- ++I;
- N->replaceAllOperandsWithNull();
+ I != E; ++I) {
+ MDNodes.push_back(&*I);
}
- while (!MDNodeSet.empty()) {
- MDNode *N = &(*MDNodeSet.begin());
- N->destroy();
+ MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end());
+ for (SmallVector<MDNode*, 8>::iterator I = MDNodes.begin(),
+ E = MDNodes.end(); I != E; ++I) {
+ (*I)->destroy();
}
+ assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() &&
+ "Destroying all MDNodes didn't empty the Context's sets.");
// Destroy MDStrings.
for (StringMap<MDString*>::iterator I = MDStringCache.begin(),
E = MDStringCache.end(); I != E; ++I) {