summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/LLVMContextImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR/LLVMContextImpl.cpp')
-rw-r--r--llvm/lib/IR/LLVMContextImpl.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index 506b0e3ac5a..30a1ca28c57 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -119,12 +119,11 @@ struct DropFirst {
}
LLVMContextImpl::~LLVMContextImpl() {
- // NOTE: We need to delete the contents of OwnedModules, but we have to
- // duplicate it into a temporary vector, because the destructor of Module
- // will try to remove itself from OwnedModules set. This would cause
- // iterator invalidation if we iterated on the set directly.
- std::vector<Module*> Modules(OwnedModules.begin(), OwnedModules.end());
- DeleteContainerPointers(Modules);
+ // NOTE: We need to delete the contents of OwnedModules, but Module's dtor
+ // will call LLVMContextImpl::removeModule, thus invalidating iterators into
+ // the container. Avoid iterators during this operation:
+ while (!OwnedModules.empty())
+ delete *OwnedModules.begin();
// Free the constants. This is important to do here to ensure that they are
// freed before the LeakDetector is torn down.
OpenPOWER on IntegriCloud